diff --git a/__tests__/integration/snapshots/tooltip/alphabet-interval-tooltip-render-update/step0.html b/__tests__/integration/snapshots/tooltip/alphabet-interval-tooltip-render-update/step0.html new file mode 100644 index 0000000000..f7ff97fafb --- /dev/null +++ b/__tests__/integration/snapshots/tooltip/alphabet-interval-tooltip-render-update/step0.html @@ -0,0 +1,10 @@ +
+
+

A

+ frequency: 0.08167 +
+
; diff --git a/__tests__/integration/snapshots/tooltip/alphabet-interval-tooltip-render-update/step1.html b/__tests__/integration/snapshots/tooltip/alphabet-interval-tooltip-render-update/step1.html new file mode 100644 index 0000000000..22cb338daf --- /dev/null +++ b/__tests__/integration/snapshots/tooltip/alphabet-interval-tooltip-render-update/step1.html @@ -0,0 +1,10 @@ +
+
+

B

+ frequency: 0.01492 +
+
; diff --git a/__tests__/plots/tooltip/alphabet-interval-tooltip-render-update.ts b/__tests__/plots/tooltip/alphabet-interval-tooltip-render-update.ts new file mode 100644 index 0000000000..16eb3320ff --- /dev/null +++ b/__tests__/plots/tooltip/alphabet-interval-tooltip-render-update.ts @@ -0,0 +1,53 @@ +import { CustomEvent } from '@antv/g'; +import { G2Spec, ELEMENT_CLASS_NAME } from '../../../src'; +import { LEGEND_ITEMS_CLASS_NAME } from '../../../src/interaction/legendFilter'; + +export function alphabetIntervalTooltipRenderUpdate(): G2Spec { + return { + type: 'interval', + paddingLeft: 60, + data: { + type: 'fetch', + value: 'data/alphabet.csv', + transform: [{ type: 'slice', start: 0, end: 3 }], + }, + encode: { + x: 'letter', + y: 'frequency', + color: 'letter', + }, + interaction: { + legendFilter: true, + tooltip: { + render: (_, { title, items }) => + `

${title}

${items.map( + (d) => `${d.name}: ${d.value}`, + )}`, + }, + }, + }; +} + +alphabetIntervalTooltipRenderUpdate.steps = ({ canvas }) => { + const { document } = canvas; + return [ + { + changeState: async () => { + const items = document.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME); + const [i0] = items; + i0.dispatchEvent(new CustomEvent('click')); + + const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME); + const [e0] = elements; + e0.dispatchEvent(new CustomEvent('pointerover')); + }, + }, + { + changeState: async () => { + const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME); + const [e0] = elements; + e0.dispatchEvent(new CustomEvent('pointerover')); + }, + }, + ]; +}; diff --git a/__tests__/plots/tooltip/index.ts b/__tests__/plots/tooltip/index.ts index 47fb59ed52..cd18085e5d 100644 --- a/__tests__/plots/tooltip/index.ts +++ b/__tests__/plots/tooltip/index.ts @@ -61,3 +61,4 @@ export { alphabetIntervalBrushTooltip } from './alphabet-interval-brush-tooltip' export { mockLineFalsy } from './mock-line-falsy'; export { provincesLineGroupName } from './provinces-line-group-name'; export { pointsPointRegressionQuad } from './points-point-regression-quad'; +export { alphabetIntervalTooltipRenderUpdate } from './alphabet-interval-tooltip-render-update'; diff --git a/src/runtime/plot.ts b/src/runtime/plot.ts index 3aa7491da4..bd3226f45f 100644 --- a/src/runtime/plot.ts +++ b/src/runtime/plot.ts @@ -324,8 +324,7 @@ function updateTooltip(selection, options, view, library, context) { // Instances for tooltip. const container = selection.node(); const nameInteraction = container['nameInteraction']; - const { interaction } = options; - const tooltipOptions = inferInteraction(interaction).find( + const tooltipOptions = inferInteraction(options).find( (d) => d.type === 'tooltip', ); diff --git a/src/transform/filter.ts b/src/transform/filter.ts index d20e889b64..d6af63d658 100644 --- a/src/transform/filter.ts +++ b/src/transform/filter.ts @@ -11,7 +11,7 @@ export type FilterOptions = Omit; */ export const Filter: TC = (options = {}) => { return (I, mark) => { - const { encode } = mark; + const { encode, data } = mark; const filters = Object.entries(options) .map(([key, value]) => { const [V] = columnOf(encode, key); @@ -43,7 +43,11 @@ export const Filter: TC = (options = {}) => { }); return [ newIndex, - deepMix({}, mark, { encode: Object.fromEntries(newEncodes) }), + deepMix({}, mark, { + encode: Object.fromEntries(newEncodes), + // Filter data for tooltip item. + data: FI.map((i) => data[i]), + }), ]; }; };