Ejemplo n.º 1
0
 def f(t, id, match):
     if not match:
         if t == "node":
             graphiti.set_node_attribute(id, "graphiti:space:lod", "float",
                                         "0.0")
         elif t == "edge":
             graphiti.set_edge_attribute(id, "graphiti:space:lod", "float",
                                         "0.0")
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def on_started():
    global cities

    dico = {}

    for city in cities:
        nid = graphiti.add_node(city["name"])
        graphiti.set_node_attribute(nid, "og:world:geolocation", "vec2", std.vec2_to_str(city["geolocation"]))
        graphiti.set_node_attribute(nid, "og:world:color", "vec4", std.vec4_to_str(city["color"]))
        graphiti.set_node_attribute(nid, "og:world:size", "float", str(city["size"]))
        dico[city['name']] = nid

    eid = graphiti.add_edge(dico['Paris'], dico['San Francisco'])
    graphiti.set_edge_attribute(eid, "og:world:color", "vec4", "0.0 1.0 0.0 1.0")
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
def on_started():
    global cities

    dico = {}

    for city in cities:
        nid = graphiti.add_node(city["name"])
        graphiti.set_node_attribute(nid, "og:world:geolocation", "vec2",
                                    std.vec2_to_str(city["geolocation"]))
        graphiti.set_node_attribute(nid, "og:world:color", "vec4",
                                    std.vec4_to_str(city["color"]))
        graphiti.set_node_attribute(nid, "og:world:size", "float",
                                    str(city["size"]))
        dico[city['name']] = nid

    eid = graphiti.add_edge(dico['Paris'], dico['San Francisco'])
    graphiti.set_edge_attribute(eid, "og:world:color", "vec4",
                                "0.0 1.0 0.0 1.0")
Ejemplo n.º 6
0
def load_json(json_filename):
    nodes = {}
    edges = {}
    global node_attributes
    global edge_attributes

    print ("Loading \"" + json_filename + "\" ...")

    import json
    with open(json_filename, "r") as infile:
        data = json.load(infile)

    print("Loading meta information ...")
    # TODO : Find a more generic way of doing this
    if "meta" in data:
        if "title" in data["meta"].keys():
            if data["meta"]["title"] is not None:
                graphiti.set_attribute("raindance:space:title", "string", data["meta"]["title"])

    if "attributes" in data:
        for key in data["attributes"].keys():
            if key in reserved_attributes:
                continue
            att_info = get_attribute_info(data["attributes"][key])
            if att_info is None:
                print("Error: Couldn't parse key '" + key + "' with value '" + str(data["attributes"][key]) + "'!")
                continue
            graphiti.set_attribute(key, att_info[0], att_info[1])

    print(". Loading nodes ...")
    for n in data["nodes"]:
        n = prepare_node(n)

        label = ""
        if "label" in n:
            label = n["label"].encode("utf-8")
        
        nid = graphiti.add_node(label)
        nodes[n["id"]] = nid

        for key in n.keys():
            if key in reserved_attributes:
                continue
            att_info = get_attribute_info(n[key])
            if att_info is None:
                print("Error: Couldn't parse key '" + key + "' with value '" + str(n[key]) + "'!")
                continue
            graphiti.set_node_attribute(nid, key, att_info[0], att_info[1])

    print(". Loading edges ...")
    for e in data["edges"]:
        e = prepare_edge(e)

        if "src" in e:
            eid = graphiti.add_edge(nodes[e["src"]], nodes[e["dst"]])
        else:
            eid = graphiti.add_edge(nodes[e['source']], nodes[e['target']])
        edges[e["id"]] = eid

        for key in e.keys():
            if key in reserved_attributes:
                continue
            att_info = get_attribute_info(e[key])
            if att_info is None:
                print("Error: Couldn't parse key '" + key + "' with value '" + str(e[key]) + "'!")
                continue
            graphiti.set_edge_attribute(eid, key, att_info[0], att_info[1])

    if "timeline" in data:
        print(". Loading timeline ...")
        for c in data["timeline"]:
            # TODO : Get rid of this translation phase when possible.
            if c[1].startswith("graph:"):
                if c[1] in ["graph:remove_node", "graph:set_node_attribute"]:
                    c[2]["id"] = nodes[c[2]["id"]]
                elif c[1] in ["graph:remove_edge", "graph:set_edge_attribute"]:
                    c[2]["id"] = edges[c[2]["id"]]
                elif c[1] in ["graph:add_edge"]:
                    c[2]["src"] = nodes[c[2]["src"]]
                    c[2]["dst"] = nodes[c[2]["dst"]]
            graphiti.send_command(c[0], c[1], c[2])

    print("Done.")
Ejemplo n.º 7
0
 def f(t, id, match):
     if not match:
         if t == "node":
             graphiti.set_node_attribute(id, "graphiti:space:lod", "float", "0.0")
         elif t == "edge":
             graphiti.set_edge_attribute(id, "graphiti:space:lod", "float", "0.0")