Esempio n. 1
0
def sphere_layout(radius):
    ids = graphiti.get_node_ids()
    for nid in ids:
        r1 = random.random() * 2 * math.pi
        r2 = random.random() * 2 * math.pi
        r3 = 0.9 + 0.1 * random.random()

        pos = [
            radius * r3 * math.sin(r1) * math.cos(r2),
            radius * r3 * math.cos(r1),
            radius * r3 * math.sin(r1) * math.sin(r2)
        ]

        graphiti.set_node_attribute(nid, "graphiti:space:position", "vec3", std.vec3_to_str(pos))
Esempio n. 2
0
def show_connected_components():

    graphiti.set_attribute("graphiti:space:linkmode", "string", "node_color")

    graph = std.load_nx_graph()
    cc = nx.connected_components(graph)

    for list in cc:
        r = random.random()
        g = random.random()
        b = random.random()
        color = str(r) + " " + str(g) + " " + str(b) 
        
        for node in list:
            graphiti.set_node_attribute(node, "graphiti:space:color", "vec3", color)
Esempio n. 3
0
def color_edges_by_type():

    graphiti.set_attribute("graphiti:space:linkmode", "string", "edge_color")

    ids = graphiti.get_link_ids()
    colors = dict()

    for id in ids:
        type = graphiti.get_link_attribute(id, "type")
        if type == None:
            print("Edge " + str(id) + " has no type attribute !")
        color = None
        if type in colors:
            color = colors[type]
        else:
            r = random.random()
            g = random.random()
            b = random.random()
            color = str(r) + " " + str(g) + " " + str(b)
            colors[type] = color
        graphiti.set_link_attribute(id, "graphiti:space:color", "vec3", color)
Esempio n. 4
0
def color_nodes_by_nominal_attribute(attribute_name):

    graphiti.set_attribute("graphiti:space:linkmode", "string", "edge_color")

    ids = graphiti.get_node_ids()
    colors = dict()

    for id in ids:
        type = graphiti.get_node_attribute(id, attribute_name)
        if type == None:
            print("Node " + str(id) + " has no <" + attribute_name + "> attribute !")
        color = None
        if type in colors:
            color = colors[type]
        else:
            r = random.random()
            g = random.random()
            b = random.random()
            color = str(r) + " " + str(g) + " " + str(b)
            colors[type] = color
        graphiti.set_node_attribute(id, "graphiti:space:color", "vec3", color)
Esempio n. 5
0
def conic_layout():
    graph = std.load_nx_graph()

    graphiti.set_attribute("graphiti:space:linkmode", "string", "node_color")

    sorted_degrees = sorted(nx.degree(graph).values())
    max_degree = sorted_degrees[-1]

    degree_nodes = {}
    for n in graph.nodes(data = True):
        degree = nx.degree(graph, n[0])
        if degree in degree_nodes:
            degree_nodes[degree].append(n[0])
        else:
            degree_nodes[degree] = [n[0]]

    max_radius = 30.0
    max_height = 20
    for n in graph.nodes(data = True):
        degree = nx.degree(graph, n[0])

        nodes = degree_nodes[degree]

        radius = 1.0 + max_radius * float(1.0 - float(degree) / float(max_degree))
        alpha = 2.0 * math.pi * random.random() #float(nodes.index(n[0])) / float(len(nodes)) 
        # 3D
        # beta = 2.0 * math.pi * random.random() #float(nodes.index(n[0])) / float(len(nodes)) 

        x = radius * math.cos(alpha)
        y = max_height * float(degree) / float(max_degree)
        z = radius * math.sin(alpha)
        # 3D
        # x = radius * math.sin(alpha) * math.cos(beta)
        # y = radius * math.sin(alpha) * math.sin(beta)
        # z = radius * math.cos(alpha)

        graphiti.set_node_attribute(n[0], "graphiti:space:position", "vec3", str(x) + " " + str(y) + " " + str(z))
Esempio n. 6
0
def randomize_lod():
    for id in graphiti.get_node_ids():
        graphiti.set_node_attribute(id, "og:space:lod", "float", str(random.random()))   
    for id in graphiti.get_link_ids():
        graphiti.set_link_attribute(id, "og:space:lod", "float", str(random.random()))