dagre graph rendering for spaday
Overview
spaday-dagre renders directed graphs in spaday from a
serializable node/edge config, laid out by @dagrejs/dagre and
drawn as light-DOM SVG. Colors ride the spaday shell's --spa-* tokens, so
bind_root_class("wa-dark", ...) re-themes the graph with the rest of the page, and application CSS
reaches every shape. dagre-node-click bubbles {id, label, x, y} and dagre-edge-click bubbles
{source, target, label, x, y} — the graph context plus the pointer position — so
SetField("selected", event_value("id")) selects and open_popup(..., x=event_value("x"), y=event_value("y")) positions. Right-clicking a node or edge bubbles dagre-node-contextmenu /
dagre-edge-contextmenu with the same shape, pairing with spaday's open_popup for context menus.
Navigation is dagre-d3-class: cursor-anchored wheel zoom, drag pan (clamped so the graph can never
be dragged out of view), double-click reset, and an optional GitHub-mermaid-style D-pad
(controls) with pan arrows around a center reset circle.
Quick example
from spaday import element
from spaday.backends.starlette import serve
from spaday_dagre import Dagre, package
graph = Dagre(
graph={
"nodes": [{"id": "a", "label": "Alpha"}, {"id": "b", "shape": "diamond"}],
"edges": [{"source": "a", "target": "b", "label": "flow"}],
},
layout={"rankdir": "LR"},
controls=True,
)
app = serve(element("main").child(graph), packages=[package])
Node sizes default from label measurement; per-node width/height/class/shape (rect,
diamond, ellipse) and per-edge label/class override. The maxLabelWidth prop (px) caps
label-driven width: wider labels are ellipsized, with the full label as a native tooltip. layout
passes through to dagre (rankdir, align, nodesep,
ranksep, edgesep, marginx/marginy, ranker). Installing the package registers the dagre
entry point, so packages=["dagre"] also works.
Theming
Component-scoped tokens layer over the shell's --spa-* tokens, so an application can theme the
graph from the host (or any ancestor) without knowing its internals — a token set once wins in both
light and dark page modes:
| Token | Themes |
|---|---|
--dagre-node-fill |
node shape fill |
--dagre-node-stroke |
node shape outline |
--dagre-node-text |
node label text |
--dagre-edge-stroke |
edge lines and arrowheads |
--dagre-edge-label |
edge label text |
--dagre-accent |
hover, connected-endpoint, and emphasis affordances |
Node and edge class values are forwarded onto the rendered <g> groups (alongside
spaday-dagre-node / spaday-dagre-edge), so custom classes are CSS-targetable directly. One
variant is built in: a node or edge whose class includes emphasis gets an accent outline.
Run the local example
python -m spaday_dagre.example
Open http://127.0.0.1:8016: a pipeline DAG live over a transports wire — the server sweeps an active-stage highlight through the graph while node/edge selection rides back as model edits — with direction switching, mixed node shapes, a right-click menu for nodes and edges, view controls, and the dark-mode toggle.
[!NOTE] This library was generated using copier from the Base Python Project Template repository.
Metadata
Release files for spaday-dagre 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spaday_dagre-0.2.0.tar.gz | 179.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spaday_dagre-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 309.3 kB
Release files / spaday_dagre-0.2.0.tar.gz
| Download URL | spaday_dagre-0.2.0.tar.gz |
|---|---|
| Size | 179.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20a7e195751f5866dbaba16409dc03e18d18f7c188e4a1e9fe730ee08b90b233
|
|
BLAKE2b-256 checksum How to use checksums |
7a412f8d7606dbbe4852ae3a213e92683bacf02aed42c982d2d62143c095a14a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / spaday_dagre-0.2.0-py3-none-any.whl
| Download URL | spaday_dagre-0.2.0-py3-none-any.whl |
|---|---|
| Size | 129.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48964289ed8219167092615ccee1b115cd00b3b236528c5e95db629da16578c5
|
|
BLAKE2b-256 checksum How to use checksums |
e11854a9f9f1e5b55f86d710ec9f0b3c5582b7f4c918b7841d09ded70b5bca74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|