Add ability to color and label edges.

This commit is contained in:
Anna Rose 2014-05-03 14:53:52 -04:00
parent 228e899b66
commit 73ec40414e
3 changed files with 19 additions and 11 deletions

View File

@ -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"]}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -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)