diff --git a/example.json b/example.json index a13fbd7..42d3b59 100644 --- a/example.json +++ b/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"]} ] } diff --git a/example.png b/example.png index 7d7082a..617b6e4 100644 Binary files a/example.png and b/example.png differ diff --git a/polygraph.py b/polygraph.py index 7fe07c7..3d13d10 100755 --- a/polygraph.py +++ b/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)