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": [
|
||||
["Sam", "Max", "solid"],
|
||||
["Sam", "Eve", "solid"],
|
||||
["Max", "Eve", "solid"],
|
||||
["Sam", "Bob", "solid"],
|
||||
["Alice", "Bob", "dashed"],
|
||||
["Alice", "Charles", "solid"],
|
||||
["Charles", "Max", "dashed"]
|
||||
{"members": ["Sam", "Max"]},
|
||||
{"members": ["Sam", "Eve"], "color": "red"},
|
||||
{"members": ["Max", "Eve"], "label": "friends+"},
|
||||
{"members": ["Sam", "Bob"], "color": "yellow", "label": "cuddle friends"},
|
||||
{"members": ["Alice", "Bob"], "style": "dashed"},
|
||||
{"members": ["Alice", "Charles"]},
|
||||
{"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)
|
||||
|
||||
# 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']:
|
||||
edge_style = edge
|
||||
graph.add_edge(member1, member2, style=edge_style, color='black')
|
||||
member0 = relationship['members'][0]
|
||||
member1 = relationship['members'][1]
|
||||
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.draw(settings.output)
|
||||
|
|
Loading…
Reference in New Issue
Block a user