Skip to content

Commit fdd9fcf

Browse files
lxfu1liufu.lf
and
liufu.lf
authored
feat: 新增堆叠分组功能 (#1893)
* feat: 新增堆叠分组功能 * feat: 补充双轴图堆叠分组 line * fix: tests * fix: conversation * fix: 修复 tooltip 偏移 * docs: 打开tooltip * fix: word Co-authored-by: liufu.lf <[email protected]>
1 parent 3b24f38 commit fdd9fcf

File tree

23 files changed

+638
-23
lines changed

23 files changed

+638
-23
lines changed

__tests__/data/common.ts

+32
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,35 @@ export const POSITIVE_NEGATIVE_DATA = [
4848
value: -470,
4949
},
5050
];
51+
52+
export const MultipleData = [
53+
{ name: 'London', month: 'Jan.', value: 12.9, type: '语文' },
54+
{ name: 'London', month: 'Jan.', value: 10.9, type: '数学' },
55+
{ name: 'London', month: 'Jan.', value: 120.9, type: '英语' },
56+
{ name: 'Berlin', month: 'Jan.', value: 12.4, type: '美术' },
57+
{ name: 'Berlin', month: 'Jan.', value: 12.4, type: '线性代数' },
58+
{ name: 'beijing', month: 'Jan.', value: 12.4, type: '高数' },
59+
{ name: 'London', month: 'Feb.', value: 2.9, type: '语文' },
60+
{ name: 'London', month: 'Feb.', value: 5.9, type: '数学' },
61+
{ name: 'London', month: 'Feb.', value: 10.9, type: '英语' },
62+
{ name: 'Berlin', month: 'Feb.', value: 22.4, type: '美术' },
63+
{ name: 'Berlin', month: 'Feb.', value: 32.4, type: '线性代数' },
64+
{ name: 'beijing', month: 'Feb.', value: 42.4, type: '高数' },
65+
{ name: 'London', month: 'Mar.', value: 2.9, type: '语文' },
66+
{ name: 'London', month: 'Mar.', value: 5.9, type: '数学' },
67+
{ name: 'Berlin', month: 'Mar.', value: 22.4, type: '美术' },
68+
{ name: 'Berlin', month: 'Mar.', value: 32.4, type: '线性代数' },
69+
{ name: 'beijing', month: 'Mar.', value: 42.4, type: '高数' },
70+
];
71+
72+
export const LineData = [
73+
{ name: '福老师', month: 'Jan.', value: 12.9, type: '美术' },
74+
{ name: '逍老师', month: 'Jan.', value: 1.4, type: '线性代数' },
75+
{ name: '新老师', month: 'Jan.', value: 2.4, type: '高数' },
76+
{ name: '福老师', month: 'Feb.', value: 18.9, type: '美术' },
77+
{ name: '逍老师', month: 'Feb.', value: 13.4, type: '线性代数' },
78+
{ name: '新老师', month: 'Feb.', value: 15.4, type: '高数' },
79+
{ name: '福老师', month: 'Mar.', value: 8.9, type: '美术' },
80+
{ name: '逍老师', month: 'Mar.', value: 6.4, type: '线性代数' },
81+
{ name: '新老师', month: 'Mar.', value: 5.4, type: '高数' },
82+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Bar } from '../../../../src';
2+
import { MultipleData } from '../../../data/common';
3+
import { createDiv } from '../../../utils/dom';
4+
5+
describe('Bar stacked grouped', () => {
6+
it('stacked grouped', () => {
7+
const bar = new Bar(createDiv(), {
8+
width: 400,
9+
height: 300,
10+
data: MultipleData,
11+
xField: 'value',
12+
yField: 'month',
13+
isGroup: true,
14+
isStack: true,
15+
seriesField: 'type',
16+
groupField: 'name',
17+
});
18+
19+
bar.render();
20+
21+
const geometry = bar.chart.geometries[0];
22+
const elements = geometry.elements;
23+
// @ts-ignore
24+
const adjusts = geometry.adjusts;
25+
expect(adjusts.dodge.dodgeBy).toBe('name');
26+
expect(adjusts.stack.xField).toBe('month');
27+
expect(elements.length).toBe(17);
28+
bar.destroy();
29+
});
30+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Column } from '../../../../src';
2+
import { MultipleData } from '../../../data/common';
3+
import { createDiv } from '../../../utils/dom';
4+
5+
describe('column stacked grouped', () => {
6+
it('stacked grouped', () => {
7+
const column = new Column(createDiv(), {
8+
width: 400,
9+
height: 300,
10+
data: MultipleData,
11+
xField: 'month',
12+
yField: 'value',
13+
isGroup: true,
14+
isStack: true,
15+
seriesField: 'type',
16+
groupField: 'name',
17+
});
18+
19+
column.render();
20+
21+
const geometry = column.chart.geometries[0];
22+
const elements = geometry.elements;
23+
// @ts-ignore
24+
const adjusts = geometry.adjusts;
25+
expect(adjusts.dodge.dodgeBy).toBe('name');
26+
expect(adjusts.stack.xField).toBe('month');
27+
expect(elements.length).toBe(17);
28+
column.destroy();
29+
});
30+
});

0 commit comments

Comments
 (0)