Skip to content

Commit

Permalink
refactor: 百分比堆叠柱图数据更新
Browse files Browse the repository at this point in the history
  • Loading branch information
lucy-cl committed Sep 14, 2021
1 parent f9c4102 commit 66ad00b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Wbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +51,7 @@ interface WbarConfig extends BaseChartConfig, ZoomConfig, ScrollbarConfig {

export class Bar extends Base<WbarConfig> {
chartName = 'G2Bar';
private barDataView: DataView;
getDefaultConfig(): WbarConfig {
return {
colors: themes.category_12,
Expand Down Expand Up @@ -119,7 +120,8 @@ export class Bar extends Base<WbarConfig> {
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);
Expand Down Expand Up @@ -251,9 +253,9 @@ export class Bar extends Base<WbarConfig> {
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);
}
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 66ad00b

Please sign in to comment.