diff --git a/projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts b/projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts index cd36378c6..979d0d05e 100644 --- a/projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts +++ b/projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts @@ -36,6 +36,7 @@ import { CartesianIntervalData } from '../legend/cartesian-interval-control.comp import { CartesianLegend } from '../legend/cartesian-legend'; import { ScaleBounds } from '../scale/cartesian-scale'; import { CartesianScaleBuilder } from '../scale/cartesian-scale-builder'; +import { debounceTime, tap } from 'rxjs/operators'; export class DefaultCartesianChart implements CartesianChart { public static DATA_SERIES_CLASS: string = 'data-series'; @@ -608,16 +609,23 @@ export class DefaultCartesianChart implements CartesianChart { } private onMouseLeave(): void { - if (this.tooltip) { - this.tooltip.hide(); - } - - this.eventListeners.forEach(listener => { - if (listener.event === ChartEvent.MouseLeave) { - listener.onEvent(); - } - }); - - this.hideCrosshair(); + this.tooltip?.hovered$ + .pipe( + debounceTime(300), + tap(onHoverTooltip => { + if (!onHoverTooltip) { + this.tooltip?.hide(); + + this.eventListeners.forEach(listener => { + if (listener.event === ChartEvent.MouseLeave) { + listener.onEvent(); + } + }); + + this.hideCrosshair(); + } + }) + ) + .subscribe(); } } diff --git a/projects/observability/src/shared/components/utils/chart-tooltip/chart-tooltip-popover.ts b/projects/observability/src/shared/components/utils/chart-tooltip/chart-tooltip-popover.ts index 3b7e02ac7..5b123d392 100644 --- a/projects/observability/src/shared/components/utils/chart-tooltip/chart-tooltip-popover.ts +++ b/projects/observability/src/shared/components/utils/chart-tooltip/chart-tooltip-popover.ts @@ -1,14 +1,17 @@ import { PopoverPositionType, PopoverRef } from '@hypertrace/components'; -import { Observer } from 'rxjs'; +import { Observable, Observer } from 'rxjs'; import { MouseLocationData } from '../mouse-tracking/mouse-tracking'; export class ChartTooltipPopover implements ChartTooltipRef { private boundElement?: Element; + public readonly hovered$: Observable; public constructor( private readonly popoverRef: PopoverRef, private readonly dataObserver: Observer[]> - ) {} + ) { + this.hovered$ = popoverRef.hovered$; + } public showWithData(element: Element, data: MouseLocationData[]): void { this.updatePositionStrategyIfNeeded(element); @@ -30,8 +33,8 @@ export class ChartTooltipPopover implements ChartTooltipRef { showWithData(relativeTo: Element, data: MouseLocationData[]): void; hide(): void; destroy(): void; + hovered$: Observable; }