From 66ad00b0d11158ff4c04cad397ae537f79bd0c81 Mon Sep 17 00:00:00 2001 From: lucy-cl Date: Tue, 14 Sep 2021 11:37:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=99=BE=E5=88=86=E6=AF=94?= =?UTF-8?q?=E5=A0=86=E5=8F=A0=E6=9F=B1=E5=9B=BE=E6=95=B0=E6=8D=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Wbar/index.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Wbar/index.tsx b/src/Wbar/index.tsx index c9503d41..50a8a146 100644 --- a/src/Wbar/index.tsx +++ b/src/Wbar/index.tsx @@ -2,7 +2,7 @@ import { Chart, Types, BaseChartConfig, Colors } from '../common/types'; import Base from "../common/Base"; -import { DataSet } from '@antv/data-set/lib/data-set'; +import { View as DataView } from '@antv/data-set/lib/view'; import '@antv/data-set/lib/transform/percent'; import errorWrap from '../common/errorWrap'; import themes from '../themes/index'; @@ -51,6 +51,7 @@ interface WbarConfig extends BaseChartConfig, ZoomConfig, ScrollbarConfig { export class Bar extends Base { chartName = 'G2Bar'; + private barDataView: DataView; getDefaultConfig(): WbarConfig { return { colors: themes.category_12, @@ -119,7 +120,8 @@ export class Bar extends Base { chart.scale(defs); if (config.percentStack) { - const dataView = computerData(config, data); + const dataView = computerData(data); + this.barDataView = dataView; chart.data(dataView.rows); } else { chart.data(data); @@ -251,9 +253,9 @@ export class Bar extends Base { rectScrollbar(chart, config); } changeData(chart: Chart, config: WbarConfig, data: any) { - if (config.percentStack) { - const dataView = computerData(config, data); - chart.changeData(dataView.rows); + if (config.percentStack && this.barDataView) { + this.barDataView.source(data); + chart.changeData(this.barDataView.rows); } else { chart.changeData(data); } @@ -320,10 +322,8 @@ function drawBar(chart: Chart, config: WbarConfig, colors: Colors, field = 'type label(geom, config); } -function computerData(config: WbarConfig, data: any) { - const ds = new DataSet(); - const dv = ds - .createView() +function computerData(data: any) { + const dv = new DataView() .source(data); dv.transform({ type: 'percent',