Skip to content

Commit

Permalink
Move to graphviz pure python library.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfreckleton committed Mar 30, 2017
1 parent 762ddb2 commit 0675d77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 20 additions & 14 deletions graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import collections
import textwrap
import sys
import pygraphviz
import graphviz
import parser

Entity = collections.namedtuple("Entity", "id label cls")
Expand Down Expand Up @@ -75,21 +75,27 @@ def create_graph(semantic_graph):
splines = 'spline'
if semantic_graph.loop_edges or semantic_graph.and_loop_edges:
splines = 'ortho'
g = pygraphviz.AGraph(directed=True, rankdir="BT", splines=splines)
g.node_attr['shape'] = 'rectangle'
g.node_attr['style'] = 'rounded,filled'
g.node_attr['fillcolor'] = '#FFFFCC'
g = graphviz.Digraph(
graph_attr={'rankdir':'BT', 'splines':splines},
node_attr={
'shape':'rectangle', 'style':'rounded,filled', 'fillcolor':'#FFFFCC'
}
)
for identifier, label, cls in semantic_graph.nodes:
g.add_node(identifier, label=label, **attrs[cls])
g.add_edges_from(semantic_graph.edges)
g.add_edges_from(semantic_graph.and_edges, dir="none")
g.add_edges_from(semantic_graph.loop_edges, constraint=False)
g.add_edges_from(semantic_graph.and_loop_edges, dir="none", constraint=False)
g.node(identifier, label=label, **attrs[cls])
g.edges(semantic_graph.edges)
for e in semantic_graph.and_edges:
g.edge(e, dir="none")
for e in semantic_graph.loop_edges:
g.edge(e, constraint=False)
for e in semantic_graph.and_loop_edges:
g.edge(e, dir="none", constraint=False)
for a, b in semantic_graph.conflicts:
g.add_edge(a, b, style="tapered", dir="both", arrowhead=None,
arrowtail=None, constraint=False, color="red", penwidth=7)
g.add_subgraph([a,b], name="cluster", rank="same", color=None)
return g.to_string()
subgraph = graphviz.Digraph('cluster', graph_attr={'rank':'same', 'color':'none'})
subgraph.edge(a, b, style="tapered", dir="both", arrowhead="none",
arrowtail="none", constraint="false", color="red", penwidth="7")
g.subgraph(subgraph)
return g

if __name__ == "__main__":
if not sys.argv[1:]:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
grako==3.10.0
graphviz==0.6

0 comments on commit 0675d77

Please sign in to comment.