示例#1
0
def seed_circle_layout():
    radius = 100.0

    ids = graphiti.get_node_ids()
    zeros = []
    for id in ids:
        attribute = graphiti.get_node_attribute(id, "depth")
        if attribute == None:
            continue
        else:
            if attribute == 0:
                zeros.append(id)

    count = 0
    if len(zeros) == 1:
        radius = 0.0
    for id in zeros:
        angle = 2.0 * math.pi * float(count) / float(len(zeros))

        x = radius * math.cos(angle)
        y = 0.0
        z = radius * math.sin(angle)

        graphiti.set_node_attribute(id, "graphiti:space:position", "vec3", str(x) + " " + str(y) + " " + str(z))
        graphiti.set_node_attribute(id, "graphiti:space:locked", "bool", "True")
        graphiti.set_node_attribute(id, "graphiti:space:activity", "float", "2.0")
        graphiti.set_node_attribute(id, "og:space:mark", "int", "2")
        count += 1
示例#2
0
def load_nx_graph():

    global node_attributes
    global edge_attributes
    
    graph = nx.Graph()
    
    print(graphiti.get_node_ids())

    for id in graphiti.get_node_ids():
        graph.add_node(id)
        graph.node[id]['label'] = graphiti.get_node_label(id)

        for a in node_attributes:
            attribute = graphiti.get_node_attribute(id, a['name'])
            if not(attribute is None):
                value = str(attribute)
                if a['type'] == "vec2" or a['type'] == "vec3":
                    value = filter(lambda x: not (x in "[,]"), value)
                graph.node[id][a['name']] = value

    for id in graphiti.get_edge_ids():
        node1 = graphiti.get_edge_node1(id)
        node2 = graphiti.get_edge_node2(id)
        graph.add_edge(node1, node2)
    
    return graph
示例#3
0
def globe_layout():
    ids = graphiti.get_node_ids()
    for id in ids:
        geo = graphiti.get_node_attribute(id, "world:geolocation")
        if geo is not None:
           pos = globe_coordinates(geo[0], geo[1])
           graphiti.set_node_attribute(id, "graphiti:space:position", "vec3", std.vec3_to_str(pos))
           graphiti.set_node_attribute(id, "graphiti:space:locked", "bool", "true")
示例#4
0
def attribute_to_lod(attribute, fun = lambda x : x):
    min = float("inf")
    max = float("-inf")
    min_value = None
    max_value = None

    n_values = dict()
    for nid in graphiti.get_node_ids():
        value = graphiti.get_node_attribute(nid, attribute)
        if value is None:
            graphiti.set_node_attribute(nid, "graphiti:space:lod", "float", "-1000")
            continue
        fun_value = fun(value)
        if fun_value is None:
            graphiti.set_node_attribute(nid, "graphiti:space:lod", "float", "-1000")
            continue
        fvalue = float(fun_value)
        if fvalue > max:
            max = fvalue
            max_value = value
        if fvalue < min:
            min = fvalue
            min_value = value
        n_values[nid] = fvalue

    e_values = dict()
    for eid in graphiti.get_link_ids():
        value = graphiti.get_link_attribute(eid, attribute)
        if value is None:
            graphiti.set_link_attribute(eid, "graphiti:space:lod", "float", "-1000")
            continue
        fun_value = fun(value)
        if fun_value is None:
            graphiti.set_link_attribute(eid, "graphiti:space:lod", "float", "-1000")
            continue
        fvalue = float(fun_value)
        if fvalue > max:
            max = fvalue
            max_value = value
        if fvalue < min:
            min = fvalue
            min_value = value
        e_values[eid] = fvalue

    for nid in n_values.keys():
        svalue = (n_values[nid] - min) / (max - min)
        print(attribute + " : " + str(n_values[nid]) + " --> lod : " + str(svalue)) 
        graphiti.set_node_attribute(nid, "graphiti:space:lod", "float", str(svalue))
    for eid in e_values.keys():
        svalue = (e_values[eid] - min) / (max - min)
        print(attribute + " : " + str(e_values[eid]) + " --> lod : " + str(svalue)) 
        graphiti.set_link_attribute(eid, "graphiti:space:lod", "float", str(svalue))

    print("LOD range : " + str(min_value) + " to " + str(max_value))
示例#5
0
def color_diff():
    global colors
    for n in graphiti.get_node_ids():
        s = graphiti.get_node_attribute(n, 'diffstatus')
        graphiti.set_node_attribute(n, "graphiti:space:color", "vec3", colors[s])
    for e in graphiti.get_link_ids():
        s = graphiti.get_link_attribute(e, 'diffstatus')
        try:
            graphiti.set_link_attribute(e, "graphiti:space:color", "vec3", colors[s])
        except KeyError:
            print("link: {}".format(e))
            print("diffstatus: {}".format(s))
            sys.exit(-1)
示例#6
0
def color_diff():
    global colors
    for n in graphiti.get_node_ids():
        s = graphiti.get_node_attribute(n, 'diffstatus')
        graphiti.set_node_attribute(n, "graphiti:space:color", "vec3", colors[s])
    for e in graphiti.get_edge_ids():
        s = graphiti.get_edge_attribute(e, 'diffstatus')
        try:
            graphiti.set_edge_attribute(e, "graphiti:space:color", "vec3", colors[s])
        except KeyError:
            print("edge: {}".format(e))
            print("diffstatus: {}".format(s))
            sys.exit(-1)
示例#7
0
def color_nodes_by_dga_score():

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

    ids = graphiti.get_node_ids()
    for id in ids:
        score = graphiti.get_node_attribute(id, "sgraph:dga:score")
        if score is None:
            graphiti.set_node_attribute(id, "graphiti:space:color", "vec4", "0.5 0.5 0.5 0.5")
            continue
        else:
            # DGA score is between [0 : not DGA, 100 : DGA]
            sub = score / 100;
            rgb = [1.0, 1.0 - sub, 1.0 - sub, 1.0]
            graphiti.set_node_attribute(id, "graphiti:space:color", "vec4", std.vec4_to_str(rgb))
示例#8
0
def color_nodes_by_infected():
    
    graphiti.set_attribute("graphiti:space:linkmode", "string", "node_color")

    ids = graphiti.get_node_ids()
    for id in ids:
        score = graphiti.get_node_attribute(id, "sgraph:infected")
        if score is None:
            graphiti.set_node_attribute(id, "graphiti:space:color", "vec4", "0.5 0.5 0.5 0.5")
        elif score < 0:
            graphiti.set_node_attribute(id, "graphiti:space:color", "vec3", "1.0 0.0 0.0")
        elif score > 0:
            graphiti.set_node_attribute(id, "graphiti:space:color", "vec3", "0.0 1.0 0.0")
        else:
            graphiti.set_node_attribute(id, "graphiti:space:color", "vec3", "1.0 1.0 1.0")
示例#9
0
def multiply_colors(v, node_flag, edge_flag):
    def f(c, v):
        return [c[0] * v[0], c[1] * v[1], c[2] * v[2], c[3] * v[3]]
        

    if node_flag:
        for id in graphiti.get_node_ids():
            c = graphiti.get_node_attribute(id, "graphiti:space:color")
            graphiti.set_node_attribute(id, "graphiti:space:color", "vec4", std.vec4_to_str(f(c, v)))

    if edge_flag:
        for id in graphiti.get_link_ids():
            c = graphiti.get_link_attribute(id, "graphiti:space:color1")
            graphiti.set_link_attribute(id, "graphiti:space:color1", "vec4", std.vec4_to_str(f(c, v)))
            c = graphiti.get_link_attribute(id, "graphiti:space:color2")
            graphiti.set_link_attribute(id, "graphiti:space:color2", "vec4", std.vec4_to_str(f(c, v)))
示例#10
0
def show_low_degrees():
    graphiti.set_attribute("graphiti:space:linkmode", "string", "node_color")

    graph = std.load_nx_graph()
    max_degree = max(nx.degree(graph).values())
    for n in graph.nodes(data = True):
        deg = nx.degree(graph, n[0])
        tint = 0.3 + 0.9 * (1.0 - float(deg) / float(max_degree))

        color = graphiti.get_node_attribute(n[0], "graphiti:space:color")
        color[0] = tint * color[0]
        color[1] = tint * color[1]
        color[2] = tint * color[2]
        c = str(color[0]) + " " + str(color[1]) + " " + str(color[2])

        graphiti.set_node_attribute(n[0], "graphiti:space:color", "vec3", c)
示例#11
0
def lock_unlock():
    if graphiti.count_selected_nodes() == 0:
        print ("Please select a node !")
        return

    selected = graphiti.get_selected_node(0)
    print("SELECTED : ", selected)
    locked = graphiti.get_node_attribute(selected, "graphiti:space:locked")
    if locked:
        graphiti.set_node_attribute(selected, "graphiti:space:locked", "bool", "False")
        graphiti.set_node_attribute(selected, "og:space:mark", "int", "0");
        print("Node " + str(selected) + " unlocked.")
    else:
        graphiti.set_node_attribute(selected, "graphiti:space:locked", "bool", "True")
        graphiti.set_node_attribute(selected, "og:space:mark", "int", "2");
        print("Node " + str(selected) + " locked.")
示例#12
0
def save_json(filename):

    graph = {}
    graph["meta"] = dict()
    graph["nodes"] = list()
    graph["edges"] = list()

    global node_attributes
    global edge_attributes

    print("Saving graph into '" + filename + "' ...")

    for id in graphiti.get_node_ids():
        node = dict()
        node["id"] = id
        node["label"] = graphiti.get_node_label(id)

        for attribute in node_attributes:
            name = attribute['name']
            value = graphiti.get_node_attribute(id, name)
            if value is None:
                continue
            node[name] = value

        graph["nodes"].append(node)

    for id in graphiti.get_link_ids():
        edge = dict()
        edge["id"] = id
        edge["src"] = graphiti.get_link_node1(id)
        edge["dst"] = graphiti.get_link_node2(id)

        for attribute in edge_attributes:
            name = attribute['name']
            value = graphiti.get_link_attribute(id, name)
            if value is None:
                continue
            edge[name] = value

        graph["edges"].append(edge)

    with open(filename, 'w') as outfile:
        json.dump(graph, outfile, indent=True, sort_keys=True)
    print("Done.")
示例#13
0
def regex_map(expression, attribute, node_flag, edge_flag, f, translate = True):

    if translate:
        expression = fnmatch.translate(expression)
    r = re.compile(expression)
    if r is None:
        print("Invalid expression : <" + expression + "> !")
        return            

    if node_flag:
        for nid in graphiti.get_node_ids():
            value = None

            if attribute == "label":
                value = graphiti.get_node_label(nid)
            elif attribute == "mark":
                value = graphiti.get_node_mark(nid)
            elif attribute == "weight":
                value = graphiti.get_node_weight(nid)
            else:
                value = graphiti.get_node_attribute(nid, attribute)

            if value is None:
                f("node", nid, None)
            else:
                f("node", nid, r.match(str(value)))

    if edge_flag:
        for eid in graphiti.get_edge_ids():
            value = None

            if attribute == "node1":
                value = graphiti.get_edge_node1(eid)
            elif attribute == "node2":
                value = graphiti.get_edge_node2(eid)
            else:
                value = graphiti.get_edge_attribute(eid, attribute)

            if value is None:
                f("edge", eid, None)
            else:
                value_str = str(value)
                f("edge", eid, r.match(value_str))
示例#14
0
def save_json(filename):
    
    graph = {}
    graph["meta"] = dict()
    graph["nodes"] = list()
    graph["edges"] = list()

    global node_attributes
    global edge_attributes
    
    for id in graphiti.get_node_ids():
        node = dict()
        node["id"] = id
        node["label"] = graphiti.get_node_label(id)

        for attribute in node_attributes:
            name = attribute['name']
            value = graphiti.get_node_attribute(id, name)
            if value is None:
                continue
            node[name] = value

        graph["nodes"].append(node)

    for id in graphiti.get_edge_ids():
        edge = dict()
        edge["id"] = id
        edge["src"] = graphiti.get_edge_node1(id)
        edge["dst"] = graphiti.get_edge_node2(id)

        for attribute in edge_attributes:
            name = attribute['name']
            value = graphiti.get_edge_attribute(id, name)
            if value is None:
                continue
            edge[name] = value

        graph["edges"].append(edge)

    with open(filename, 'w') as outfile:
        json.dump(graph, outfile, indent=True, sort_keys=True)
示例#15
0
def color_nodes_by_type():

    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, "type")
        if type == None:
            print("Node " + 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_node_attribute(id, "graphiti:space:color", "vec3", color)
示例#16
0
def attribute_to_icon(attribute, fun = lambda a : "shapes/disk"):
    for nid in graphiti.get_node_ids():
        value = graphiti.get_node_attribute(nid, attribute)
        graphiti.set_node_attribute(nid, "graphiti:space:icon", "string", fun(value))