33 from distutils.version
import LooseVersion
35 from urllib.request
import quote
37 from urllib
import quote
49 if name
in [
'graph',
'subgraph',
'node',
'edge']:
56 ret = quote(name.strip())
57 ret = ret.replace(
'/',
'__')
58 ret = ret.replace(
'%',
'_')
59 ret = ret.replace(
'-',
'_')
63 self, graph_type=
'digraph', rank=
'same', simplify=
True,
64 rankdir=
'TB', ranksep=0.2, compound=
True):
67 if LooseVersion(pydot.__version__) > LooseVersion(
'1.0.10'):
68 graph = pydot.Dot(
'graphname',
69 graph_type=graph_type,
74 graph.set_ranksep(ranksep)
75 graph.set_compound(compound)
77 graph = pydot.Dot(
'graphname',
78 graph_type=graph_type,
92 Create a node item for this factory, adds it to the graph. 94 Node name can vary from label but must always be same for the same node label 96 if nodename
is None or nodename ==
'':
97 raise ValueError(
'Empty Node name')
101 node.set_shape(shape)
103 if tooltip
is not None:
104 node.set_tooltip(tooltip)
105 elif url
is not None:
106 node.set_tooltip(url)
109 if color
is not None:
110 node.set_color(color)
126 Create a cluster subgraph item for this factory, adds it to the graph. 128 cluster name can vary from label but must always be same for the same node label. 129 Most layouters require cluster names to start with cluster. 131 if subgraphname
is None or subgraphname ==
'':
132 raise ValueError(
'Empty subgraph name')
134 rank=rank, rankdir=rankdir, simplify=simplify)
135 if 'set_style' in g.__dict__:
137 if 'set_shape' in g.__dict__:
139 if LooseVersion(pydot.__version__) > LooseVersion(
'1.0.10'):
140 g.set_compound(compound)
141 g.set_ranksep(ranksep)
142 subgraphlabel = subgraphname
if subgraphlabel
is None else subgraphlabel
145 g.set_label(subgraphlabel)
146 if 'set_color' in g.__dict__:
147 if color
is not None:
149 graph.add_subgraph(g)
153 self, graph, nodename1, nodename2, label=
None, url=
None,
154 simplify=
True, style=
None, penwidth=1, color=
None):
155 if simplify
and LooseVersion(pydot.__version__) < LooseVersion(
'1.0.10'):
159 if label
is not None and label !=
'':
160 edge.set_label(label)
163 if style
is not None:
164 edge.set_style(style)
165 edge.obj_dict[
'attributes'][
'penwidth'] = str(penwidth)
166 if color
is not None:
167 edge.obj_dict[
'attributes'][
'colorR'] = str(color[0])
168 edge.obj_dict[
'attributes'][
'colorG'] = str(color[1])
169 edge.obj_dict[
'attributes'][
'colorB'] = str(color[2])
173 dot = graph.create_dot()
177 return dot.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)