Add relationship types, color-code and style-code edges
This commit is contained in:
parent
1f659d32ee
commit
91ad21eff1
30
polygraph.py
30
polygraph.py
|
@ -3,27 +3,41 @@
|
||||||
import pygraphviz as pgv
|
import pygraphviz as pgv
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# These are the categories to use for color-coding the graph.
|
# These are the attributes to use for color-coding the graphs
|
||||||
# These are highly arbitrary categories that suited my purposes, feel free
|
|
||||||
# to edit them!
|
|
||||||
# fixme: make these configurable
|
# fixme: make these configurable
|
||||||
relationship_colors = { 'yes': 'black',
|
|
||||||
'no': 'grey',
|
# This represents whether a particular relationship involves the
|
||||||
|
# *risk* of fluid exchange. The values are applied to the edge 'style' attribute
|
||||||
|
fluid_colors = { 'yes': 'solid',
|
||||||
|
'no': 'dashed',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Three gender colours, so that we encapsulate masculine, feminine, and a catch-all for other identities
|
||||||
|
# If you'd rather explicitly colour-code other identities, just add them :)
|
||||||
gender_colors = {
|
gender_colors = {
|
||||||
'm': 'blue',
|
'm': 'blue',
|
||||||
'f': 'pink',
|
'f': 'pink',
|
||||||
'o': 'green',
|
'o': 'green',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Relationship types... feel free to edit to suit your poly family's needs
|
||||||
|
relationship_colors = {
|
||||||
|
'v': 'blue',
|
||||||
|
'ds': 'red'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
try:
|
||||||
data = json.load(open('network.dat', 'r'))
|
data = json.load(open('network.dat', 'r'))
|
||||||
|
except Exception as e:
|
||||||
|
print "Error parsing data file: " + str(e)
|
||||||
|
return
|
||||||
|
|
||||||
graph = pgv.AGraph()
|
graph = pgv.AGraph()
|
||||||
graph.node_attr['style'] = 'filled'
|
|
||||||
graph.graph_attr['overlap'] = 'prism'
|
graph.graph_attr['overlap'] = 'prism'
|
||||||
|
graph.node_attr['style'] = 'filled'
|
||||||
|
graph.edge_attr['arrowsize'] = 0.5
|
||||||
|
|
||||||
# Add nodes to graph
|
# Add nodes to graph
|
||||||
for user in data:
|
for user in data:
|
||||||
|
@ -31,8 +45,8 @@ def main():
|
||||||
|
|
||||||
# Add edges to graph
|
# Add edges to graph
|
||||||
for user1 in data:
|
for user1 in data:
|
||||||
for (user2, rel) in user1['connections']:
|
for (user2, rel, fluid) in user1['connections']:
|
||||||
graph.add_edge(user1['name'], user2, color=relationship_colors[rel])
|
graph.add_edge(user1['name'], user2, style=fluid_colors[fluid], color=relationship_colors[rel])
|
||||||
|
|
||||||
graph.layout()
|
graph.layout()
|
||||||
graph.draw('/tmp/graph.png')
|
graph.draw('/tmp/graph.png')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user