示例#1
0
# You can also construct the nodes and edges of the graph by loading the graph.json
# file and setting it for the graph.

# with open('graph.json') as graph_json_file:
#     graph_json = json.load(graph_json_file)
# G.set_graph_json(graph_json)

# Adding style to the graph elements
G.add_style('node', {
    "width": "60px",
    "height": "60px",
    "content": "data(id)",
    "pie-size": "80%",
    "pie-1-background-color": "#E8747C",
    "pie-1-background-size": "mapData(foo, 0, 10, 0, 100)",
    "pie-2-background-color": "#74CBE8",
    "pie-2-background-size": "mapData(bar, 0, 10, 0, 100)",
    "pie-3-background-color": "#74E883",
    "pie-3-background-size": "mapData(baz, 0, 10, 0, 100)",
    "background-color": "grey",
    "text-valign": "top"
})
G.add_style('edge', {
    "curve-style": "bezier",
    "width": 4,
    "target-arrow-shape": "triangle",
    "opacity": 0.5,
    "line-color": "grey"
})

# You can also add style by loading the style.json file and setting it for the graph.
示例#2
0
 <a href=\"http://js.cytoscape.org/demos/circle-layout/\">http://js.cytoscape.org/demos/circle-layout/</a>',
    'directed': True
}
G.set_data(data)

# Construct nodes and edges of the graph from graph data
for elem in graph_data:
    if elem['group'] == 'nodes':
        G.add_node(elem['data']['id'], elem['data'])
        G.set_node_position(elem['data']['id'], elem['position']['y'],
                            elem['position']['x'])
    else:
        G.add_edge(elem['data']['source'], elem['data']['target'],
                   elem['data'])

# Define style for the graph elements
G.add_style('node', {'height': 20, 'width': 20, 'background-color': '#e8e406'})
G.add_style(
    'edge', {
        'curve-style': 'haystack',
        'haystack-radius': 0,
        'width': 5,
        'opacity': 0.5,
        'line-color': '#f2f08c'
    })

# Post graph to GraphSpace
graph = graphspace.post_graph(G)
print('Your graph has been saved on GraphSpace. You can view it at %s.' %
      graph.url)
# Add edges
G.add_edge('a', 'd')
G.add_edge('e', 'b')

# You can also construct the nodes and edges of the graph by loading the graph.json
# file and setting it for the graph.

# with open('graph.json') as graph_json_file:
#     graph_json = json.load(graph_json_file)
# G.set_graph_json(graph_json)

# Adding style to the graph elements
G.add_style(
    'node', {
        "content": "data(id)",
        "text-valign": "center",
        "text-halign": "center",
        "background-color": "grey"
    })
G.add_style(
    '$node > node', {
        "padding-top": "10px",
        "padding-left": "10px",
        "padding-bottom": "10px",
        "padding-right": "10px",
        "text-valign": "top",
        "text-halign": "center",
        "background-color": "#bbb"
    })
G.add_style('edge', {"target-arrow-shape": "triangle", "line-color": "grey"})
示例#4
0
G.add_edge('n01', 'n02', {'type': 'bezier'})
G.add_edge('n03', 'n04', {'type': 'unbundled-bezier'})
G.add_edge('n02', 'n01', {'type': 'bezier'})

# You can also construct the nodes and edges of the graph by loading the graph.json
# file and setting it for the graph.

# with open('graph.json') as graph_json_file:
#     graph_json = json.load(graph_json_file)
# G.set_graph_json(graph_json)

# Adding style to the graph elements
G.add_style(
    'node', {
        "height": 40,
        "width": 40,
        "background-color": "#333",
        "text-valign": "center",
        "text-halign": "left"
    })
G.add_style('edge', {"width": 3, "opacity": 0.666, "line-color": "#888"})
G.add_style('edge[type="bezier"]', {
    "curve-style": "bezier",
    "control-point-step-size": 40
})
G.add_style(
    'edge[type="unbundled-bezier"]', {
        "curve-style": "unbundled-bezier",
        "control-point-distances": 120,
        "control-point-weights": 0.1
    })
G.add_style(
G.add_edge('k', 'g', {"faveColor": "#86B342", "strength": 100})
G.add_edge('g', 'j', {"faveColor": "#F5A45D", "strength": 90})

# You can also construct the nodes and edges of the graph by loading the graph.json
# file and setting it for the graph.

# with open('graph.json') as graph_json_file:
#     graph_json = json.load(graph_json_file)
# G.set_graph_json(graph_json)

# Adding style to the graph elements
G.add_style(
    'node', {
        "width": "mapData(weight, 40, 80, 20, 60)",
        "content": "data(label)",
        "text-valign": "center",
        "text-outline-width": 2,
        "text-outline-color": "data(faveColor)",
        "background-color": "data(faveColor)",
        "color": "#fff"
    })
G.add_style('node[name="j"]', {"shape": "triangle"})
G.add_style('node[name="e"]', {"shape": "ellipse"})
G.add_style('node[name="k"]', {"shape": "octagon"})
G.add_style('node[name="g"]', {"shape": "rectangle"})
G.add_style(
    'edge', {
        "curve-style": "bezier",
        "opacity": 0.666,
        "width": "mapData(strength, 70, 100, 2, 6)",
        "target-arrow-shape": "triangle",
        "source-arrow-shape": "circle",
示例#6
0
edges = [('cat', 'bird'), ('bird', 'ladybug'), ('bird', 'grasshopper'), ('grasshopper', 'plant'),
        ('grasshopper', 'wheat'), ('ladybug', 'aphid'), ('aphid', 'rose')]
G.add_edges_from(edges)

# You can also construct the nodes and edges of the graph by loading the graph.json
# file and setting it for the graph.

# with open('graph.json') as graph_json_file:
#     graph_json = json.load(graph_json_file)
# G.set_graph_json(graph_json)

# Adding style to the graph elements
G.add_style('node', {
    "height": 80,
    "width": 80,
    "background-fit": "cover",
    "border-color": "#000",
    "border-width": 3,
    "border-opacity": 0.5
})
G.add_style('node[name="bird"]', {
    "background-image": "https://farm8.staticflickr.com/7272/7633179468_3e19e45a0c_b.jpg"
})
G.add_style('node[name="cat"]', {
    "background-image": "https://farm2.staticflickr.com/1261/1413379559_412a540d29_b.jpg"
})
G.add_style('node[name="ladybug"]', {
    "background-image": "https://farm4.staticflickr.com/3063/2751740612_af11fb090b_b.jpg"
})
G.add_style('node[name="aphid"]', {
    "background-image": "https://farm9.staticflickr.com/8316/8003798443_32d01257c8_b.jpg"
})