33 from distutils.version
import LooseVersion
35 from urllib.request
import quote
37 from urllib
import quote
50 if name
in [
'graph',
'subgraph',
'node',
'edge']:
57 ret = quote(name.strip())
58 ret = ret.replace(
'/',
'__')
59 ret = ret.replace(
'%',
'_')
60 ret = ret.replace(
'-',
'_')
64 self, graph_type=
'digraph', rank=
'same', simplify=
True,
65 rankdir=
'TB', ranksep=0.2, compound=
True):
68 if LooseVersion(pydot.__version__) > LooseVersion(
'1.0.10'):
69 graph = pydot.Dot(
'graphname',
70 graph_type=graph_type,
75 graph.set_ranksep(ranksep)
76 graph.set_compound(compound)
78 graph = pydot.Dot(
'graphname',
79 graph_type=graph_type,
93 Create a node item for this factory, adds it to the graph. 95 Node name can vary from label but must always be same for the same node label 97 if nodename
is None or nodename ==
'':
98 raise ValueError(
'Empty Node name')
102 node.set_shape(shape)
104 if tooltip
is not None:
105 node.set_tooltip(tooltip)
106 elif url
is not None:
107 node.set_tooltip(url)
110 if color
is not None:
111 node.set_color(color)
127 Create a cluster subgraph item for this factory, adds it to the graph. 129 cluster name can vary from label but must always be same for the same node label. 130 Most layouters require cluster names to start with cluster. 132 if subgraphname
is None or subgraphname ==
'':
133 raise ValueError(
'Empty subgraph name')
135 rank=rank, rankdir=rankdir, simplify=simplify)
136 if 'set_style' in g.__dict__:
138 if 'set_shape' in g.__dict__:
140 if LooseVersion(pydot.__version__) > LooseVersion(
'1.0.10'):
141 g.set_compound(compound)
142 g.set_ranksep(ranksep)
143 subgraphlabel = subgraphname
if subgraphlabel
is None else subgraphlabel
146 g.set_label(subgraphlabel)
147 if 'set_color' in g.__dict__:
148 if color
is not None:
150 graph.add_subgraph(g)
154 self, graph, nodename1, nodename2, label=
None, url=
None,
155 simplify=
True, style=
None, penwidth=1, color=
None):
156 if simplify
and LooseVersion(pydot.__version__) < LooseVersion(
'1.0.10'):
160 if label
is not None and label !=
'':
161 edge.set_label(label)
164 if style
is not None:
165 edge.set_style(style)
166 edge.obj_dict[
'attributes'][
'penwidth'] = str(penwidth)
167 if color
is not None:
168 edge.obj_dict[
'attributes'][
'colorR'] = str(color[0])
169 edge.obj_dict[
'attributes'][
'colorG'] = str(color[1])
170 edge.obj_dict[
'attributes'][
'colorB'] = str(color[2])
174 dot = graph.create_dot()
178 return dot.replace(
'\\%s' % os.linesep,
'').replace(
'\\\n',
'')
def get_graph(self, graph_type='digraph', rank='same', simplify=True, rankdir='TB', ranksep=0.2, compound=True)
def add_node_to_graph(self, graph, nodename, nodelabel=None, shape='box', color=None, url=None, tooltip=None)
def escape_label(self, name)
def create_dot(self, graph)
def add_subgraph_to_graph(self, graph, subgraphname, rank='same', simplify=True, rankdir='TB', ranksep=0.2, compound=True, color=None, shape='box', style='bold', subgraphlabel=None)
def escape_name(self, name)
def add_edge_to_graph(self, graph, nodename1, nodename2, label=None, url=None, simplify=True, style=None, penwidth=1, color=None)