Fixed gender colors to be more free-form.

This commit is contained in:
Anna Rose 2014-01-06 10:08:39 -05:00
parent bc6ff95ffc
commit 9a41ae471d
2 changed files with 9 additions and 21 deletions

View File

@ -1,10 +1,10 @@
{ "members": [ { "members": [
{"name": "Alice", "gender": "f"}, {"name": "Alice", "color": "pink"},
{"name": "Bob", "gender": "m"}, {"name": "Bob", "color": "blue"},
{"name": "Sam", "gender": "o"}, {"name": "Sam", "color": "green"},
{"name": "Eve", "gender": "f"}, {"name": "Eve", "color": "pink"},
{"name": "Charles", "gender": "m"}, {"name": "Charles", "color": "blue"},
{"name": "Max", "gender": "o"} {"name": "Max", "color": "yellow"}
], ],
"relationships": [ "relationships": [

View File

@ -4,22 +4,11 @@ import pygraphviz as pgv
import json import json
import argparse import argparse
# These are the attributes to use for color-coding the graphs
# 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 = {
'm': 'blue',
'f': 'pink',
'o': 'green',
}
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description='Generate graphs of polyamorous family networks from data files') parser = argparse.ArgumentParser(description='Generate graphs of polyamorous family networks from data files')
parser.add_argument('--input', '-i', default='network.json', help='Input file in json format') parser.add_argument('--input', '-i', default='network.json', help='Input file in json format')
parser.add_argument('--output', '-o', default='network.png', help='Output image file. Format auto-detected from file extension') parser.add_argument('--output', '-o', default='network.png', help='Output image file. Format auto-detected from file extension')
parser.add_argument('--gender', '-g', action='store_true', help='Indicate gender in output graph') parser.add_argument('--gender', '-g', action='store_true', help='Include gender colors in output graph')
return parser.parse_args() return parser.parse_args()
@ -38,11 +27,10 @@ def main():
graph.edge_attr['arrowsize'] = 0.5 graph.edge_attr['arrowsize'] = 0.5
# Add nodes to graph # Add nodes to graph
gender_color = 'white'
for user in data['members']: for user in data['members']:
gender_color = 'white'
if settings.gender: if settings.gender:
gender_color = gender_colors[user['gender']] gender_color = user['color']
graph.add_node(user['name'], fillcolor=gender_color) graph.add_node(user['name'], fillcolor=gender_color)