Add synced tooltips across chart and subplots#256
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds following functionality to price-chart GUIs:
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 intoBasePriceandBaseSubplot) giving each pane a lightweight "value at bar" tooltip (abq.Label). Hosts customise via_synced_tooltip_y_values,_synced_tooltip_fields,_synced_tooltip_anchor,_synced_tooltip_prefixand_format_synced_tooltip_value;_event_xmaps a hover event to its bar.guis.BasePricecoordinates 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-scaledomain) or clicking a chart's background (handled viamark.on_background_click).guis.GuiOHLCCaseBaseadditionally 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).OHLCoverrides 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.2.
charts.SubplotLineColoredBase 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. Abq.Linesmark 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 abq.ColorScalefixed 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