Skip to content

Allow creating graphs with parameterized Node and Edge instances#54

Merged
philippjfr merged 2 commits intomainfrom
node_edge_instances
Mar 13, 2026
Merged

Allow creating graphs with parameterized Node and Edge instances#54
philippjfr merged 2 commits intomainfrom
node_edge_instances

Conversation

@philippjfr
Copy link
Copy Markdown
Contributor

Summary

This PR adds first-class instance-based graph elements to Panel-ReactFlow by introducing Node and Edge base classes and wiring them into the core sync/event/editor pipeline.

Users can now pass Node/Edge objects directly (not just dicts), define reusable subclasses with parameters, and build object-oriented graph workflows with automatic two-way data synchronization.

What’s included

  • Added new base classes:
    • Node (with shared node fields, to_dict(), optional __panel__, editor hook, on_* hooks)
    • Edge (with shared edge fields, to_dict(), editor hook, on_* hooks)
  • Exported Node and Edge in package API.
  • Updated ReactFlow to accept/retain Node and Edge instances in nodes/edges.
  • Serialization of instances happens only in _process_param_change.
  • Added per-instance event hook dispatch for nodes/edges (on_event, on_add, on_delete, etc.).
  • Added per-instance editor support (node.editor(...), edge.editor(...)).
  • Added automatic two-way parameter <-> data behavior for subclass params with precedence >= 0:
    • included in data
    • included in auto-generated schema (when no explicit schema provided)
    • parameter changes auto-trigger data patch + frontend sync
    • incoming data patches/sync update matching instance parameters
  • Added watcher lifecycle management and cleanup when nodes/edges are removed/replaced.

Docs

  • Updated guides to document:
    • class-based nodes/edges
    • __panel__ usage
    • parameter/data sync semantics
    • precedence rule (>= 0) for data/schema inclusion
    • event behavior for parameter-driven patches
  • Added/updated examples, including complex instance-based workflows and a Three.js instance-based variant.

Tests

Added/extended tests to cover:

  • acceptance of Node/Edge instances
  • sync and patch behavior updating instance state directly
  • hook dispatch behavior
  • per-instance editor resolution
  • parameter inclusion in data + schema generation
  • automatic param-change patching
  • watcher cleanup on delete
  • bokeh model children initialization for view/editor child trees

All relevant tests pass locally.


Test plan

  • pytest tests/test_api.py tests/test_core.py -q
  • Verify examples compile:
    • python -m py_compile examples/node_edge_instances.py
    • python -m py_compile examples/threejs_viewer_instances.py
  • Manual UI smoke test (recommended):
    • Run example app(s), modify parameter-bound widgets, confirm graph data and viewer update immediately
    • Add/remove instance nodes and edges, confirm no stale behavior or leaks

Backward compatibility

  • Existing dict / NodeSpec / EdgeSpec usage is preserved.
  • New instance-based APIs are additive and optional.

@philippjfr philippjfr merged commit 0a3e354 into main Mar 13, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant