Repository navigation
Conversation
|
I ran my review agent on the PR, here are its findings that I deem relevant:
|
There was a problem hiding this comment.
🟡 Changes recommended
Incomplete hover cancellation and timer cleanup allow delayed tooltips and highlights to appear after Escape, legend interactions, or delay changes, while canceled or hidden targets can leave stale cursor previews.
6 open issues
Restore the cursor preview when a pending hover is cancelled · New Clear cursor previews for targets that become invisible · New Legend focus should cancel pending chart-point hover · New Visibility actions should cancel both hover schedulers · New Escape should cancel pending hover even before the tooltip appears · New Cancel the previous hover timer when replacing its debounce · New
What changed in this PR
Adds internal hover debouncing to the core chart to coordinate highlights, legend scrolling, and tooltips in dense charts while keeping cursor previews immediate.
Changes:
- Introduces a shared scheduler implementation for delayed point, group, and legend hover effects.
- Adds cancellation, click-to-pin handling, and visibility checks for pending targets.
- Adds unit tests, browser tests, and a configurable dense-chart demo.
| File | Description |
|---|---|
test/functional/hover-debounce.test.ts |
Adds browser coverage for delayed and immediate hover behavior. |
src/internal/components/chart-legend/index.tsx |
Configures tooltip and scroll timing and distinguishes pointer hover. |
src/core/internal-interfaces.ts |
Defines the internal hoverDebounce prop. |
src/core/components/core-legend.tsx |
Routes legend pointer highlights through the scheduler. |
src/core/chart-core.tsx |
Wires hover delay into chart settings, legends, and tooltips. |
src/core/chart-api/index.tsx |
Coordinates legend scheduling, cursor previews, and cancellation. |
src/core/chart-api/hover-scheduler.ts |
Adds reusable target-aware hover scheduling. |
src/core/chart-api/chart-extra-tooltip.tsx |
Separates cursor previews from tooltip anchor updates. |
src/core/chart-api/chart-extra-pointer.tsx |
Schedules pointer targets and flushes pending hover on click. |
src/core/chart-api/chart-extra-context.tsx |
Adds the hover-delay setting and default. |
src/core/__tests__/common.tsx |
Extends test helpers to accept internal hover props. |
src/core/__tests__/chart-core-hover-debounce.test.tsx |
Covers timing, previews, cancellation, and visibility checks. |
pages/03-core/hover-debounce.page.tsx |
Adds a dense-chart demo with adjustable delay. |
Review effort: Balanced
d12e9a7 to
9c26861
Compare
|
Thanks for the review. All points are addressed in 9c26861:
|
There was a problem hiding this comment.
🟡 Changes recommended
Inconsistent cancellation of delayed hover work causes stale tooltips and highlights after pointer exit or Escape/API actions, and suppresses valid legend highlights during plot-to-legend transitions.
4 open issues
6 resolved since last review
Cancel the previous hover timer when replacing its debounce Escape should cancel pending hover even before the tooltip appears Visibility actions should cancel both hover schedulers Legend focus should cancel pending chart-point hover Clear cursor previews for targets that become invisible Restore the cursor preview when a pending hover is cancelled
Review effort: Balanced
| } | ||
| }; | ||
|
|
||
| private applyHover = (target: PointerHoverTarget) => { |
| if (this.chartExtraPointer.cancelPendingHover()) { | ||
| this.chartExtraTooltip.restoreCursor(); | ||
| } | ||
| this.legendItemHover.cancel(); |
9c26861 to
665cac7
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved hover scheduling and state issues can show stale tooltips, highlight items after legend teardown, cancel newer cross-legend hovers, and reset cursor previews on redraw.
6 open issues
Preserve preview cursor target across chart redraws · New Scope delayed highlight cleanup to its originating legend · New Cancel pending legend tooltip when highlighting another item · New Cancel pending legend highlight when unmounting the legend · New Escape leaves the pending legend tooltip timer active Pending point hover commits after pointer leaves
2 resolved since last review
Review effort: Balanced
| public showCursor(point: null | Highcharts.Point, group: readonly Highcharts.Point[]) { | ||
| if (!this.tooltipLock && this.chartType === "cartesian") { | ||
| this.createCursor(point, group); | ||
| } |
| }; | ||
| public onLeaveLegendItem = () => this.legendItemHover.cancel(); | ||
| public onClearChartItemsHighlight = () => { | ||
| this.legendItemHover.cancel(); |
| if (!keepLegendHover) { | ||
| this.legendItemHover.cancel(); | ||
| } |
| }, | ||
| }; | ||
| }, []); | ||
| useEffect(() => cancelTooltip, [cancelTooltip]); |
| labels: ChartLabels; | ||
| getItemOptions?: CoreChartProps.GetItemOptions; | ||
| zoomEnabled: boolean; | ||
| hoverDelay: number; |
There was a problem hiding this comment.
Is it deliberate that the behaviour only applies for pointer hover but not for keyboard highlight?
There was a problem hiding this comment.
Yes, deliberate. The delay filters the in-between targets a pointer passes over while sweeping a dense chart. A keyboard step goes straight to one intended target, so it is not really an issue there. Do you think we should try to debounce keyboard navigation as well?
There was a problem hiding this comment.
Now that keyboard interactions are included - I believe we need to come up with a better var name, as "hover" implies pointer interactions.
I am thinking of some abstract one like debounce or effectsDebounce. One advantage here is that we can type it as number now, but later expand if we need more fine-grained configuration, like debounce: { hover: 300, keyboard: 200 } etc.
What do you think?
|
|
||
| import { DebouncedCall } from "../../internal/utils/utils"; | ||
|
|
||
| export class HoverScheduler<Target> { |
There was a problem hiding this comment.
nit: The class looks very abstract as Target is generic - it has no logic coupled to the hover or chart etc. I recommend calling it differently, maybe DebounceScheduler etc. - or see if it can be merged with DebouncedCall.
There was a problem hiding this comment.
Merging it with DebouncedCall.
| @@ -0,0 +1,86 @@ | |||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | |||
There was a problem hiding this comment.
This page does not feature anything new but the hover. I recommend to instead add it as settings to existing core chart test pages, where it makes sense. This will allow to see how it works in practice on the variety of different chart types and settings combinations - including core-specific chart types like heapmap or gauge.
There was a problem hiding this comment.
Makes sense, I will add it to the existing pages.
5066937 to
19b5ab6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #283 +/- ##
==========================================
- Coverage 93.81% 92.43% -1.38%
==========================================
Files 64 64
Lines 3445 2923 -522
Branches 1092 894 -198
==========================================
- Hits 3232 2702 -530
+ Misses 213 181 -32
- Partials 0 40 +40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Inconsistent hover cancellation and debounce timing can cause stale tooltip and legend updates, cursor–tooltip mismatches when pinning, and highlights after focus leaves.
10 open issues
Tooltip entry fails to cancel pending keyboard hovers · New Pinning a focused item leaves another hover's cursor preview · New Repeated legend entry restarts the pending tooltip delay · New Blur allows pending legend highlights to fire · New Cancel pending legend highlight when unmounting the legend Cancel pending legend tooltip when highlighting another item Scope delayed highlight cleanup to its originating legend Preserve preview cursor target across chart redraws Escape leaves the pending legend tooltip timer active Pending point hover commits after pointer leaves
Review effort: Balanced
| if (this.hover.cancelPrevious()) { | ||
| this.handlers.onHoverPreviewCancel(); | ||
| } |
| } | ||
|
|
||
| private applyActivatedTarget(target: PointerHoverTarget) { | ||
| this.focusHighlight.cancelPrevious(); |
| return { | ||
| showTooltip(itemId: string) { | ||
| control.call(() => setTooltipItemId(itemId), TOOLTIP_SHOW_DELAY); | ||
| control.call(() => setTooltipItemId(itemId), tooltipShowDelayRef.current); |
| showTooltip(item.id); | ||
| }, | ||
| onMouseLeave: () => { | ||
| onItemHoverLeave?.(); |
| this.tooltipHovered = true; | ||
| this.hoveredPoint = null; | ||
| this.hoveredGroup = null; | ||
| if (this.hover.cancelPrevious()) { |
There was a problem hiding this comment.
Nice thinking! I love that we cancel next hover when the cursor goes inside the tooltip 👍
| pending?.callback(); | ||
| }; | ||
|
|
||
| public cancelPrevious(): boolean { |
There was a problem hiding this comment.
Should we rename this to cancelPending for better clearity?
There was a problem hiding this comment.
Sounds good, renaming!
| if (tooltipState.visible && !tooltipState.pinned) { | ||
| api.hideTooltip(); | ||
| if (event.keyCode === KeyCode.escape) { | ||
| api.cancelPendingHovers(); |
There was a problem hiding this comment.
Why do we need this change? I removed that locally and noticed no effect on the UX.
There was a problem hiding this comment.
I can see the difference on a long debounce, if you hover on a datapoint and press Esc before the debounce settles, it will still show the tooltip while. With this change it cancels it so the tooltip is not shown if the debounce was interrupted with an Esc.
7369812 to
b9c0950
Compare
In dense charts, series highlight, legend highlight, legend scroll-into-view and the tooltip all react to every pointer move, which causes a lot of motion. The existing tooltip.debounce only delays the tooltip. This adds an internal hoverDebounce prop to core chart (a number in ms, or true for 150ms). The hovered series and its legend item highlight as soon as the pointer reaches them, and onHighlight and onLegendItemHighlight fire at once. Dimming the other series and legend items waits for the delay when nothing is dimmed yet; once they are dimmed, moving to another target swaps the highlight at once. Column series dim at once, as their hover state alone is hard to see. The tooltip, including the legend item tooltip, waits for the delay, and the legend scrolls the highlighted item into view only after the pointer has rested for the delay. Undimming has no fade. highlightItems, highlightChartPoint and highlightChartGroup from the public API follow the same model, so a chart that syncs highlights through onHighlight lights the same series at once and dims after the delay. Keyboard navigation and legend item focus are not delayed. A pending hover is dropped when the pointer leaves its target or enters the tooltip, on Escape, chart focus, visibility changes, zoom start and destroy, and is replaced by a newer pointer, legend or API hover. The previewed highlight is then restored, and onHighlight or onClearHighlight reports the result. A click applies the pending hover first, so pinning doesn't wait, and a pending point or group is checked for visibility again when the delay ends. DebouncedCall can now take a key: scheduling the key that is already pending keeps it, flush() runs the pending call, and cancelPending() (renamed from cancelPrevious()) reports whether something was pending. tooltip.debounce is ignored while hoverDebounce is set, and is planned for removal. The core dev pages get a "Hover debounce (ms)" setting. Without hoverDebounce, the behavior is unchanged.
b9c0950 to
004d36d
Compare

Description
In dense charts, series highlight, legend highlight, legend scroll-into-view and the tooltip all react to every pointer move, which causes a lot of motion. The existing
tooltip.debounceonly delays the tooltip.This adds an internal
hoverDebounceprop to core chart (a number in ms, ortruefor 150ms):onHighlight/onLegendItemHighlightfire (once per target), so charts synced through these events follow straight away.tooltip.debounceis ignored whilehoverDebounceis set, so the delays don't stack, and it's marked for removal.Details:
highlightItems,highlightChartPointandhighlightChartGroupfollow the same model: the target lights up at once, and dimming and the tooltip follow after the delay. This lets a synced chart light the series together with the hovered chart and dim after the same delay. Without it, synced charts would dim at once while the hovered chart waits.DebouncedCall(src/internal/utils/utils.ts) can now take a key: scheduling the key that is already pending keeps it instead of restarting the delay,flush()runs the pending call at once, andcancelPending()(renamed fromcancelPrevious()) reports whether something was pending. Callers that don't pass a key behave as before.highlightActions,clearHighlightActions,highlightChartItemsand the legend's clear-highlight cancel pending hovers at the top. Pointer, legend and API hovers replace each other's pending highlight through one scheduling method. A pending highlight is also dropped when the pointer leaves its target or enters the tooltip, on Escape, chart focus, visibility changes, zoom start and destroy. The previewed highlight is then restored, andonHighlightoronClearHighlightreports the result. A pending point or group is checked for visibility again when the delay ends.getScrollIntoViewDelaycallback, and doesn't know about the core's debounce.Without
hoverDebounce, behavior is unchanged. Like the zoom props, the prop lives ininternal-interfaces.tsand isn't part of the public API, so the documenter snapshot doesn't change.Related links, issue #, if available: n/a
How has this been tested?
src/core/__tests__/chart-core-hover-debounce.test.tsx, covering the instant highlight with the delayed dimming and tooltip, the immediate swap once dimmed, column and pie points, the 150ms default withtooltip.debounceignored, a zero delay, moving into the tooltip, click to pin, the visibility re-check, the cancellation cases (pointer leave, Escape, chart focus, visibility change, zoom start), API highlights, and legend hover, leave, toggle, Escape and focus. 6 more insrc/internal/utils/__tests__/utils.test.tsforDebouncedCall. Full unit suite: 617 passing.test/functional/hover-debounce.test.ts, using real WebDriver mouse input against the core line chart page with a 1000ms delay. They check that the cursor shows at once while the tooltip waits, that the tooltip stays on the previous point until the pointer rests, that dimming waits when hovering a legend item, and the no-delay baseline. All functional tests pass withnpm run test:functional.hoverDebounceURL parameter, for example#/03-core/core-line-chart?hoverDebounce=150. The default is 0, which shows the current behavior.Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md.CONTRIBUTING.md.Security
checkSafeUrlfunction.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Screen.Recording.2026-11-18.at.17.02.59.mov