Linnet · latest
On this page

DiagramView

symbolica.community.graph Class

DiagramView()

A resolved drawing with static exports and optional browser measurements.

Clones retain the same scenes, receipt identity, and completion cells. A widget and its caller therefore observe the same completed snapshot. Each freshly constructed view has a new identity; receipts belong to that view, and a completed view rejects different measurements. SVG/HTML exports are immutable snapshots and never trigger implicit remeasurement.

With the generic graph bindings installed:

from symbolica.community.graph import DotCodec, Graph
graph = Graph.from_dot("graph { a -- b }", DotCodec.topology())
view = graph.render()
static = view.snapshot()  # Complete static output with default settings.
svg = static.to_svg()
measured = view.measured(browser="chromium")  # Explicit Playwright capture.
outlined = view.outlined()  # Optional typst-py vector labels.
static.to_svg() == svg  # Earlier snapshots remain immutable.

Member details

diagrams

Property · read-only#
diagrams: list[DiagramView]

Configured child views for a collection, retaining their original scenes. See [Self] for an example. Returned clones share child completion state.

measurement_request

Method#
measurement_request() -> dict

The exact ordered MathML probes, fixed font, and receipt identity.

See [Self] for the measurement lifecycle. A receipt must echo this request's id and contain one finite, nonnegative rectangle per label in request order. All dimensions and the baseline are SVG user units (points).

# Errors Returns a Python error if bundled font loading, hashing, or request serialization fails. No browser or notebook dependency is imported here.

measured

Method#
measured(measurements: Optional[dict] = None, *, browser: Optional[str] = None) -> DiagramRender

Obtain a completed immutable snapshot, or explicitly measure using Chromium.

See [Self] for an example. Calling without arguments reuses completion; pending labels need either an external receipt or explicit browser mode. The same receipt is idempotent, including through a retained clone. Notebook widgets allow 15 seconds for font-resource transfer, followed by a separate five-second browser layout deadline. Explicit Chromium capture has the font inline and a five-second measurement deadline; expiry raises Python TimeoutError. Widgets retain static output on either timeout.

# Errors Returns ValueError for conflicting arguments, an unsupported browser, stale/malformed receipts, changed measurements, or invalid label sources. Returns RuntimeError while measurement is pending or native rendering fails. Optional browser setup and execution errors propagate as Python errors. Failed capture does not publish this view's completed snapshot; child views already completed remain independently usable.

Parameters

NameTypeDefaultDescription
measurementsOptional[dict]None—
browserOptional[str]None—

outlined

Method#
outlined() -> DiagramRender

Outline labels with the optional Python Typst compiler; no browser is used.

See [Self] for an example. The vector snapshot has its own completion cell, shared by clones, and never changes an existing measured export.

# Errors Returns ValueError if labels lack Typst sources or captured MathML has no retained scene, ImportError if the optional typst package is absent, or a Python error on compilation/rendering failure. Compiler exceptions retain their Python cause via [typst_export::compile_sources].

snapshot

Method#
snapshot(*, browser: Optional[str] = None) -> DiagramRender

Static export owner: completed measurement, optional Typst, then estimates.

Estimates use [LabelSource::estimated_metrics] at the request's fixed 9px STIX style. They never complete measurement; a later receipt replaces them. See [Self::to_svg] for an export example.

# Errors Propagates label validation, optional compiler, and rendering errors.

Parameters

NameTypeDefaultDescription
browserOptional[str]None—

to_svg

Method#
to_svg() -> str

Return a static single-page SVG; see [Self] for an example.

# Errors Propagates [Self::snapshot] errors and rejects multipage snapshots.

to_svg_pages

Method#
to_svg_pages() -> list[str]

Return independent strings for all static pages; see [Self].

# Errors Propagates [Self::snapshot] errors.

to_html

Method#
to_html() -> str

Return static HTML with its shared font resource; see [Self].

# Errors Propagates [Self::snapshot] errors.

save

Method#
save(output: str | os.PathLike | pathlib.Path) -> pathlib.Path

Save a static snapshot, selecting the format by suffix.

from symbolica.community.graph import DotCodec, Graph
view = Graph.from_dot("graph { a -- b }", DotCodec.topology()).render()
path = view.save("diagram.svg")

# Errors Propagates [Self::snapshot] errors, filesystem/export errors, and invalid format/page-count errors. PDF/PNG need an outlined snapshot.

Parameters

NameTypeDefaultDescription
outputstr | os.PathLike | pathlib.Path——

widget

Method#
widget() -> Any

Optional notebook dependencies are imported only when displaying a view. The widget retains a clone of the backend owner until it is closed.

from symbolica.community.graph import DotCodec, Graph
view = Graph.from_dot("graph { a -- b }", DotCodec.topology()).render()
widget = view.widget()  # Requires anywidget in this environment.

# Errors Propagates font/request errors and Python import or widget setup errors.

_repr_mimebundle_

Method#
_repr_mimebundle_(include: Optional[Sequence[str]] = None, exclude: Optional[Sequence[str]] = None) -> Any

Static Jupyter bundle with an optional widget, respecting MIME filters. See [Self::widget] for explicit notebook construction.

# Errors Propagates widget setup and Python MIME protocol errors.

Parameters

NameTypeDefaultDescription
includeOptional[Sequence[str]]None—
excludeOptional[Sequence[str]]None—

_display_

Method#
_display_() -> Any

Marimo adapter: retained widget when available, otherwise isolated HTML. See [Self::widget] for explicit widget construction.

# Errors Propagates widget errors and missing/failed Marimo imports or adapters.

_mime_

Method#
_mime_() -> Any

Marimo MIME hook for [Self::_display_]; see [Self::widget].

# Errors Propagates display adapter and Python MIME protocol errors.

__repr__

Method#
__repr__() -> str

No description is available for this member.