diff --git a/__tests__/integration/snapshots/tooltip/alphabet-interval-brush-tooltip/step1.html b/__tests__/integration/snapshots/tooltip/alphabet-interval-brush-tooltip/step1.html new file mode 100644 index 0000000000..ec747fa47d --- /dev/null +++ b/__tests__/integration/snapshots/tooltip/alphabet-interval-brush-tooltip/step1.html @@ -0,0 +1 @@ +null \ No newline at end of file diff --git a/__tests__/plots/tooltip/alphabet-interval-brush-tooltip.ts b/__tests__/plots/tooltip/alphabet-interval-brush-tooltip.ts new file mode 100644 index 0000000000..2a16ccca0c --- /dev/null +++ b/__tests__/plots/tooltip/alphabet-interval-brush-tooltip.ts @@ -0,0 +1,48 @@ +import { CustomEvent } from '@antv/g'; +import { G2Spec, PLOT_CLASS_NAME } from '../../../src'; +import { brush } from '../interaction/penguins-point-brush'; + +export function alphabetIntervalBrushTooltip(): G2Spec { + return { + type: 'interval', + transform: [{ type: 'sortX', by: 'y', reverse: true }], + data: { + type: 'fetch', + value: 'data/alphabet.csv', + }, + encode: { + x: 'letter', + y: 'frequency', + color: 'steelblue', + }, + state: { + active: { fill: 'red' }, + }, + interaction: { + brushHighlight: true, + }, + }; +} + +alphabetIntervalBrushTooltip.steps = ({ canvas }) => { + const { document } = canvas; + const plot = document.getElementsByClassName(PLOT_CLASS_NAME)[0]; + return [ + { + skip: true, + changeState: () => { + brush(plot, 400, 300, 600, 400); + }, + }, + { + changeState: () => { + plot.dispatchEvent( + new CustomEvent('pointerover', { + offsetX: 500, + offsetY: 360, + }), + ); + }, + }, + ]; +}; diff --git a/__tests__/plots/tooltip/index.ts b/__tests__/plots/tooltip/index.ts index 0baf98854f..4a8dd5c924 100644 --- a/__tests__/plots/tooltip/index.ts +++ b/__tests__/plots/tooltip/index.ts @@ -57,3 +57,4 @@ export { profitIntervalLegendFilterOrdinal } from './profit-interval-legend-filt export { aaplLineSliderFilter } from './appl-line-slider-filter'; export { aaplLineAreaBasicSample } from './aapl-line-area-basic-sample'; export { aaplAreaMissingDataTranspose } from './aapl-area-missing-data-transpose'; +export { alphabetIntervalBrushTooltip } from './alphabet-interval-brush-tooltip'; diff --git a/src/interaction/tooltip.ts b/src/interaction/tooltip.ts index e62299f348..be03c695a8 100644 --- a/src/interaction/tooltip.ts +++ b/src/interaction/tooltip.ts @@ -497,7 +497,10 @@ export function tooltip( const pointerover = throttle( (event) => { const { target: element } = event; - if (!elementSet.has(element)) return; + if (!elementSet.has(element)) { + hideTooltip(root, single); + return; + } const k = groupKey(element); const group = keyGroup.get(k); const data =