Skip to content

feat: linked axes across dashboard figures - #77

Merged
jvdd merged 33 commits into
mainfrom
feat/linked-axes
Sep 24, 2026
Merged

jvdd merged 33 commits into
mainfrom
feat/linked-axes

Conversation

@jvdd

@jvdd jvdd commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

Zooming one figure did not move the others. For a dashboard of several time series, the user had to zoom each figure by hand. Linked axes share one range: zoom, pan, double-click or reset one of them, and the others follow. Every affected figure re-aggregates at the new range, in one request.

dash.link_axes(on="timestamp")                 # every figure that shows the column
dash.link_axes(temp, hum, on="timestamp")      # only these figures
dash.link_axes(temp, hum, axis="y")            # the same axis of each figure
dash.link_axes((temp, "x"), (hist, "y"))       # explicit (figure, axis) pairs

What

Event refactor (commit 1). A viewport event no longer carries axis_ranges and figure_uid. It names the state.viewport keys it changed (viewport_keys), and the engine reads every range from state. One event can therefore re-aggregate several figures. The engine rule is the same for every event type: a trace re-aggregates when one of its recompute_axes is listed for its figure, or on force_update. A figure is never filtered by its own selection, so traces are partitioned by selection owner, with one pass per partition. A single-figure zoom stays one pass. The unfiltered domain probe runs once per request for all partitions.

Removed, because no client used them: POST /update (a single figure is shown as a one-figure dashboard), parse_event on AbstractAdapter and PlotlyAdapter, and the "reset" event type. state.viewport keys must now be "<figure_uid>/<axis_id>" and name a figure of the spec. The spec version stays 0.6: 0.6 is unreleased, and v0.1.0b3 shipped 0.5.

Linking (commits 4 and 5).

  • ClientState.axis_links holds groups of viewport keys. The engine never reads it.
  • In the browser, one writer (fvWriteViewport) writes a range to every key of a group. fvCommitViewportChange redraws the other moved figures from state and sends one request, only when a changed axis binds a trace somewhere. Plotly.react fires no relayout, so the redraws post nothing.
  • Panel reset and double-click reset the whole group. A lock toggle reaches every member, so a locked member pins the group.
  • One DashboardSpec validator runs at every entry point (builder, share URL, import, flexvizApply, each request). It rejects:
    • a group with fewer than two keys, or a key in two groups;
    • an axis other than x and y;
    • an axis without a data column (count axes, bars, maps);
    • a log axis, or reversed and normal axes in one group;
    • unequal linked ranges (None counts as absent), or mixed locks.
  • The builder adds the one check that needs the schema: numeric and temporal axes do not mix. Date and datetime axes do mix.
  • history.record_state validates the whole spec and keeps axis_links when a client_state patch omits them.

Bugs on main fixed on the way.

  • In overlay mode, zooming a figure that sources a selection left its heatmap-like traces (hist2d, box, ...) with stale data. The owner partition now computes a background for every trace.
  • Panel reset, global reset and double-click cleared a locked axis's viewport key. The figure kept showing the lock range while the server aggregated the full range: 51 of 500 points in view. Locked keys now stay (commit 2).
  • A rejected flexvizApply patch emptied all layer data, kept the bad value, and made every later gesture fail with 422. It now restores the previous state and page, and rejects with the server's reason (commit 3).
  • The axes= docstring claimed that ("x2", "y2") draws a second axis. It does not.

Limits

  • After a double-click autorange, each member autoranges on its own data.
  • Log axes cannot be linked until Zooming a log axis aggregates with log10 values as data bounds #74 is fixed. Zooming a log axis already aggregates the wrong range on main.
  • ECharts (deprecated) is untouched. Its zoom sends no viewport_keys, so it no longer re-aggregates, and it does not support links.

Follow-ups: #74 (log axes), #75 (stale responses), #76 (_programmaticOp).

Tests

  • Engine: two changed figures, one owning a selection; the overlay owner gets a bg delta for every trace (this fails on main); a selection event that changes a source figure's key; an absent key or a None value means full range; two owner partitions share one unfiltered probe.
  • Spec: key format, unknown figures, and every link rule. Server: /view answers 400 and /dashboard/update answers 422 for a bad link. CLI: history keeps and checks links.
  • Builder (tests/test_dashboard_links.py): each form, merging, late resolution, every error, and the save, load and share round trip.
  • Browser: a linked zoom sends one POST and re-aggregates every member; a display-only y link posts nothing; autorange; panel reset keeps other state; a lock pins the group; the overlay owner; share-URL restore; flexvizApply refuses a patch that breaks a link. Also resets and double-click on a locked axis, and flexvizApply rollback for a 422 and for a failed second request. These fail without the fixes.
  • make test: 2229 passed. make test-browser: 280 passed. mkdocs build --strict is clean. A real mouse drag and double-click on a three-figure linked dashboard sent one POST each and moved all figures.

Review follow-ups

  • Type rule on the server. The numeric-vs-temporal rule needs the source schema, so it now runs in the builder and in /dashboard/update (422) through one function, check_axis_link_types. A hand-built numeric-to-Date link had returned 200 with empty data.
  • Time and Duration. Only numeric, Date and Datetime axes link. Time and Duration render as category axes, and their zoom already returns 500 on main (Zooming a Time or Duration axis returns 500 #79).
  • One axis per figure. A group may hold one axis per figure. A link of a figure's own x and y left its display out of sync.
  • /share validates the spec before it issues a URL (400 instead of a URL that /view rejects).
  • Overlay. The unfiltered backgrounds of all partitions run in one aggregate pass. Interleaved A/B on a resident 20M-row source with two owners, under load: hist 75–80 → 59 ms, hist2d 65–79 → 55–58 ms, line 52–62 → 49–51 ms.
  • Trailing whitespace in the browser test scripts is stripped.

make test: 2236 passed. make test-browser: 280 passed. mkdocs build --strict and git diff --check main are clean.

Second review follow-ups

  • Link rules: only axis types whose range is in data units (unset, -, linear, date) link, so category and multicategory are rejected along with log. Every reversed form counts: reversed, min reversed, max reversed, or a descending fixed range. A non-dict axis layout no longer gives a 500. Axes in different time zones do not link: the range is copied as wall-clock text, so one window would be two instants.
  • Engine: a partition shows a foreground only when it has filters, so a selection without predicates keeps filtered_only backgrounds. TraceInfo.figure_uid is required, and each partition builds its own specs.
  • Client: a viewport-only panel reset posts only when a cleared axis re-aggregates a trace. flexvizApply says when the rollback also fails, and a stale error is no longer reported. The shadowed toolbar reset handlers and a duplicate helper are removed.
  • Builder errors name figures (figure 2 (hist)) instead of UUIDs, with no pydantic dump. A target of the wrong type raises TypeError. An unknown on= column says so.
  • The overlay merge is recorded in tests/test_perf_choices.py, a linked browser test uses a real drag, and stale comments are fixed.
  • Not changed: extra="forbid" on InteractionEvent (it would make every ECharts request fail with 422, not only zoom); the history of d202fd6.
  • Filed: Update mode: a figure with its own selection does not follow other selections live (trade-off) #80 (an owner figure keeps stale data when another brush changes; this is on main), Axis handling gaps found while reviewing linked axes #81 (axis-handling gaps from main). Commented on postDashboardUpdate applies responses in arrival order #75.

make test: 2250 passed. make test-browser: 283 passed. Lint, format, git diff --check main and mkdocs build --strict are clean.

@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing feat/linked-axes (a071d05) with main (04404c3)

Open in CodSpeed

@jvdd
jvdd requested a balanced review from Copilot September 23, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Two moderate validation issues remain unresolved in flexviz/server.py and flexviz/spec.py.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 1 Low severity

Open (3)

Comment thread flexviz/server.py Resolved
Comment thread flexviz/spec.py Resolved
Comment thread Architecture.md Resolved
@jvdd
jvdd merged commit bf401c8 into main Sep 24, 2026
18 checks passed
@jvdd
jvdd deleted the feat/linked-axes branch September 24, 2026 08:39
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.

2 participants