Skip to content

Commit e71a279

Browse files
committed
chore: 2.0.0-beta.3
1 parent 46389c7 commit e71a279

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

__tests__/unit/plugin/index-spec.ts

+4-2
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, getDefaultOptions, StepLineOption } from './step-line';
55

66
describe('plugin - G2Plot', () => {
77
it('StepLine', () => {
@@ -16,12 +16,14 @@ describe('plugin - G2Plot', () => {
1616
yField: 'value',
1717
stepType: 'hv',
1818
},
19-
StepLineAdaptor
19+
adaptor,
20+
getDefaultOptions
2021
);
2122

2223
plot.render();
2324

2425
expect(plot.type).toBe('g2-plot');
26+
expect(plot.options.stepType).toBe('vh');
2527
expect(plot.chart.geometries[0].type).toBe('line');
2628
});
2729
});

__tests__/unit/plugin/step-line.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface StepLineOption extends Options {
77
}
88

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

@@ -16,3 +16,10 @@ export function StepLineAdaptor(params: Params<StepLineOption>): Params<StepLine
1616

1717
return params;
1818
}
19+
20+
/** 默认参数处理 */
21+
export function getDefaultOptions(options: StepLineOption): Partial<StepLineOption> {
22+
return {
23+
stepType: 'vh',
24+
};
25+
}

package.json

+1-1
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.3",
44
"description": "An interactive and responsive charting library",
55
"keywords": [
66
"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.3';
22

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

src/plugin/index.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { deepMix, isFunction } from '@antv/util';
12
import { Plot, PickOptions } from '../core/plot';
23
import { Adaptor } from '../core/adaptor';
34
/**
@@ -28,17 +29,34 @@ export class G2Plot<O extends PickOptions> extends Plot<O> {
2829

2930
/** 外部传入的 adaptor 函数 */
3031
private adaptor: Adaptor<O>;
32+
private getDefaultOptionsFunction: (options: O) => Partial<O>;
3133

3234
/**
3335
* 相比普通图表增加 adaptor 参数。后续还可以考虑增加 defaultOptions
3436
* @param container
3537
* @param options
3638
* @param adaptor
3739
*/
38-
constructor(container: string | HTMLElement, options: O, adaptor: Adaptor<O>) {
40+
constructor(
41+
container: string | HTMLElement,
42+
options: O,
43+
adaptor: Adaptor<O>,
44+
getDefaultOptionsFunction?: (options: O) => Partial<O>
45+
) {
3946
super(container, options);
4047

4148
this.adaptor = adaptor;
49+
this.getDefaultOptionsFunction = getDefaultOptionsFunction;
50+
}
51+
52+
/**
53+
* 默认配置
54+
* @param options
55+
*/
56+
protected getDefaultOptions(options: O) {
57+
return isFunction(this.getDefaultOptionsFunction)
58+
? deepMix({}, super.getDefaultOptions(options), this.getDefaultOptionsFunction(options))
59+
: super.getDefaultOptions();
4260
}
4361

4462
/**

0 commit comments

Comments
 (0)