Skip to content

Isolate a series on legend double-click (Plotly-style) - #506

Open
Alek99 wants to merge 2 commits into
mainfrom
alek/legend-dblclick-isolate
Open

Isolate a series on legend double-click (Plotly-style)#506
Alek99 wants to merge 2 commits into
mainfrom
alek/legend-dblclick-isolate

Conversation

@Alek99

@Alek99 Alek99 commented Sep 2, 2026

Copy link
Copy Markdown
Member

Closes #505.

What

Double-clicking a legend row shows only that series/category; double-clicking the row that is already alone restores every entry (Plotly's legenddoubleclick model). Single click keeps toggling one entry exactly as before. New xy.legend(isolate=False) opts out — same default-on, opt-out-only wire rule as toggle/highlight, and independent of toggle (with toggle=False, single clicks are inert while double-click still isolates).

before after double-click on "Beta"
all four series only Beta draws, the other rows fade

How

  • No disambiguation delay. Single clicks commit immediately (Plotly waits 300 ms). So when dblclick fires, the burst's first click has already toggled the row; the client ignores the second click (event.detail >= 2) and decides isolate-vs-restore against the pre-gesture state. End state equals a fresh isolate; the transient first-click frame is the recorded cost (spec §10).
  • One path for every row. _legendToggle is factored into _legendSetOff (row chrome, view-held off-sets, GPU flag, kernel message) + _legendApplyBatch (category re-filter once per affected trace, badges, pick). Isolate walks all linked rows across every legend box in legend order; each changed row ships its own legend_toggle and xy:legendtoggle; one xy:legendisolate {name, isolated, traces, category?} names the gesture (not fired when nothing changed).
  • The second press is preventDefaulted on mousedown so the label text is not selected; single presses keep native focus/selection rules.

Spec / docs

  • spec/api/interaction.md §10: the gesture and its limits. §3 event table now lists xy:legendtoggle — it was dispatched but missing from the "those nine are the whole surface" list — plus xy:legendisolate.
  • spec/design/wire-protocol.md: isolate is not a message of its own.
  • docs/components/legends.md: new "Toggle and Isolate Series" section with a demo.

Tests

  • test_legend_isolate_option: wire opt-out, independence from toggle, public Legend positional order still binds.
  • Browser probes drive a real burst (click detail 1, click detail 2, dblclick) against the built client: default path (isolate, restore, isolate from a partly-hidden chart), isolate=False (byte-identical pre-existing toggle behavior on the wire), toggle=False. They assert vertex-buffer row counts, row data-xy-legend-off state, the exact legend_toggle message sequence, and the xy:legendtoggle/xy:legendisolate events.
  • Full tests/ suite, ruff check/ruff format --check, ty check (no new diagnostics vs main), docs-site tests (119 passed) run locally.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Double-click a legend entry to isolate that series or category; double-click the sole visible entry to restore all entries.
    • Configure isolation independently from single-click visibility toggling, with isolation enabled by default.
    • Legend interactions now emit dedicated toggle and isolation events.
  • Documentation

    • Added guidance and examples covering legend hover, toggle, isolation behavior, configuration options, events, and protocol details.

Double-clicking a legend row now shows only that series or category; a
second double-click on the row that is already alone restores every entry
(Plotly's legenddoubleclick model). Single click keeps toggling exactly as
before. `xy.legend(isolate=False)` opts out, following the same default-on,
opt-out-only wire rule as `toggle` and `highlight`, and is independent of
`toggle`: with `toggle=False` single clicks stay inert while double-click
still isolates.

Single clicks commit immediately -- no Plotly-style 300 ms disambiguation
delay -- so by the time `dblclick` fires the gesture's first click has
already toggled the row. The client ignores the second click of the burst
(`event.detail >= 2`) and decides isolate-vs-restore against the
pre-gesture state, so the end state is exactly what a fresh isolate would
produce. Each changed row goes through the ordinary toggle path (one
`legend_toggle` message and one `xy:legendtoggle` per row, in legend
order); category re-filtering runs once per affected trace after the whole
batch; one new `xy:legendisolate {name, isolated, traces, category?}` event
names the gesture. The second press is preventDefault'ed on mousedown so the
label text is not selected.

Spec: interaction.md §10 documents the gesture and its recorded limits, and
the §3 event table now lists `xy:legendtoggle` (it was dispatched but
missing from the "whole surface" list) and `xy:legendisolate`;
wire-protocol.md notes isolate is not a message of its own. Docs gain a
"Toggle and Isolate Series" section. Browser probes cover the default,
`isolate=False` (byte-identical pre-existing toggle behavior) and
`toggle=False` paths, asserting buffers, row state, wire messages and events.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: ce9b79c6-fe29-4c35-bfb0-c63a8d27d8be

📥 Commits

Reviewing files that changed from the base of the PR and between 8d84ec1 and a668818.

📒 Files selected for processing (7)
  • docs/components/legends.md
  • js/src/50_chartview.ts
  • news/506.feature.md
  • python/xy/components.py
  • spec/api/interaction.md
  • spec/design/wire-protocol.md
  • tests/test_legend_toggle.py
🚧 Files skipped from review as they are similar to previous changes (5)
  • docs/components/legends.md
  • spec/design/wire-protocol.md
  • python/xy/components.py
  • tests/test_legend_toggle.py
  • js/src/50_chartview.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Adds Plotly-style legend double-click isolation and restoration. Adds an independent isolate option, batched visibility updates, xy:legendisolate events, documented legend_toggle messages, and unit and browser tests.

Changes

Legend isolation

Layer / File(s) Summary
Legend API and wire contract
python/xy/components.py, spec/api/interaction.md, spec/design/wire-protocol.md
Adds the enabled-by-default isolate legend option. Documents isolation events and per-row legend_toggle messages.
Legend gesture and batch processing
js/src/50_chartview.ts
Adds double-click isolation and restoration. Batches category and trace visibility updates. Dispatches per-row toggle events and one isolate event per gesture.
Isolation behavior validation
tests/test_legend_toggle.py
Tests option validation, browser gestures, restoration, opt-outs, event payloads, and kernel message ordering.
Legend isolation documentation
docs/components/legends.md, news/506.feature.md
Documents hover, toggle, isolation, independent options, messages, and events.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to a6688

This change adds legend double-click isolation and restoration while preserving existing single-click behavior and providing an opt-out; no actionable merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant LegendRow
  participant ChartView
  participant Kernel
  participant ChartRoot
  LegendRow->>ChartView: Double-click linked legend entry
  ChartView->>ChartView: Isolate or restore linked rows
  ChartView->>Kernel: Send legend_toggle for changed rows
  ChartView->>ChartRoot: Dispatch xy:legendtoggle events
  ChartView->>ChartRoot: Dispatch xy:legendisolate event
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: isolating a series through legend double-click behavior.
Linked Issues check ✅ Passed The pull request satisfies issue #505. It preserves single-click toggling, adds double-click isolation and restoration, supports category entries, and includes the requested tests and documentation.
Out of Scope Changes check ✅ Passed The changes remain in scope for issue #505. They implement legend isolation and update the related Python API, specifications, documentation, release notes, and tests.
Full details: Docstring Coverage

Explanation

Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. (4 skipped: 4 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alek/legend-dblclick-isolate

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Sep 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 109 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing alek/legend-dblclick-isolate (a668818) with main (8d84ec1)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 7 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread js/src/50_chartview.ts
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.

Legend: double-click a series to isolate it (Plotly-style)

1 participant