Skip to content

Commit

Permalink
feat: 玉珏图重写changeData方法 && 添加单测 (#2206)
Browse files Browse the repository at this point in the history
Co-authored-by: 沈建斌 <wb-sjb709429@antfin.com>
  • Loading branch information
yp0413150120 and 沈建斌 authored Jan 12, 2021
1 parent 144cf23 commit 71868f2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
49 changes: 49 additions & 0 deletions __tests__/unit/plots/radial-bar/change-data-spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
9 changes: 9 additions & 0 deletions src/plots/radial-bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export class RadialBar extends Plot<RadialBarOptions> {
/** 图表类型 */
public type: string = 'radial-bar';

/**
* @override
* @param data
*/
public changeData(data) {
this.updateOption({ data });
this.chart.changeData(data);
}

/**
* 获取默认配置
*/
Expand Down

0 comments on commit 71868f2

Please sign in to comment.