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: 柱条形图支持组间和组内padding的像素级设置 #2539

Merged
merged 2 commits into from
May 12, 2021
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
23 changes: 1 addition & 22 deletions __tests__/bugs/issue-2021-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,7 @@ import { TinyLine, TinyArea, TinyColumn } from '../../src';
import { createDiv } from '../utils/dom';

const DATA = [
264,
417,
438,
887,
309,
397,
550,
575,
563,
430,
525,
592,
492,
467,
513,
546,
983,
340,
539,
243,
226,
192,
264, 417, 438, 887, 309, 397, 550, 575, 563, 430, 525, 592, 492, 467, 513, 546, 983, 340, 539, 243, 226, 192,
];

describe('#2021', () => {
Expand Down
12 changes: 10 additions & 2 deletions __tests__/unit/plots/bullet/change-data-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ describe('Bullet changeData', () => {

const newData = [{ title: '数学', ranges: [0, 50, 100], measures: [120], target: 85 }];
bullet.changeData(newData);
const { min: newMin, max: newMax, ds: newDs } = transformData({
const {
min: newMin,
max: newMax,
ds: newDs,
} = transformData({
data: newData,
measureField: 'measures',
rangeField: 'ranges',
Expand Down Expand Up @@ -61,7 +65,11 @@ describe('Bullet changeData', () => {
expect(bullet.chart.geometries[0].data).toEqual([]);

bullet.changeData(bulletData);
const { min: newMin, max: newMax, ds: newDs } = transformData({
const {
min: newMin,
max: newMax,
ds: newDs,
} = transformData({
data: bulletData,
measureField: 'measures',
rangeField: 'ranges',
Expand Down
10 changes: 2 additions & 8 deletions __tests__/unit/plots/sankey/layout-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,14 @@ describe('sankeyLayout', () => {
expect(data.nodes[0].name).toBe("Agricultural 'waste'");
expect(data.nodes[0].x).toEqual([0, 0.008, 0.008, 0]);
expect(data.nodes[0].y).toEqual([
0.15714829392583463,
0.15714829392583463,
0.17602864502202453,
0.17602864502202453,
0.15714829392583463, 0.15714829392583463, 0.17602864502202453, 0.17602864502202453,
]);

expect(data.links[0].source.name).toBe("Agricultural 'waste'");
expect(data.links[0].target.name).toBe('Bio-conversion');
expect(data.links[0].x).toEqual([0.008, 0.008, 0.1417142857142857, 0.1417142857142857]);
expect(data.links[0].y).toEqual([
0.17602864502202453,
0.15714829392583463,
0.23174113600532192,
0.21286078490913202,
0.17602864502202453, 0.15714829392583463, 0.23174113600532192, 0.21286078490913202,
]);
});
});
16 changes: 16 additions & 0 deletions docs/common/bar-style.en.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#### intervalPadding

<description>**optional**, _number_</description>

Specify the padding of interval, pixel value. Used in GroupColumn plot.

<playground path='bar/grouped/interval-padding.ts' rid='rect1'></playground>

#### dodgePadding

<description>**optional**, _number_</description>

Specify the padding of interval on the same group, pixel value. Used in GroupColumn plot.

<playground path='bar/grouped/dodge-padding.ts' rid='rect2'></playground>

#### minBarWidth

<description>**optional**, _number_</description>
Expand Down
15 changes: 15 additions & 0 deletions docs/common/bar-style.zh.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#### intervalPadding

<description>**可选**, _number_</description>

功能描述: 分组柱状图的组间间距调整,像素级别。

<playground path='bar/grouped/interval-padding.ts' rid='rect1'></playground>

#### dodgePadding

<description>**可选**, _number_</description>

功能描述: 分组柱状图的组内柱子间距调整,像素级别。

<playground path='bar/grouped/dodge-padding.ts' rid='rect2'></playground>

#### minBarWidth

Expand Down
16 changes: 16 additions & 0 deletions docs/common/column-style.en.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#### intervalPadding

<description>**optional**, _number_</description>

Specify the padding of interval, pixel value. Used in GroupColumn plot.

<playground path='column/grouped/interval-padding.ts' rid='rect1'></playground>

#### dodgePadding

<description>**optional**, _number_</description>

Specify the padding of interval on the same group, pixel value. Used in GroupColumn plot.

<playground path='column/grouped/dodge-padding.ts' rid='rect2'></playground>

#### minColumnWidth

<description>**optional**, _number_</description>
Expand Down
15 changes: 15 additions & 0 deletions docs/common/column-style.zh.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#### intervalPadding

<description>**可选**, _number_</description>

功能描述: 分组柱状图的组间间距调整,像素级别。

<playground path='column/grouped/interval-padding.ts' rid='rect1'></playground>

#### dodgePadding

<description>**可选**, _number_</description>

功能描述: 分组柱状图的组内柱子间距调整,像素级别。

<playground path='column/grouped/dodge-padding.ts' rid='rect2'></playground>

#### minColumnWidth

Expand Down
78 changes: 78 additions & 0 deletions examples/bar/grouped/demo/dodge-padding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Bar } from '@antv/g2plot';

const data = [
{
label: 'Mon.',
type: 'series1',
value: 2800,
},
{
label: 'Mon.',
type: 'series2',
value: 2260,
},
{
label: 'Tues.',
type: 'series1',
value: 1800,
},
{
label: 'Tues.',
type: 'series2',
value: 1300,
},
{
label: 'Wed.',
type: 'series1',
value: 950,
},
{
label: 'Wed.',
type: 'series2',
value: 900,
},
{
label: 'Thur.',
type: 'series1',
value: 500,
},
{
label: 'Thur.',
type: 'series2',
value: 390,
},
{
label: 'Fri.',
type: 'series1',
value: 170,
},
{
label: 'Fri.',
type: 'series2',
value: 100,
},
];

const stackedBarPlot = new Bar('container', {
data,
isGroup: true,
xField: 'value',
yField: 'label',
seriesField: 'type',
dodgePadding: 4,
label: {
// 可手动配置 label 数据标签位置
position: 'middle', // 'left', 'middle', 'right'
// 可配置附加的布局方法
layout: [
// 柱形图数据标签位置自动调整
{ type: 'interval-adjust-position' },
// 数据标签防遮挡
{ type: 'interval-hide-overlap' },
// 数据标签文颜色自动调整
{ type: 'adjust-color' },
],
},
});

stackedBarPlot.render();
79 changes: 79 additions & 0 deletions examples/bar/grouped/demo/interval-padding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Bar } from '@antv/g2plot';

const data = [
{
label: 'Mon.',
type: 'series1',
value: 2800,
},
{
label: 'Mon.',
type: 'series2',
value: 2260,
},
{
label: 'Tues.',
type: 'series1',
value: 1800,
},
{
label: 'Tues.',
type: 'series2',
value: 1300,
},
{
label: 'Wed.',
type: 'series1',
value: 950,
},
{
label: 'Wed.',
type: 'series2',
value: 900,
},
{
label: 'Thur.',
type: 'series1',
value: 500,
},
{
label: 'Thur.',
type: 'series2',
value: 390,
},
{
label: 'Fri.',
type: 'series1',
value: 170,
},
{
label: 'Fri.',
type: 'series2',
value: 100,
},
];

const stackedBarPlot = new Bar('container', {
data,
isGroup: true,
xField: 'value',
yField: 'label',
seriesField: 'type',
dodgePadding: 4,
intervalPadding: 20,
label: {
// 可手动配置 label 数据标签位置
position: 'middle', // 'left', 'middle', 'right'
// 可配置附加的布局方法
layout: [
// 柱形图数据标签位置自动调整
{ type: 'interval-adjust-position' },
// 数据标签防遮挡
{ type: 'interval-hide-overlap' },
// 数据标签文颜色自动调整
{ type: 'adjust-color' },
],
},
});

stackedBarPlot.render();
16 changes: 16 additions & 0 deletions examples/bar/grouped/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
"en": "Bar plot with corner-radius"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/vFQNz1dCaD/21d77486-a9a3-4287-bc49-24fc40ad4800.png"
},
{
"filename": "dodge-padding.ts",
"title": {
"zh": "分组条形图像素级组内柱子间距",
"en": "DodgePadding of grouped bar plot"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/pb4RmT767Q/953ed207-ec9b-4d0b-8f19-dadd7e016610.png"
},
{
"filename": "interval-padding.ts",
"title": {
"zh": "分组条形图像素级组间间距",
"en": "IntervalPadding of grouped bar plot"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/%24aj8gaJ%267H/8d4e1840-3aa0-44af-bae4-6f6aa4de47e0.png"
}
]
}
30 changes: 30 additions & 0 deletions examples/column/grouped/demo/dodge-padding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Column } from '@antv/g2plot';

fetch('https://gw.alipayobjects.com/os/antfincdn/iPY8JFnxdb/dodge-padding.json')
.then((data) => data.json())
.then((data) => {
const plot = new Column('container', {
data,
isGroup: true,
xField: '月份',
yField: '月均降雨量',
seriesField: 'name',
// 分组柱状图 组内柱子间的间距 (像素级别)
dodgePadding: 2,
label: {
// 可手动配置 label 数据标签位置
position: 'middle', // 'top', 'middle', 'bottom'
// 可配置附加的布局方法
layout: [
// 柱形图数据标签位置自动调整
{ type: 'interval-adjust-position' },
// 数据标签防遮挡
{ type: 'interval-hide-overlap' },
// 数据标签文颜色自动调整
{ type: 'adjust-color' },
],
},
});

plot.render();
});
Loading