Generate a GraphViz Dot graph. Returns a GraphViz Digraph object.
(self)
| 307 | return getrandbits(64) |
| 308 | |
| 309 | def build_dot(self): |
| 310 | """Generate a GraphViz Dot graph. |
| 311 | |
| 312 | Returns a GraphViz Digraph object. |
| 313 | """ |
| 314 | from graphviz import Digraph |
| 315 | |
| 316 | # Build GraphViz Digraph |
| 317 | dot = Digraph() |
| 318 | dot.attr("graph", |
| 319 | bgcolor=self.theme["background_color"], |
| 320 | color=self.theme["outline_color"], |
| 321 | fontsize=self.theme["font_size"], |
| 322 | fontcolor=self.theme["font_color"], |
| 323 | fontname=self.theme["font_name"], |
| 324 | margin=self.theme["margin"], |
| 325 | pad=self.theme["padding"]) |
| 326 | dot.attr("node", shape="box", |
| 327 | style="filled", margin="0,0", |
| 328 | fillcolor=self.theme["fill_color"], |
| 329 | color=self.theme["outline_color"], |
| 330 | fontsize=self.theme["font_size"], |
| 331 | fontcolor=self.theme["font_color"], |
| 332 | fontname=self.theme["font_name"]) |
| 333 | dot.attr("edge", style="solid", |
| 334 | color=self.theme["outline_color"], |
| 335 | fontsize=self.theme["font_size"], |
| 336 | fontcolor=self.theme["font_color"], |
| 337 | fontname=self.theme["font_name"]) |
| 338 | |
| 339 | for k, n in self.nodes.items(): |
| 340 | label = "<tr><td cellpadding='6'>{}</td></tr>".format(n.title) |
| 341 | if n.caption: |
| 342 | label += "<tr><td>{}</td></tr>".format(n.caption) |
| 343 | if n.repeat > 1: |
| 344 | label += "<tr><td align='right' cellpadding='2'>x{}</td></tr>".format(n.repeat) |
| 345 | label = "<<table border='0' cellborder='0' cellpadding='0'>" + label + "</table>>" |
| 346 | dot.node(str(k), label) |
| 347 | for a, b, label in self.edges: |
| 348 | if isinstance(label, (list, tuple)): |
| 349 | label = "x".join([str(l or "?") for l in label]) |
| 350 | |
| 351 | dot.edge(str(a), str(b), label) |
| 352 | return dot |
| 353 | |
| 354 | def _repr_svg_(self): |
| 355 | """Allows Jupyter notebook to render the graph automatically.""" |
no outgoing calls