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: 面积图支持 startOnZero #2444

Merged
merged 3 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions __tests__/unit/plots/area/start-on-zero-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Area } from '../../../../src';
import { createDiv } from '../../../utils/dom';

describe('area', () => {
it('start on zero', () => {
const data = [
{ date: '19/05/2006', type: 'FF', value: 3600 },
{ date: '19/06/2006', type: 'FG', value: 2500 },
{ date: '19/07/2006', type: 'Lab', value: -2000 },
{ date: '19/08/2006', type: 'SF', value: 800 },
{ date: '19/09/2006', type: 'Ind/Oth', value: 1700 },
];
const area = new Area(createDiv(), {
width: 400,
height: 300,
data,
xField: 'date',
yField: 'value',
startOnZero: false,
isStack: false,
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved
});

area.render();
const geometry = area.chart.geometries[0];
// @ts-ignore
expect(geometry.startOnZero).toBeFalsy();
expect(area.chart.getScaleByField('value').min).toBe(-2000);
area.update({
startOnZero: true,
});
// @ts-ignore
expect(area.chart.geometries[0].startOnZero).toBeTruthy();
area.destroy();
});
});
9 changes: 9 additions & 0 deletions docs/api/plots/area.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ Whether the plot is Stacked Area.

Whether the plot is Percent Area. When the plot is Percent Area, isStack is `true` by default.

#### startOnZero

<description>**optional** _boolean_ _default:_ `true`</description>

Whether the plot is filled from 0 datum,isStack must be false when used.

<img alt='startOnZero-true' width='300' src='https://gw.alipayobjects.com/zos/rmsportal/ZQqwUCczalrKqGgagOVp.png'/>
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved

<img alt='startOnZero-false' width='300' src='https://gw.alipayobjects.com/zos/rmsportal/yPswkaXvUpCYOdhocGwB.png'/>
#### areaStyle

<description>**optional** _StyleAttr | Function_</description>
Expand Down
10 changes: 10 additions & 0 deletions docs/api/plots/area.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ order: 1

是否百分比面积图,百分比时默认开启 isStack。

#### startOnZero

<description>**optional** _boolean_ _default:_ `true`</description>

积图是否从 0 基准线开始填充,使用时 isStack 需为 false。

<img alt='startOnZero-true' width='300' src='https://gw.alipayobjects.com/zos/rmsportal/ZQqwUCczalrKqGgagOVp.png'/>

<img alt='startOnZero-false' width='300' src='https://gw.alipayobjects.com/zos/rmsportal/yPswkaXvUpCYOdhocGwB.png'/>

#### areaStyle

<description>**optional** _StyleAttr | Function_</description>
Expand Down
4 changes: 4 additions & 0 deletions src/plots/area/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
yField,
tooltip,
seriesField,
startOnZero,
} = options;
const pointState = pointMapping?.state;

Expand Down Expand Up @@ -60,6 +61,9 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
tooltip: tooltipOptions,
// label 不传递给各个 geometry adaptor,由 label adaptor 处理
label: undefined,
args: {
startOnZero,
},
},
});
const second = deepAssign({}, primary, { options: { tooltip: false } });
Expand Down
2 changes: 2 additions & 0 deletions src/plots/area/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ export interface AreaOptions extends Options {
readonly line?: LineGeometryOptions['line'];
/** 面积图数据点图形样式 */
readonly point?: PointGeometryOptions['point'] & Pick<PointGeometryOptions, 'state'>;
/** 积图是否从 0 基准线开始填充 */
readonly startOnZero?: boolean;
}