Add documentation and port to python3.
This commit is contained in:
parent
73ec40414e
commit
8b14daf190
18
polygraph.py
18
polygraph.py
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import pygraphviz as pgv
|
import pygraphviz as pgv
|
||||||
import json
|
import json
|
||||||
|
@ -18,7 +18,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
data = json.load(open(settings.input, 'r'))
|
data = json.load(open(settings.input, 'r'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "Error parsing data file: " + str(e)
|
print("Error parsing data file: " + str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
graph = pgv.AGraph()
|
graph = pgv.AGraph()
|
||||||
|
@ -29,19 +29,23 @@ def main():
|
||||||
# Add nodes to graph
|
# Add nodes to graph
|
||||||
for user in data['members']:
|
for user in data['members']:
|
||||||
node_color = 'white'
|
node_color = 'white'
|
||||||
if settings.color and user.has_key('color'):
|
if settings.color and 'color' in user:
|
||||||
node_color = user['color']
|
node_color = user['color']
|
||||||
|
|
||||||
graph.add_node(user['name'], fillcolor=node_color)
|
graph.add_node(user['name'], fillcolor=node_color)
|
||||||
|
|
||||||
|
# if user.has_key('cloud') and user['cloud'] = true:
|
||||||
|
# graph.add_node()
|
||||||
|
# graph.add_edge()
|
||||||
|
|
||||||
|
|
||||||
# Add edges to graph
|
# Add edges to graph
|
||||||
for relationship in data['relationships']:
|
for relationship in data['relationships']:
|
||||||
edge_style = 'solid'
|
edge_style = 'solid'
|
||||||
if relationship.has_key('style'): edge_style = relationship['style']
|
if 'style' in relationship: edge_style = relationship['style']
|
||||||
edge_color = 'black'
|
edge_color = 'black'
|
||||||
if relationship.has_key('color'): edge_color = relationship['color']
|
if 'color' in relationship: edge_color = relationship['color']
|
||||||
edge_label = None
|
edge_label = None
|
||||||
if relationship.has_key('label'): edge_label = relationship['label']
|
if 'label' in relationship: edge_label = relationship['label']
|
||||||
|
|
||||||
member0 = relationship['members'][0]
|
member0 = relationship['members'][0]
|
||||||
member1 = relationship['members'][1]
|
member1 = relationship['members'][1]
|
||||||
|
|
23
readme.md
Normal file
23
readme.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Polygraph - polycule visualization for nerds
|
||||||
|
|
||||||
|
This program is a thin shell on top of pygraphviz aimed at making it easy to draw a graph of your polyamorous network.
|
||||||
|
|
||||||
|
It can, of course, be trivially used for anyone who wants a quick way to define a graph and render it; it's just
|
||||||
|
a thin shell on top of a few of pygraphviz' features. Feel free to use it for anything that seems useful to you!
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
On Ubuntu, just run:
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo apt install graphviz-dev python3-pydot
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Now you can define a graph file and run the tool with:
|
||||||
|
|
||||||
|
```
|
||||||
|
./polygraph.py -i <input_file.json> -o <output_file.json>
|
||||||
|
```
|
||||||
|
|
||||||
|
See `./polygraph.py --help` for more detailed options.
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pygraphviz
|
Loading…
Reference in New Issue
Block a user