Skip to content

Commit 7f9d4a0

Browse files
author
xinming
committed
feat(v2/pie-annotations): 增加 utils 测试单例
1 parent 3e890f9 commit 7f9d4a0

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

__tests__/unit/plots/pie/utils-spec.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { getTotalValue } from '../../../../src/plots/pie/utils';
1+
import { Pie } from '../../../../src';
2+
import { getStatisticData, getTotalValue } from '../../../../src/plots/pie/utils';
3+
import { createDiv } from '../../../utils/dom';
24

35
describe('utils of pie plot', () => {
46
const data = [
@@ -46,4 +48,37 @@ describe('utils of pie plot', () => {
4648
)
4749
).toBe(null);
4850
});
51+
52+
it('getStatisticData: 单色饼图', () => {
53+
const pie = new Pie(createDiv(), {
54+
width: 400,
55+
height: 300,
56+
data: [],
57+
angleField: 'value',
58+
radius: 0.8,
59+
});
60+
61+
pie.render();
62+
expect(getStatisticData(pie.chart, [])).toEqual({ title: '总计', value: null });
63+
expect(getStatisticData(pie.chart, { value: 20 })).toEqual({ title: null, value: '20', color: undefined });
64+
});
65+
66+
it('getStatisticData: 带 colorField', () => {
67+
const pie = new Pie(createDiv(), {
68+
width: 400,
69+
height: 300,
70+
data: [],
71+
angleField: 'value',
72+
colorField: 'type',
73+
radius: 0.8,
74+
});
75+
76+
pie.render();
77+
expect(getStatisticData(pie.chart, [])).toEqual({ title: '总计', value: null });
78+
expect(getStatisticData(pie.chart, { type: 'item1', value: 20 })).toEqual({
79+
title: 'item1',
80+
value: '20',
81+
color: undefined,
82+
});
83+
});
4984
});

src/plots/pie/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getTotalValue(data: object[], field: string) {
1212
return total;
1313
}
1414

15-
export function getStatisticData(chart: View, data: object[], color?: string): StatisticData {
15+
export function getStatisticData(chart: View, data: object[] | object, color?: string): StatisticData {
1616
// @ts-ignore
1717
const [__, angleField, colorField] = chart.getScaleFields();
1818
const angleScale = chart.getScaleByField(angleField);

0 commit comments

Comments
 (0)