From 71868f22e26fc635c18f74bd54ce5bd12e58ab2e Mon Sep 17 00:00:00 2001 From: banli <691525671@qq.com> Date: Tue, 12 Jan 2021 16:22:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8E=89=E7=8F=8F=E5=9B=BE=E9=87=8D?= =?UTF-8?q?=E5=86=99changeData=E6=96=B9=E6=B3=95=20&&=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=8D=95=E6=B5=8B=20(#2206)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 沈建斌 --- .../unit/plots/radial-bar/change-data-spec.ts | 49 +++++++++++++++++++ src/plots/radial-bar/index.ts | 9 ++++ 2 files changed, 58 insertions(+) create mode 100644 __tests__/unit/plots/radial-bar/change-data-spec.ts diff --git a/__tests__/unit/plots/radial-bar/change-data-spec.ts b/__tests__/unit/plots/radial-bar/change-data-spec.ts new file mode 100644 index 0000000000..8172284a1c --- /dev/null +++ b/__tests__/unit/plots/radial-bar/change-data-spec.ts @@ -0,0 +1,49 @@ +import { RadialBar } from '../../../../src'; +import { createDiv } from '../../../utils/dom'; +import { antvStar } from '../../../data/antv-star'; + +describe('radial-bar changeData', () => { + it('changeData: normal', () => { + const bar = new RadialBar(createDiv(), { + width: 400, + height: 300, + data: antvStar, + xField: 'name', + yField: 'start', + radius: 0.8, + innerRadius: 0.2, + }); + bar.render(); + + expect(bar.chart.geometries[0].elements.length).toEqual(antvStar.length); + + const newData = antvStar.slice(0, 4); + bar.changeData(newData); + expect(bar.chart.geometries[0].elements.length).toEqual(newData.length); + expect(bar.options.data).toEqual(newData); + + bar.destroy(); + }); + + it('changeData: from empty to have data', () => { + const bar = new RadialBar(createDiv(), { + width: 400, + height: 300, + data: [], + xField: 'name', + yField: 'start', + radius: 0.8, + innerRadius: 0.2, + }); + + bar.render(); + + expect(bar.chart.geometries[0].elements.length).toEqual(0); + + bar.changeData(antvStar); + expect(bar.chart.geometries[0].elements.length).toEqual(antvStar.length); + expect(bar.options.data).toEqual(antvStar); + + bar.destroy(); + }); +}); diff --git a/src/plots/radial-bar/index.ts b/src/plots/radial-bar/index.ts index 50eed5bbef..5f4e98ed93 100644 --- a/src/plots/radial-bar/index.ts +++ b/src/plots/radial-bar/index.ts @@ -13,6 +13,15 @@ export class RadialBar extends Plot { /** 图表类型 */ public type: string = 'radial-bar'; + /** + * @override + * @param data + */ + public changeData(data) { + this.updateOption({ data }); + this.chart.changeData(data); + } + /** * 获取默认配置 */