Skip to content

Commit da3b36b

Browse files
authored
chore: 2.0.0-beta.3 (#1531)
* chore: 2.0.0-beta.3 * chore: update unpkg file path * feat(plugin): add defaultOptions params * fix(padding): make update padding work
1 parent 46389c7 commit da3b36b

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

__tests__/unit/plugin/index-spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { G2Plot } from '../../../src';
22
import { createDiv } from '../../utils/dom';
33
import { partySupport } from '../../data/party-support';
4-
import { StepLineAdaptor, StepLineOption } from './step-line';
4+
import { adaptor, defaultOptions, StepLineOption } from './step-line';
55

66
describe('plugin - G2Plot', () => {
77
it('StepLine', () => {
@@ -14,14 +14,15 @@ describe('plugin - G2Plot', () => {
1414
data: partySupport.filter((o) => o.type === 'FF'),
1515
xField: 'date',
1616
yField: 'value',
17-
stepType: 'hv',
1817
},
19-
StepLineAdaptor
18+
adaptor,
19+
defaultOptions
2020
);
2121

2222
plot.render();
2323

2424
expect(plot.type).toBe('g2-plot');
25+
expect(plot.options.stepType).toBe('vh');
2526
expect(plot.chart.geometries[0].type).toBe('line');
2627
});
2728
});

__tests__/unit/plugin/step-line.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { Params, Options } from '../../../src';
22

3+
type StepType = 'vh' | 'hv' | 'vhv' | 'hvh';
4+
35
export interface StepLineOption extends Options {
46
readonly xField: string;
57
readonly yField: string;
6-
readonly stepType?: 'vh' | 'hv' | 'vhv' | 'hvh';
8+
readonly stepType?: StepType;
79
}
810

911
/** 这个方法作为一个包 export 出去 */
10-
export function StepLineAdaptor(params: Params<StepLineOption>): Params<StepLineOption> {
12+
export function adaptor(params: Params<StepLineOption>): Params<StepLineOption> {
1113
const { chart, options } = params;
12-
const { xField, yField, stepType = 'vh', data } = options;
14+
const { xField, yField, stepType, data } = options;
1315

1416
chart.line().position(`${xField}*${yField}`).shape(stepType);
1517
chart.data(data);
1618

1719
return params;
1820
}
21+
22+
/** 默认配置 */
23+
export const defaultOptions = {
24+
stepType: 'vh' as StepType,
25+
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g2plot",
3-
"version": "2.0.0-beta.2",
3+
"version": "2.0.0-beta.4",
44
"description": "An interactive and responsive charting library",
55
"keywords": [
66
"chart",
@@ -11,7 +11,7 @@
1111
"main": "lib/index.js",
1212
"module": "esm/index.js",
1313
"types": "lib/index.d.ts",
14-
"unpkg": "dist/g2plot.js",
14+
"unpkg": "dist/g2plot.min.js",
1515
"files": [
1616
"lib",
1717
"esm",

src/core/plot.ts

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export abstract class Plot<O extends PickOptions> extends EE {
125125

126126
const adaptor = this.getSchemaAdaptor();
127127

128+
const { padding } = this.options;
129+
// 更新 padding
130+
this.chart.padding = padding;
131+
128132
// 转化成 G2 API
129133
adaptor({
130134
chart: this.chart,

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const version = '2.0.0-beta.2';
1+
export const version = '2.0.0-beta.4';
22

33
// G2 自定义能力透出
44
export * as G2 from '@antv/g2';

src/plugin/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { deepMix } from '@antv/util';
12
import { Plot, PickOptions } from '../core/plot';
23
import { Adaptor } from '../core/adaptor';
34
/**
@@ -30,13 +31,14 @@ export class G2Plot<O extends PickOptions> extends Plot<O> {
3031
private adaptor: Adaptor<O>;
3132

3233
/**
33-
* 相比普通图表增加 adaptor 参数。后续还可以考虑增加 defaultOptions
34+
* 相比普通图表增加 adaptor 参数。
3435
* @param container
3536
* @param options
3637
* @param adaptor
38+
* @param defaultOptions
3739
*/
38-
constructor(container: string | HTMLElement, options: O, adaptor: Adaptor<O>) {
39-
super(container, options);
40+
constructor(container: string | HTMLElement, options: O, adaptor: Adaptor<O>, defaultOptions?: Partial<O>) {
41+
super(container, deepMix({}, defaultOptions, options));
4042

4143
this.adaptor = adaptor;
4244
}

0 commit comments

Comments
 (0)