From b39be0a1deebafbf6f92485ea662f798d23ad6a8 Mon Sep 17 00:00:00 2001 From: MiniPear Date: Mon, 25 Sep 2023 11:27:07 +0800 Subject: [PATCH] fix(tooltip): for fisheye (#5590) --- src/interaction/fisheye.ts | 4 +++- src/interaction/tooltip.ts | 14 ++++++++++++-- src/runtime/plot.ts | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/interaction/fisheye.ts b/src/interaction/fisheye.ts index 38f4204673..d6cb3ff86b 100644 --- a/src/interaction/fisheye.ts +++ b/src/interaction/fisheye.ts @@ -36,7 +36,9 @@ export function Fisheye({ setState('fisheye', (options) => { // Clone options and mutate it. // Disable animation. - const clonedOptions = deepMix({}, options); + const clonedOptions = deepMix({}, options, { + interaction: { tooltip: { preserve: true } }, + }); for (const mark of clonedOptions.marks) mark.animate = false; const [x, y] = focus; const fisheye = maybeCoordinate(clonedOptions); diff --git a/src/interaction/tooltip.ts b/src/interaction/tooltip.ts index 0514b47690..9dc99b9836 100644 --- a/src/interaction/tooltip.ts +++ b/src/interaction/tooltip.ts @@ -442,6 +442,7 @@ export function seriesTooltip( theme, disableNative = false, marker = true, + preserve = false, style: _style = {}, css = {}, ...rest @@ -742,7 +743,11 @@ export function seriesTooltip( emitter.off('tooltip:hide', onTooltipHide); emitter.off('tooltip:disable', onTooltipDisable); emitter.off('tooltip:enable', onTooltipEnable); - destroy(); + if (preserve) { + hideTooltip({ root, single, emitter, nativeEvent: false }); + } else { + destroy(); + } }; } @@ -774,6 +779,7 @@ export function tooltip( shared = false, body = true, disableNative = false, + preserve = false, css = {}, }: Record, ) { @@ -899,7 +905,11 @@ export function tooltip( removeEventListeners(); emitter.off('tooltip:show', onTooltipShow); emitter.off('tooltip:hide', onTooltipHide); - destroyTooltip({ root, single }); + if (preserve) { + hideTooltip({ root, single, emitter, nativeEvent: false }); + } else { + destroyTooltip({ root, single }); + } }; } diff --git a/src/runtime/plot.ts b/src/runtime/plot.ts index f9c83100f4..20dcae4558 100644 --- a/src/runtime/plot.ts +++ b/src/runtime/plot.ts @@ -424,7 +424,8 @@ function updateTooltip( container: selection.node(), update: (options) => Promise.resolve(options), }; - applyTooltip(target, [], context.emitter); + const newTooltip = applyTooltip(target, [], context.emitter); + nameInteraction.set('tooltip', newTooltip); } async function initializeView(