Browse Source

Allow any graph attribute in `pydot__tree_to_png`.

Keeping the explicit `rankdir="LR"` as default, add `kwargs`
to `pydot__tree_to_png` and `pydot.Dot` so that all graphviz
attributes are available for the graph.
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.7.2
fbindel 6 years ago
parent
commit
09afcfcfc7
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      lark/tree.py

+ 6
- 4
lark/tree.py View File

@@ -141,17 +141,19 @@ class SlottedTree(Tree):
__slots__ = 'data', 'children', 'rule', '_meta'


def pydot__tree_to_png(tree, filename, rankdir="LR"):
def pydot__tree_to_png(tree, filename, rankdir="LR", **kwargs):
"""Creates a colorful image that represents the tree (data+children, without meta)

Possible values for `rankdir` are "TB", "LR", "BT", "RL", corresponding to
directed graphs drawn from top to bottom, from left to right, from bottom to
top, and from right to left, respectively. See:
https://www.graphviz.org/doc/info/attrs.html#k:rankdir
top, and from right to left, respectively.

`kwargs` can be any graph attribute (e. g. `dpi=200`). For a list of
possible attributes, see https://www.graphviz.org/doc/info/attrs.html.
"""

import pydot
graph = pydot.Dot(graph_type='digraph', rankdir=rankdir)
graph = pydot.Dot(graph_type='digraph', rankdir=rankdir, **kwargs)

i = [0]



Loading…
Cancel
Save