From a81e92d4ef4792939ad84a44e257dce3d76b30c2 Mon Sep 17 00:00:00 2001 From: kasmine <736929286@qq.com> Date: Sun, 26 Jul 2020 21:38:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(v2/pie):=20=E4=BF=AE=E6=94=B9=20cr=20?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/bugs/issue-1245-spec.ts | 11 ++++------- package.json | 1 + src/plots/pie/adaptor.ts | 10 ++++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/__tests__/bugs/issue-1245-spec.ts b/__tests__/bugs/issue-1245-spec.ts index 0dac914cb99..875d21c4c8e 100644 --- a/__tests__/bugs/issue-1245-spec.ts +++ b/__tests__/bugs/issue-1245-spec.ts @@ -1,6 +1,5 @@ import { Pie } from '../../src'; import { createDiv } from '.././utils/dom'; -import { delay } from '.././utils/delay'; describe('donut plot', () => { test('angleField & colorField 配置交换, 不会触发 out-of-memory, 但是坐标为 NaN', () => { @@ -90,12 +89,10 @@ describe('donut plot', () => { expect(piePlot).toBeDefined(); expect(piePlot.chart.geometries[0].elements.length).toBe(data.length - 1); - delay(3000).then(() => { - piePlot.update({ - ...piePlot.options, - data: data.map((d, idx) => (idx !== 0 ? { ...d, value: null } : d)), - }); - expect(piePlot.chart.geometries[0].elements.length).toBe(data.length); + piePlot.update({ + ...piePlot.options, + data: data.map((d, idx) => (idx !== 0 ? { ...d, value: null } : d)), }); + expect(piePlot.chart.geometries[0].elements.length).toBe(data.length); }); }); diff --git a/package.json b/package.json index ba2793c232c..d799409e78e 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "eslint-config-prettier": "^6.0.0", "eslint-plugin-prettier": "^3.1.0", "husky": "^4.2.3", + "invariant": "^2.2.4", "jest": "^26.0.1", "jest-electron": "^0.1.7", "jest-extended": "^0.11.2", diff --git a/src/plots/pie/adaptor.ts b/src/plots/pie/adaptor.ts index 50576a0b33e..509687ad7c5 100644 --- a/src/plots/pie/adaptor.ts +++ b/src/plots/pie/adaptor.ts @@ -1,4 +1,5 @@ import { deepMix, each, filter, get, isFunction, isNil } from '@antv/util'; +import invariant from 'invariant'; import { Params } from '../../core/adaptor'; import { tooltip, interaction, animation, theme } from '../../common/adaptor'; import { flow } from '../../utils'; @@ -15,13 +16,10 @@ function field(params: Params): Params { const { data, angleField, colorField, color } = options; // 处理不合法的数据 - const progressData = filter(data, (d) => typeof d[angleField] === 'number' || isNil(d[angleField])); - if (progressData.length !== data.length) { - // 先打印出来,后面统一界面提示 - console.error('数据源存在不合适的数据,请检查'); - } + const processData = filter(data, (d) => typeof d[angleField] === 'number' || isNil(d[angleField])); + invariant(processData.length === data.length, 'Please check whether there exists illegal data'); - chart.data(progressData); + chart.data(processData); const geometry = chart.interval().position(`1*${angleField}`).adjust({ type: 'stack' }); if (colorField) {