feat(chart): dim non-hovered series rows in tooltip#447
feat(chart): dim non-hovered series rows in tooltip#447lkipke wants to merge 8 commits intocloudflare:mainfrom
Conversation
commit: |
Docs PreviewCommit: |
mattrothenberg
left a comment
There was a problem hiding this comment.
Oops, didn't mean to approve. Still reviewing
|
/bonk My other AI Agent wants to know: Why drive tooltip-row dimming from element-level mouseover/mouseout and a seriesName ref, when axis-trigger tooltips aren't element-activated. Does this silently no-op on line charts with |
|
@mattrothenberg Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
|
/bonk pls review |
There was a problem hiding this comment.
Summary
This PR adds tooltip row dimming when hovering chart series. The visual goal is good, but the implementation has a critical synchronization issue that will cause the dimming to not work reliably or at all.
Critical Issues
1. Stale Closure in Tooltip Formatter (Primary Issue)
The dangerousHtmlFormatter is created inside useMemo and captures hoveredSeriesRef.current in its closure. When mouseover/mouseout update the ref, the formatter function does not get re-created because refs don't trigger re-renders and the useMemo dependencies don't include the hovered state.
Result: The formatter always sees the initial null value, so dimming never actually works.
2. Event Mismatch with Axis-Triggered Tooltips
The tooltip uses trigger: 'axis', meaning tooltips appear on axis hover, not element hover. However, mouseover/mouseout events fire when hovering specific graphical elements.
Problems:
- Line charts with
showSymbol: false: No symbols to hover, so mouseover events may not fire for the tooltip to dim rows - Bar charts: Rapidly moving between adjacent bars of the same series can cause flicker (mouseout clears, then mouseover sets)
- The tooltip renders before/without element mouseover, leaving rows undimmed during axis hover
3. Incomplete Incomplete-Series Config
The incomplete-series config adds triggerLineEvent: true but this doesn't work for bar series (bar charts don't have lines). The hover tracking won't work consistently across chart types.
Suggested Approach
Consider using updateAxisPointer event instead, which fires consistently for axis-triggered tooltips. Match the axis pointer's series index to dim the correct tooltip row:
handlers.updateAxisPointer = (params: any) => {
// params.dataIndex gives the hovered data index
// Compare with series data to determine which series is 'active'
hoveredSeriesRef.current = findSeriesAtDataIndex(params.dataIndex);
};Or use React state with a throttled update to ensure the formatter re-renders when hover changes.
Questions
- Have you verified this works on line charts with
showSymbol: false? - Does the dimming update when hovering between bars of different series?
- Would the
emphasis.focus: 'series'state from ECharts be more reliable than tracking mouse events?
|
I've submitted a comprehensive review of PR #447. Here's a summary of the key findings: Key Issues Identified1. Stale Closure Bug (Critical)The 2. Event Mismatch with Axis-Triggered TooltipsThe tooltip uses
3.
|
8882aa0 to
ed7246e
Compare
The feedback suggested using updateAxisPointer with params.seriesIndex to identify the hovered series. The problem is that seriesIndex on updateAxisPointer doesn't work the way the reviewer assumed:
The seriesIndex field on updateAxisPointer is really only meaningful when axisPointer.type is "cross" (crosshair mode), where ECharts actively tracks which series the crosshair is snapped to. With "shadow" or "line" axis pointer types, the pointer just highlights a time column — it doesn't distinguish between series vertically. So the suggestion was directionally correct (use an axis-level event instead of element-level mouseover), but the specific mechanism (params.seriesIndex) doesn't provide the data needed for line charts. For bar charts, the original mouseover/mouseout approach was always the right call since each stacked segment is a distinct hoverable element. |
|
Note on line chart hover hit area: The hover target for line charts is the existing 2px line stroke — this is an ECharts limitation where (There is a related, but not quite the same, upstream issue for ECharts: apache/echarts#21280) |
When hovering a series on a bar or line chart, the tooltip now dims rows for other series to 50% opacity, matching the emphasis dimming that ECharts already applies to the chart elements themselves.
Address review feedback: - Replace mouseover/mouseout with updateAxisPointer + globalout for reliable hover tracking with axis-triggered tooltips - Move tooltip value formatter to a ref to avoid stale closure in the useMemo'd dangerousHtmlFormatter - Dispatch highlight/downplay actions to keep chart emphasis in sync - Add updateAxisPointer event type to ChartEvents interface
Bar charts have distinct hoverable segments so mouseover/mouseout work reliably. Line charts with showSymbol:false lack hover targets, so updateAxisPointer (which provides the nearest seriesIndex) is used instead. Both share globalout to clear state when leaving the chart.
Remove line chart hover tracking (ZRender mousemove, updateAxisPointer) since line series with showSymbol: false lack reliable hover targets, causing the tooltip dimming to be out of sync with the chart emphasis. Bar chart dimming via mouseover/mouseout works reliably since each stacked segment is a distinct hoverable element.
Expose ECharts' extraCssText and enterable tooltip options as TimeseriesChart props. When tooltipEnterable is true, the tooltip is positioned close to the cursor so users can mouse into it to scroll or interact with the content. Includes a docs demo with 8 series and a scrollable tooltip.
This event type was added during development but is no longer used — bar chart tooltip dimming uses mouseover/mouseout instead.
Tooltip row dimming now works for all chart types via mouseover/mouseout. When ECharts triggers emphasis on a series element, the tooltip dims non-hovered rows to match. The hit area for line charts is unchanged (tied to the 2px line stroke) — improving that is a separate concern.
def1616 to
0b73923
Compare
When hovering a series on a bar or line chart, the tooltip now dims rows for other series to 50% opacity, matching the emphasis dimming that ECharts already applies to the chart elements themselves.