Skip to content

Commit

Permalink
feat(line): add smooth options
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Jul 16, 2020
1 parent 28bfece commit 768a8e0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
2 changes: 0 additions & 2 deletions __tests__/unit/plots/line/label-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ describe('line', () => {
label: false,
});
// @ts-ignore
window.line = line;
// @ts-ignore
expect(line.chart.geometries[0].labelOption).toBe(false);
});

Expand Down
36 changes: 36 additions & 0 deletions __tests__/unit/plots/line/shape-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Line } from '../../../../src';
import { partySupport } from '../../../data/party-support';
import { createDiv } from '../../../utils/dom';

describe('line', () => {
it('x*y and shape', () => {
const line = new Line(createDiv(), {
width: 400,
height: 300,
data: partySupport.filter((o) => ['FF'].includes(o.type)),
xField: 'date',
yField: 'value',
appendPadding: 10,
smooth: false,
});

line.render();
expect(line.chart.geometries[0].attributes.shape.values).toEqual(['line']);
});

it('x*y*color and shape', () => {
const line = new Line(createDiv(), {
width: 400,
height: 300,
data: partySupport.filter((o) => ['FF', 'Lab'].includes(o.type)),
xField: 'date',
yField: 'value',
seriesField: 'type',
appendPadding: 10,
smooth: true,
});

line.render();
expect(line.chart.geometries[0].attributes.shape.values).toEqual(['smooth']);
});
});
2 changes: 1 addition & 1 deletion __tests__/unit/plots/line/style-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('line', () => {

line.update({
...line.options,
lineStyle: (color: string) => {
lineStyle: () => {
return { lineDash: [4, 4] };
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chart, Geometry } from '@antv/g2';
import { Chart } from '@antv/g2';
import { Options } from '../types';

/**
Expand Down
16 changes: 15 additions & 1 deletion src/plots/line/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ function style(params: Params<LineOptions>): Params<LineOptions> {
return params;
}

/**
* shape 的配置处理
* @param params
*/
function shape(params: Params<LineOptions>): Params<LineOptions> {
const { chart, options } = params;
const { smooth } = options;

const lineGeometry = chart.geometries.find((g: Geometry) => g.type === 'line');

lineGeometry.shape(smooth ? 'smooth' : 'line');
return params;
}

/**
* 数据标签
* @param params
Expand Down Expand Up @@ -134,5 +148,5 @@ function label(params: Params<LineOptions>): Params<LineOptions> {
*/
export function adaptor(params: Params<LineOptions>) {
// flow 的方式处理所有的配置到 G2 API
flow(field, meta, axis, legend, tooltip, style, label)(params);
flow(field, meta, axis, legend, tooltip, style, shape, label)(params);
}

0 comments on commit 768a8e0

Please sign in to comment.