Skip to content
v0.2.1

Graph

EdgeArrow = Literal['triangle', 'circle-triangle', 'triangle-backcurve', 'tee', 'circle', 'chevron', 'triangle-tee', 'triangle-cross', 'vee', 'square', 'diamond'] | None
class EdgeStyle(BaseModel):

Visual style options for a GraphEdge.

Attributes:

  • dashed bool — Renders the edge as a dashed line.
  • bold bool — Renders the edge as a bold line.
Source
class EdgeStyle(BaseModel):
"""Visual style options for a `GraphEdge`.
Attributes:
dashed: Renders the edge as a dashed line.
bold: Renders the edge as a bold line.
"""
dashed: bool = False
bold: bool = False
class ElkLayoutConfig(BaseModel):

ELK-based layout configuration for a Graph visualization.

Attributes:

  • options dict[str, str | int | float | bool] | None — Additional ELK layout options passed directly to the renderer. Keys and values mirror the ELK option format (e.g. {"elk.algorithm": "force"}).

For all available options see https://eclipse.dev/elk/reference/options.html.

Source
class ElkLayoutConfig(BaseModel):
"""ELK-based layout configuration for a `Graph` visualization.
Attributes:
options: Additional ELK layout options passed directly to the renderer.
Keys and values mirror the ELK option format (e.g. ``{"elk.algorithm": "force"}``).
For all available options see https://eclipse.dev/elk/reference/options.html.
"""
type: Literal["elk"] = "elk"
options: dict[str, str | int | float | bool] | None = None
class Graph(Visualization):

Graph visualization composed of nodes and directed edges.

This visualization is meant for model-like structures (for example Petri nets or directly-follows graphs). Layout is performed by the frontend renderer (ELK).

Attributes:

  • type Literal['graph'] — Fixed discriminator "graph".
  • nodes list[GraphNode] — List of nodes.
  • edges list[GraphEdge] — List of edges.
  • layout_config LayoutConfig — Layout hints consumed by the renderer.
Source
class Graph(Visualization):
"""Graph visualization composed of nodes and directed edges.
This visualization is meant for model-like structures (for example Petri nets
or directly-follows graphs). Layout is performed by the frontend renderer (ELK).
Attributes:
type: Fixed discriminator `"graph"`.
nodes: List of nodes.
edges: List of edges.
layout_config: Layout hints consumed by the renderer.
"""
type: Literal["graph"] = "graph"
nodes: list[GraphNode] = Field(default_factory=list)
edges: list[GraphEdge] = Field(default_factory=list)
layout_config: LayoutConfig = Field(default_factory=ElkLayoutConfig)
class GraphEdge(AnnotatedElement):

A directed edge in a Graph visualization.

An edge connects source -> target and can carry labels and arrowhead styles.

Attributes:

  • id str — Unique edge id. Defaults to a generated UUID string.
  • source str — Source node id.
  • target str — Target node id.
  • color str | None — Optional edge color.
  • label str | None — Optional label shown along the edge.
  • style EdgeStyle — Visual style options.
  • start_arrow EdgeArrow — Optional arrowhead style at the start of the edge.
  • end_arrow EdgeArrow — Optional arrowhead style at the end of the edge.
  • start_label str | None — Optional label shown near the source.
  • end_label str | None — Optional label shown near the target.
  • annotation T | None — Optional attached visualization.
Source
class GraphEdge(AnnotatedElement):
"""A directed edge in a `Graph` visualization.
An edge connects `source` -> `target` and can carry labels and arrowhead styles.
Attributes:
id: Unique edge id. Defaults to a generated UUID string.
source: Source node id.
target: Target node id.
color: Optional edge color.
label: Optional label shown along the edge.
style: Visual style options.
start_arrow: Optional arrowhead style at the start of the edge.
end_arrow: Optional arrowhead style at the end of the edge.
start_label: Optional label shown near the source.
end_label: Optional label shown near the target.
annotation: Optional attached visualization.
"""
id: str = Field(default_factory=uuid_factory)
source: str
target: str
color: str | None = None
label: str | None = None
style: EdgeStyle = EdgeStyle()
start_arrow: EdgeArrow = None
end_arrow: EdgeArrow = None
start_label: str | None = None
end_label: str | None = None
layout_attrs: dict[str, str | int | float | bool] | None = None
class GraphNode(AnnotatedElement):

A node in a Graph visualization.

A node defines its identity and visual appearance (shape, label, colors, size). Layout coordinates (x, y) are typically filled by the layouting step, not by the resource author.

Attributes:

  • id str — Unique node id. Defaults to a generated UUID string.
  • label str | None — Optional label shown near the node.
  • shape GraphShapes — Node shape identifier.
  • width float | None — Optional node width.
  • height float | None — Optional node height.
  • color str | None — Optional fill color (for example hex).
  • x float | None — Optional x-coordinate after layouting.
  • y float | None — Optional y-coordinate after layouting.
  • border_color str | None — Optional border/stroke color.
  • style NodeStyle — Visual style options.
  • label_pos Literal['top', 'center', 'bottom'] — Label position relative to the node.
  • rank Literal['source', 'sink'] | int | None — Optional layout constraint (source/sink or numeric rank).
  • annotation T | None — Optional attached visualization.
Source
class GraphNode(AnnotatedElement):
"""A node in a `Graph` visualization.
A node defines its identity and visual appearance (shape, label, colors, size).
Layout coordinates (`x`, `y`) are typically filled by the layouting step, not
by the resource author.
Attributes:
id: Unique node id. Defaults to a generated UUID string.
label: Optional label shown near the node.
shape: Node shape identifier.
width: Optional node width.
height: Optional node height.
color: Optional fill color (for example hex).
x: Optional x-coordinate after layouting.
y: Optional y-coordinate after layouting.
border_color: Optional border/stroke color.
style: Visual style options.
label_pos: Label position relative to the node.
rank: Optional layout constraint (source/sink or numeric rank).
annotation: Optional attached visualization.
"""
id: str = Field(default_factory=uuid_factory)
label: str | None = None
shape: GraphShapes
width: float | None = None
height: float | None = None
color: str | None = None
x: float | None = None
y: float | None = None
border_color: str | None = None
style: NodeStyle = NodeStyle()
label_pos: Literal["top", "center", "bottom"] = "center"
rank: Literal["source", "sink"] | int | None = None
layout_attrs: dict[str, str | int | float | bool] | None = None
GraphShapes = Literal['circle', 'triangle', 'rectangle', 'diamond', 'hexagon']
class GraphvizLayoutConfig(BaseModel):
Source
class GraphvizLayoutConfig(BaseModel):
type: Literal["graphviz"] = "graphviz"
engine: GraphvizLayoutEngineName = "dot"
graphAttrs: dict[str, str | int | float | bool] | None = None
nodeAttrs: dict[str, str | int | float | bool] | None = None
edgeAttrs: dict[str, str | int | float | bool] | None = None
LayoutConfig = Annotated[Union[GraphvizLayoutConfig, ElkLayoutConfig], Field(discriminator='type')]
class NodeStyle(BaseModel):

Visual style options for a GraphNode.

Attributes:

  • double_border bool — Renders a second border inside the node (e.g. final-marking places).
  • inner_symbol Literal['triangle', 'square'] | None — Optional symbol rendered inside the node shape.
  • initial_tokens int | None — Optional initial token count rendered inside a place node.
  • final_tokens int | None — Optional final token count rendered inside a place node.
Source
class NodeStyle(BaseModel):
"""Visual style options for a `GraphNode`.
Attributes:
double_border: Renders a second border inside the node (e.g. final-marking places).
inner_symbol: Optional symbol rendered inside the node shape.
initial_tokens: Optional initial token count rendered inside a place node.
final_tokens: Optional final token count rendered inside a place node.
"""
double_border: bool = False
inner_symbol: Literal["triangle", "square"] | None = None
initial_tokens: int | None = None
final_tokens: int | None = None
DIRECTED_ELK_GRAPH_LAYOUT = ElkLayoutConfig(options={'elk.algorithm': 'layered', 'elk.direction': 'RIGHT', 'elk.edgeRouting': 'SPLINES', 'elk.hierarchyHandling': 'INCLUDE_CHILDREN', 'elk.separateConnectedComponents': True, 'elk.spacing.nodeNode': 48, 'elk.spacing.edgeNode': 24, 'elk.spacing.edgeEdge': 16, 'elk.spacing.componentComponent': 96, 'elk.layered.cycleBreaking.strategy': 'GREEDY', 'elk.layered.layering.strategy': 'NETWORK_SIMPLEX', 'elk.layered.crossingMinimization.strategy': 'LAYER_SWEEP', 'elk.layered.crossingMinimization.greedySwitch.type': 'TWO_SIDED', 'elk.layered.crossingMinimization.greedySwitch.activationThreshold': 40, 'elk.layered.nodePlacement.strategy': 'NETWORK_SIMPLEX', 'elk.layered.nodePlacement.favorStraightEdges': True, 'elk.layered.spacing.nodeNodeBetweenLayers': 120, 'elk.layered.spacing.edgeNodeBetweenLayers': 36, 'elk.layered.spacing.edgeEdgeBetweenLayers': 18, 'elk.layered.thoroughness': 15, 'elk.layered.unnecessaryBendpoints': False})

High-quality ELK layered layout for large directed model graphs.

This is the preferred ELK preset for large Petri nets: it favors a stable left-to-right flow, spline edges, explicit layer spacing, and stronger crossing minimization without forcing frontend-specific defaults.

FORCE_GRAPH_LAYOUT = GraphvizLayoutConfig(engine='sfdp', graphAttrs={'overlap': 'false', 'splines': 'spline'})

Force-directed layout for general non-hierarchical graphs.

Useful for dense or cyclic graphs where neither layering nor a radial root produces a readable result.

DIRECTED_GRAPH_LAYOUT = GraphvizLayoutConfig(engine='dot', graphAttrs={'rankdir': 'LR', 'nodesep': 0.35, 'ranksep': 0.55, 'splines': 'spline'})

Left-to-right layered layout for directed model graphs.

Useful for process models, directly-follows graphs, Petri nets, and other graphs where edge direction should communicate progression.

ORDERED_TREE_LAYOUT = GraphvizLayoutConfig(engine='dot', graphAttrs={'ordering': 'out', 'rankdir': 'TB', 'nodesep': 0.3, 'ranksep': 0.5, 'splines': 'line'})

Top-down tree layout that preserves child order from the edge list.

Useful for process trees, expression trees, parse trees, and other rooted structures where sibling order carries meaning.

RADIAL_GRAPH_LAYOUT = GraphvizLayoutConfig(engine='twopi', graphAttrs={'ranksep': 0.85, 'splines': 'spline', 'overlap': 'false'})

Radial layout for connected relationship graphs.

Useful for object-to-object graphs or social-style networks where there is no single process direction and neighborhoods matter more than layers.