Skip to content

DiagramView

Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.

DiagramView

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. True

Attributes

Name Description
diagrams Configured child views for a collection, retaining their original scenes

diagrams

DiagramView.diagrams: builtins.list[DiagramView]

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

Methods

Name Description
__repr__
_display_ Marimo adapter: retained widget when available, otherwise isolated HTML
_mime_ Marimo MIME hook for [Self::_display_]; see [Self::widget].
_repr_mimebundle_ Static Jupyter bundle with an optional widget, respecting MIME filters
measured Obtain a completed immutable snapshot, or explicitly measure using Chromium
measurement_request The exact ordered MathML probes, fixed font, and receipt identity
outlined Outline labels with the optional Python Typst compiler; no browser is used
save Save a static snapshot, selecting the format by suffix.
snapshot Static export owner: completed measurement, optional Typst, then estimates
to_html Return static HTML with its shared font resource; see [Self].
to_svg Return a static single-page SVG; see [Self] for an example.
to_svg_pages Return independent strings for all static pages; see [Self].
widget Optional notebook dependencies are imported only when displaying a view

__repr__

DiagramView.__repr__() -> builtins.str

_display_

DiagramView._display_() -> typing.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_

DiagramView._mime_() -> typing.Any

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

Errors

Propagates display adapter and Python MIME protocol errors.

_repr_mimebundle_

DiagramView._repr_mimebundle_(
    include: typing.Optional[typing.Sequence[builtins.str]] = None,
    exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
) -> typing.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.

measured

DiagramView.measured(
    measurements: typing.Optional[dict] = None,
    *,
    browser: typing.Optional[builtins.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.

measurement_request

DiagramView.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.

outlined

DiagramView.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].

save

DiagramView.save(output: builtins.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.

snapshot

DiagramView.snapshot(*, browser: typing.Optional[builtins.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.

to_html

DiagramView.to_html() -> builtins.str

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

Errors

Propagates [Self::snapshot] errors.

to_svg

DiagramView.to_svg() -> builtins.str

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

Errors

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

to_svg_pages

DiagramView.to_svg_pages() -> builtins.list[builtins.str]

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

Errors

Propagates [Self::snapshot] errors.

widget

DiagramView.widget() -> typing.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.