Add ability to color and label edges.
This commit is contained in:
parent
228e899b66
commit
73ec40414e
14
example.json
14
example.json
|
@ -8,12 +8,12 @@
|
||||||
],
|
],
|
||||||
|
|
||||||
"relationships": [
|
"relationships": [
|
||||||
["Sam", "Max", "solid"],
|
{"members": ["Sam", "Max"]},
|
||||||
["Sam", "Eve", "solid"],
|
{"members": ["Sam", "Eve"], "color": "red"},
|
||||||
["Max", "Eve", "solid"],
|
{"members": ["Max", "Eve"], "label": "friends+"},
|
||||||
["Sam", "Bob", "solid"],
|
{"members": ["Sam", "Bob"], "color": "yellow", "label": "cuddle friends"},
|
||||||
["Alice", "Bob", "dashed"],
|
{"members": ["Alice", "Bob"], "style": "dashed"},
|
||||||
["Alice", "Charles", "solid"],
|
{"members": ["Alice", "Charles"]},
|
||||||
["Charles", "Max", "dashed"]
|
{"members": ["Charles", "Max"]}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
BIN
example.png
BIN
example.png
Binary file not shown.
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 20 KiB |
16
polygraph.py
16
polygraph.py
|
@ -35,11 +35,19 @@ def main():
|
||||||
graph.add_node(user['name'], fillcolor=node_color)
|
graph.add_node(user['name'], fillcolor=node_color)
|
||||||
|
|
||||||
# Add edges to graph
|
# Add edges to graph
|
||||||
edge_style = 'solid'
|
for relationship in data['relationships']:
|
||||||
|
edge_style = 'solid'
|
||||||
|
if relationship.has_key('style'): edge_style = relationship['style']
|
||||||
|
edge_color = 'black'
|
||||||
|
if relationship.has_key('color'): edge_color = relationship['color']
|
||||||
|
edge_label = None
|
||||||
|
if relationship.has_key('label'): edge_label = relationship['label']
|
||||||
|
|
||||||
for (member1,member2,edge) in data['relationships']:
|
member0 = relationship['members'][0]
|
||||||
edge_style = edge
|
member1 = relationship['members'][1]
|
||||||
graph.add_edge(member1, member2, style=edge_style, color='black')
|
graph.add_edge(member0, member1, style=edge_style, color=edge_color)
|
||||||
|
if edge_label is not None:
|
||||||
|
graph.get_edge(member0, member1).attr['label'] = edge_label
|
||||||
|
|
||||||
graph.layout()
|
graph.layout()
|
||||||
graph.draw(settings.output)
|
graph.draw(settings.output)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user