GraphRenderer

GraphRenderer(graph: OmkGraph, config: VisualizationConfig | None = None)

Draws an OmkGraph.

to_dot needs nothing installed. to_svg and to_png run Graphviz’s dot, which must be on the PATH, and raise GraphvizNotFoundError when it is not.

In Jupyter, a renderer left as a cell’s value is drawn as SVG; without Graphviz it falls back to its plain repr.

The DOT model is built afresh on every call: the graph is mutable, and a renderer is cheap to keep around.

>>> from openmusickit.graph.graph import GraphMeta
>>> from openmusickit.objects.note_event import NoteEvent
>>> from openmusickit.systems.wsmn.temporal.symbols import quarter
>>> from openmusickit.systems.wsmn.tonal.symbols import C, D
>>> graph = OmkGraph(GraphMeta())
>>> c, d = (NoteEvent(tones={t}, duration=quarter) for t in (C, D))
>>> graph.add_line([c, d])
>>> dot = GraphRenderer(graph).to_dot()
>>> dot.startswith("digraph {"), 'rankdir="LR"' in dot, f'"{c.id}" -> "{d.id}"' in dot
(True, True, True)

Attributes

Name Description
graph
config

Methods

Name Description
__init__
dot_graph The DOT model (see dot.DotGraph) of the graph under this config.
to_dot The DOT source.
to_svg The picture as SVG, rendered by the local Graphviz.
to_png The picture as PNG bytes, rendered by the local Graphviz.

__init__

__init__(graph: OmkGraph, config: VisualizationConfig | None = None)

dot_graph

dot_graph()

The DOT model (see dot.DotGraph) of the graph under this config.

to_dot

to_dot()

The DOT source.

to_svg

to_svg()

The picture as SVG, rendered by the local Graphviz.

Raises

Name Type Description
GraphvizNotFoundError if dot is not on the PATH.
RenderingError if Graphviz rejected the DOT.

to_png

to_png()

The picture as PNG bytes, rendered by the local Graphviz.

Raises

Name Type Description
GraphvizNotFoundError if dot is not on the PATH.
RenderingError if Graphviz rejected the DOT.