From f12067e08185fd2fb67ba623378b9bc72105c0d8 Mon Sep 17 00:00:00 2001 From: liwenbo Date: Sun, 24 Dec 2023 21:38:44 +0800 Subject: [PATCH 1/2] fix: fix point scale generates gradient color --- src/shape/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shape/utils.ts b/src/shape/utils.ts index db39b148be..4799a01334 100644 --- a/src/shape/utils.ts +++ b/src/shape/utils.ts @@ -148,7 +148,7 @@ export function computeGradient( range: [0, 100], }); - const percentage = (i) => p.map(P[i]); + const percentage = (i) => (Number.isNaN(P[i]) ? 0 : p.map(P[i])); const gradientMode = { // Interpolate the colors for this segment. From 2a77a10d973d3a74be3040b155ce8664f4ef00d2 Mon Sep 17 00:00:00 2001 From: liwenbo Date: Mon, 8 Jan 2024 20:55:21 +0800 Subject: [PATCH 2/2] fix(component): cr & add screenshot test --- .../static/aaplLineIllegalDataSlider.svg | 2259 +++++++++++++++++ .../static/aapl-line-illegal-data-slider.ts | 54 + __tests__/plots/static/index.ts | 1 + src/shape/utils.ts | 5 +- 4 files changed, 2317 insertions(+), 2 deletions(-) create mode 100644 __tests__/integration/snapshots/static/aaplLineIllegalDataSlider.svg create mode 100644 __tests__/plots/static/aapl-line-illegal-data-slider.ts diff --git a/__tests__/integration/snapshots/static/aaplLineIllegalDataSlider.svg b/__tests__/integration/snapshots/static/aaplLineIllegalDataSlider.svg new file mode 100644 index 0000000000..134a4ecd95 --- /dev/null +++ b/__tests__/integration/snapshots/static/aaplLineIllegalDataSlider.svg @@ -0,0 +1,2259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (东北, 长春) + + + + + + + + + + + + + + + + + + + + + + (华东, 江西) + + + + + + + + + + + + + + value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10000 + + + + + + + 15000 + + + + + + + 20000 + + + + + + + 25000 + + + + + + + 30000 + + + + + + + 35000 + + + + + + + 40000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (东北, 长春) + + + + + + + (东北, 辽宁) + + + + + + + (, 辽宁) + + + + + + + (华东, 上海) + + + + + + + (华东, 山东) + + + + + + + (华东, 江苏) + + + + + + + (华东, 江西) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10000 + + + + + + + 15000 + + + + + + + 20000 + + + + + + + 25000 + + + + + + + 30000 + + + + + + + 35000 + + + + + + + 40000 + + + + + + + + + value + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/__tests__/plots/static/aapl-line-illegal-data-slider.ts b/__tests__/plots/static/aapl-line-illegal-data-slider.ts new file mode 100644 index 0000000000..ad6a6c3788 --- /dev/null +++ b/__tests__/plots/static/aapl-line-illegal-data-slider.ts @@ -0,0 +1,54 @@ +import { G2Spec } from '../../../src'; + +export function aaplLineIllegalDataSlider(): G2Spec { + return { + type: 'line', + data: [ + { + area: '东北', + province: '长春', + value: 10000, + }, + { + area: '东北', + province: '辽宁', + value: 10000, + }, + { + area: '', + province: '辽宁', + value: null, + }, + { + area: '华东', + province: '上海', + value: 10000, + }, + { + area: '华东', + province: '山东', + value: 40000, + }, + { + area: '华东', + province: '江苏', + value: 10000, + }, + { + area: '华东', + province: '江西', + value: 10000, + }, + ], + encode: { + x: (x) => `(${x.area}, ${x.province})`, + y: 'value', + color: 'value', + }, + scale: { + color: { type: 'linear', unknown: '#fff' }, + }, + style: { gradient: 'y', lineWidth: 2 }, + slider: { x: true }, + }; +} diff --git a/__tests__/plots/static/index.ts b/__tests__/plots/static/index.ts index 2c270d41b0..ff94a9f7e7 100644 --- a/__tests__/plots/static/index.ts +++ b/__tests__/plots/static/index.ts @@ -316,3 +316,4 @@ export { titanicPointPackSharedDataPadding } from './titanic-point-pack-shared-d export { scoreByItemAreaBasicRadar } from './score-by-item-area-basic-radar'; export { scoreByItemAreaLineRadar } from './score-by-item-area-line-radar'; export { mockComplexRadar } from './mock-complex-radar'; +export { aaplLineIllegalDataSlider } from './aapl-line-illegal-data-slider'; diff --git a/src/shape/utils.ts b/src/shape/utils.ts index 4799a01334..46828c05d1 100644 --- a/src/shape/utils.ts +++ b/src/shape/utils.ts @@ -1,6 +1,6 @@ import { Coordinate } from '@antv/coord'; import { Linear } from '@antv/scale'; -import { lowerFirst } from '@antv/util'; +import { isNumber, lowerFirst } from '@antv/util'; import { extent } from 'd3-array'; import { Path as D3Path } from 'd3-path'; import { Primitive, Vector2, Vector3 } from '../runtime'; @@ -148,7 +148,8 @@ export function computeGradient( range: [0, 100], }); - const percentage = (i) => (Number.isNaN(P[i]) ? 0 : p.map(P[i])); + const percentage = (i) => + isNumber(P[i]) && !Number.isNaN(P[i]) ? p.map(P[i]) : 0; const gradientMode = { // Interpolate the colors for this segment.