From b7bb946e40cb9c117eafbdb86f9912d43d94e3e9 Mon Sep 17 00:00:00 2001 From: Bairui Su Date: Wed, 3 Jul 2024 18:12:24 +0800 Subject: [PATCH] fix(legend-filter): filter facet pie (#6346) --- .../mock-pie-legend-filter/step0.svg | 1127 +++++++++++++++++ __tests__/plots/interaction/index.ts | 1 + .../interaction/mock-pie-legend-filter.ts | 96 ++ src/runtime/coordinate.ts | 7 +- 4 files changed, 1230 insertions(+), 1 deletion(-) create mode 100644 __tests__/integration/snapshots/interaction/mock-pie-legend-filter/step0.svg create mode 100644 __tests__/plots/interaction/mock-pie-legend-filter.ts diff --git a/__tests__/integration/snapshots/interaction/mock-pie-legend-filter/step0.svg b/__tests__/integration/snapshots/interaction/mock-pie-legend-filter/step0.svg new file mode 100644 index 0000000000..cf8752b891 --- /dev/null +++ b/__tests__/integration/snapshots/interaction/mock-pie-legend-filter/step0.svg @@ -0,0 +1,1127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2024-07-02 + + + + + + + + + + + + + + + + + + + + 2024-07-01 + + + + + + + + + + + + + + + + + + + + 2024-06-30 + + + + + + + + + + + + + + + + + + + + 2024-06-29 + + + + + + + + + + + + + + + + + + + + 2024-06-28 + + + + + + + + + + + + + + + + + + + + 2024-06-27 + + + + + + + + + + + + + + + + + + + + 2024-06-26 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 单价求和 + + + + + + + 单位成本求和 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/__tests__/plots/interaction/index.ts b/__tests__/plots/interaction/index.ts index cbe9e9187f..007c3cbd67 100644 --- a/__tests__/plots/interaction/index.ts +++ b/__tests__/plots/interaction/index.ts @@ -81,3 +81,4 @@ export { mockIntervalTooltipBackground } from './mock-interval-tooltip-backgroun export { indicesLineCrosshairsXY } from './indices-line-crosshairs-xy'; export { changeSizePolarCrosshairsXY } from './change-size-polar-crosshairs-xy'; export { alphabetIntervalActiveMarkerType } from './alphabet-interval-activate-line-marker-type'; +export { mockPieLegendFilter } from './mock-pie-legend-filter'; diff --git a/__tests__/plots/interaction/mock-pie-legend-filter.ts b/__tests__/plots/interaction/mock-pie-legend-filter.ts new file mode 100644 index 0000000000..4b839c7539 --- /dev/null +++ b/__tests__/plots/interaction/mock-pie-legend-filter.ts @@ -0,0 +1,96 @@ +import { G2Spec } from '../../../src'; +import { LEGEND_ITEMS_CLASS_NAME } from '../../../src/interaction/legendFilter'; +import { step } from './utils'; + +export function mockPieLegendFilter(): G2Spec { + return { + type: 'facetRect', + data: { + type: 'inline', + value: [ + { + D2022010400161505000009920363_sum: 22828922, + dd2baf8827554249bd380cd0371f85b4: '2024-07-02', + '8abf74ed1ebe45408af4676486cb8fb6': 4549244.58, + }, + { + D2022010400161505000009920363_sum: 24710705.71, + dd2baf8827554249bd380cd0371f85b4: '2024-07-01', + '8abf74ed1ebe45408af4676486cb8fb6': 5174241.6, + }, + { + D2022010400161505000009920363_sum: 27181856.29, + dd2baf8827554249bd380cd0371f85b4: '2024-06-30', + '8abf74ed1ebe45408af4676486cb8fb6': 5564121.4, + }, + { + D2022010400161505000009920363_sum: 25462071.48, + dd2baf8827554249bd380cd0371f85b4: '2024-06-29', + '8abf74ed1ebe45408af4676486cb8fb6': 5509570.71, + }, + { + D2022010400161505000009920363_sum: 27109916.98, + dd2baf8827554249bd380cd0371f85b4: '2024-06-28', + '8abf74ed1ebe45408af4676486cb8fb6': 6320245.72, + }, + { + D2022010400161505000009920363_sum: 27554918.99, + dd2baf8827554249bd380cd0371f85b4: '2024-06-27', + '8abf74ed1ebe45408af4676486cb8fb6': 6582401.59, + }, + { + D2022010400161505000009920363_sum: 28621357.6, + dd2baf8827554249bd380cd0371f85b4: '2024-06-26', + '8abf74ed1ebe45408af4676486cb8fb6': 6744951.36, + }, + ], + transform: [ + { + type: 'rename', + D2022010400161505000009920363_sum: '单价求和', + '8abf74ed1ebe45408af4676486cb8fb6': '单位成本求和', + }, + { + type: 'fold', + fields: ['单价求和', '单位成本求和'], + key: 'folded_key', + value: 'folded_value', + }, + ], + }, + encode: { + x: 'folded_key', + }, + axis: { + x: { + title: false, + }, + }, + children: [ + { + type: 'view', + coordinate: { type: 'theta' }, + frame: false, + children: [ + { + type: 'interval', + encode: { + color: 'dd2baf8827554249bd380cd0371f85b4', + y: 'folded_value', + }, + transform: [{ type: 'stackY' }], + scale: { y: { facet: false } }, + animate: false, + }, + ], + }, + ], + }; +} + +mockPieLegendFilter.steps = ({ canvas }) => { + const { document } = canvas; + const elements = document.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME); + const [e0] = elements; + return [step(e0, 'click')]; +}; diff --git a/src/runtime/coordinate.ts b/src/runtime/coordinate.ts index e85bcadacc..57cd57a659 100644 --- a/src/runtime/coordinate.ts +++ b/src/runtime/coordinate.ts @@ -46,7 +46,12 @@ export function createCoordinate( export function coordinate2Transform(node: G2View, library: G2Library): G2View { // @ts-ignore - const { coordinate = {}, ...rest } = node; + const { coordinate = {}, coordinates, ...rest } = node; + + // If coordinates are already set, it means that the coordinate has been processed + // during the initialization. There is not need to process it during update. + if (coordinates) return node; + const { type, transform = [], ...options } = coordinate; if (!type) return { ...rest, coordinates: transform }; const [, createCoordinate] = useLibrary<