Skip to content

Add synced tooltips across chart and subplots#256

Merged
maread99 merged 10 commits into
mainfrom
claude/synced-tooltips-no-dep
Jun 26, 2026
Merged

Add synced tooltips across chart and subplots#256
maread99 merged 10 commits into
mainfrom
claude/synced-tooltips-no-dep

Conversation

@maread99

@maread99 maread99 commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

Adds following functionality to price-chart GUIs:

  • synchronised tooltips across price chart and subplot
  • value-coloured line subplot

1. Synchronised tooltips across the price chart and its subplots

When the price chart or any subplot is hovered, every other pane shows its own value for the hovered bar (the hovered pane continues to show just its native tooltip).

  • charts.SyncedTooltip — a mixin (mixed into BasePrice and BaseSubplot) giving each pane a lightweight "value at bar" tooltip (a bq.Label). Hosts customise via _synced_tooltip_y_values, _synced_tooltip_fields, _synced_tooltip_anchor, _synced_tooltip_prefix and _format_synced_tooltip_value; _event_x maps a hover event to its bar.
  • guis.BasePrice coordinates the panes (_init_synced_tooltips): it wires each pane's mark hover to show the other panes' tooltips. The synced tooltips are cleared on the next interaction, for example hovering another bar (re-shown for that bar), panning/zooming (observed via the shared x-scale domain) or clicking a chart's background (handled via mark.on_background_click).
  • guis.GuiOHLCCaseBase additionally wires the case scatter marks, so hovering a case (e.g. a position's entry/exit point) shows the subplots' tooltips for that bar.
  • Base._tooltip_color(x) — the single default tooltip text colour, used by both the native and synced tooltips (so they match). OHLC overrides it for the bar's up/down colour; where a native tooltip is multi-coloured (stacked bars) it falls back to white and colours itself directly.
  • Per pane:
    • OHLC tooltip shows open/high/low/close (synced label anchored at the bar's high)
    • multi-symbol (Compare) chart the stacked total
    • coloured-line tooltip shows its value.

2. charts.SubplotLineColored

Base class for a line subplot coloured by value: the line graduates from the first to the last colour of COLOR_SCALE (default blue→red) as the value rises from its lowest to its highest over all the data. A bq.Lines mark colours each line as a whole, so the line is split into one bqplot line per pair of adjacent bars, each coloured (mean of its end values) via a bq.ColorScale fixed to the full value range — so a given value always maps to the same colour. The color axis (colorbar) is suppressed.

🤖 Generated with Claude Code, manually revised and fully reviewed

claude and others added 10 commits June 22, 2026 13:54
Add tooltips synchronised across a price chart and its subplots: when any
pane is hovered, every other pane shows its own value for the hovered bar,
and all are hidden when the cursor leaves the hovered pane.

- `charts.SyncedTooltip` mixin: a per-pane `bq.Label` "value at bar"
  tooltip, shown/hidden via `show_synced_tooltip`/`hide_synced_tooltip`.
  Mixed into `BasePrice` (price charts) and `BaseSubplot` (subplots).
- `guis.BasePrice` coordinates the panes: it wires each pane's mark hover
  to show the others' tooltips, and uses `ipyevents` mouseleave on each
  figure to hide them (bqplot emits no un-hover event). `GuiOHLCCaseBase`
  also wires the case scatter marks, so hovering a case (e.g. a position
  entry/exit) shows the subplots' tooltips for that bar.
- `charts.SubplotLineColored`: base for a line subplot coloured by value
  (segments coloured via a `bq.ColorScale` fixed to the full value range;
  colour axis suppressed). Generalised from downstream use.

Adds `ipyevents` dependency.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xReNp6C4sSNy6Nc7K1hzM
Skip the value-coloured line's native tooltip where the hovered bar has
no value (nan). Add a unit test for `GuiOHLCCaseBase._scatter_event_x`,
which maps a case scatter's hover to the corresponding bar.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xReNp6C4sSNy6Nc7K1hzM
Alternative to the ipyevents-based implementation: drop the ipyevents
dependency and, since bqplot emits no un-hover event, clear the
synchronised tooltips on the next interaction rather than the instant the
cursor leaves a pane. They persist until the user hovers another bar
(re-shown for that bar), pans/zooms (a change to the shared x-domain) or
clicks a chart's background.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xReNp6C4sSNy6Nc7K1hzM
The synced Label now shows, on a single line, the same fields the pane's
native tooltip would show save for the bar itself. The fields are sourced
from a shared `_synced_tooltip_fields` hook (defaulting to the single
value, overridden by OHLC to give open/high/low/close), which the native
tooltips also use so the two stay consistent. OHLC anchors its label at
the bar's high.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xReNp6C4sSNy6Nc7K1hzM
- Add `Base._tooltip_color(x)`: the single default tooltip text colour,
  used by both the native and synced tooltips (OHLC overrides for up/down;
  multi-coloured natives fall back to white). Remove `SYNCED_TOOLTIP_COLOR`;
  the synced label now takes the native tooltip's colour.
- Rename `_synced_tooltip_series` -> `_synced_tooltip_y_values`.
- `SubplotBars._synced_tooltip_y_values`: enable a synced tooltip for
  multi-symbol (stacked) bars showing the total of the parts.
- Keep the mixin's TYPE_CHECKING host-attribute block (a runtime check
  couldn't silence the checker across the other methods); documented why.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xReNp6C4sSNy6Nc7K1hzM
Extract the 1-D line -> coloured-segments transform into a named
`_segment_mark` method. `_create_mark` now segments the mark on creation
(operating on the mark being built, before `self.mark` is assigned), so
the line is coloured from its first paint rather than relying on the
init-time x-domain handler fire. `_set_mark_to_plotted` delegates to
`_segment_mark` for windowed updates, giving a single source of truth.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015xReNp6C4sSNy6Nc7K1hzM
@maread99 maread99 added the enhancement New feature or request label Jun 26, 2026
@maread99 maread99 changed the title Synced tooltips without ipyevents (alternative to #255) Add synced tooltips across chart and subplots Jun 26, 2026
@maread99 maread99 merged commit 2779bb3 into main Jun 26, 2026
8 checks passed
@maread99 maread99 deleted the claude/synced-tooltips-no-dep branch June 26, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants