Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增堆叠分组功能 #1893

Merged
merged 7 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions __tests__/data/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,35 @@ export const POSITIVE_NEGATIVE_DATA = [
value: -470,
},
];

export const MultipleData = [
{ name: 'London', month: 'Jan.', value: 12.9, type: '语文' },
{ name: 'London', month: 'Jan.', value: 10.9, type: '数学' },
{ name: 'London', month: 'Jan.', value: 120.9, type: '英语' },
{ name: 'Berlin', month: 'Jan.', value: 12.4, type: '美术' },
{ name: 'Berlin', month: 'Jan.', value: 12.4, type: '线性代数' },
{ name: 'beijing', month: 'Jan.', value: 12.4, type: '高数' },
{ name: 'London', month: 'Feb.', value: 2.9, type: '语文' },
{ name: 'London', month: 'Feb.', value: 5.9, type: '数学' },
{ name: 'London', month: 'Feb.', value: 10.9, type: '英语' },
{ name: 'Berlin', month: 'Feb.', value: 22.4, type: '美术' },
{ name: 'Berlin', month: 'Feb.', value: 32.4, type: '线性代数' },
{ name: 'beijing', month: 'Feb.', value: 42.4, type: '高数' },
{ name: 'London', month: 'Mar.', value: 2.9, type: '语文' },
{ name: 'London', month: 'Mar.', value: 5.9, type: '数学' },
{ name: 'Berlin', month: 'Mar.', value: 22.4, type: '美术' },
{ name: 'Berlin', month: 'Mar.', value: 32.4, type: '线性代数' },
{ name: 'beijing', month: 'Mar.', value: 42.4, type: '高数' },
];

export const LineData = [
{ name: '福老师', month: 'Jan.', value: 12.9, type: '美术' },
{ name: '逍老师', month: 'Jan.', value: 1.4, type: '线性代数' },
{ name: '新老师', month: 'Jan.', value: 2.4, type: '高数' },
{ name: '福老师', month: 'Feb.', value: 18.9, type: '美术' },
{ name: '逍老师', month: 'Feb.', value: 13.4, type: '线性代数' },
{ name: '新老师', month: 'Feb.', value: 15.4, type: '高数' },
{ name: '福老师', month: 'Mar.', value: 8.9, type: '美术' },
{ name: '逍老师', month: 'Mar.', value: 6.4, type: '线性代数' },
{ name: '新老师', month: 'Mar.', value: 5.4, type: '高数' },
];
30 changes: 30 additions & 0 deletions __tests__/unit/plots/bar/stacked-grouped-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Bar } from '../../../../src';
import { MultipleData } from '../../../data/common';
import { createDiv } from '../../../utils/dom';

describe('Bar stacked grouped', () => {
it('stacked grouped', () => {
const bar = new Bar(createDiv(), {
width: 400,
height: 300,
data: MultipleData,
xField: 'value',
yField: 'month',
isGroup: true,
isStack: true,
seriesField: 'type',
groupField: 'name',
});

bar.render();

const geometry = bar.chart.geometries[0];
const elements = geometry.elements;
// @ts-ignore
const adjusts = geometry.adjusts;
expect(adjusts.dodge.dodgeBy).toBe('name');
expect(adjusts.stack.xField).toBe('month');
expect(elements.length).toBe(17);
bar.destroy();
});
});
30 changes: 30 additions & 0 deletions __tests__/unit/plots/column/stack-group-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Column } from '../../../../src';
import { MultipleData } from '../../../data/common';
import { createDiv } from '../../../utils/dom';

describe('column stacked grouped', () => {
it('stacked grouped', () => {
const column = new Column(createDiv(), {
width: 400,
height: 300,
data: MultipleData,
xField: 'month',
yField: 'value',
isGroup: true,
isStack: true,
seriesField: 'type',
groupField: 'name',
});

column.render();

const geometry = column.chart.geometries[0];
const elements = geometry.elements;
// @ts-ignore
const adjusts = geometry.adjusts;
expect(adjusts.dodge.dodgeBy).toBe('name');
expect(adjusts.stack.xField).toBe('month');
expect(elements.length).toBe(17);
column.destroy();
});
});
Loading