Skip to content

Commit

Permalink
feat: 添加一些方法的别名,以兼容 3.x,但是这些方法将会在 4.1 版本中移除
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ authored and hustcc committed Mar 30, 2020
1 parent 539f839 commit 6356363
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/chart/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ export class View extends Base {
return this;
}

/**
* @deprecated
* This method will be removed at G2 V4.1. Replaced by {@link #data(data)}
*/
public source(data: Data): View {
console.warn('This method will be removed at G2 V4.1. Please use chart.data() instead.');
return this.data(data);
}

/**
* 设置数据筛选规则。
*
Expand Down Expand Up @@ -517,6 +526,15 @@ export class View extends Base {
return this.getController('annotation') as Annotation;
}

/**
* @deprecated
* This method will be removed at G2 V4.1. Replaced by {@link #guide()}
*/
public guide(): Annotation {
console.warn('This method will be removed at G2 V4.1. Please use chart.annotation() instead.');
return this.annotation();
}

/**
* 坐标系配置。
*
Expand Down Expand Up @@ -567,6 +585,16 @@ export class View extends Base {
return this.coordinateController;
}

/**
* @deprecated
* This method will be removed at G2 V4.1. Replaced by {@link #coordinate()}
*/
public coord(type: string | CoordinateOption, coordinateCfg?: CoordinateCfg): CoordinateController {
console.warn('This method will be removed at G2 V4.1. Please use chart.coordinate() instead.');
// @ts-ignore
return this.coordinate(type, coordinateCfg);
}

/**
* view 分面绘制。
*
Expand Down Expand Up @@ -788,6 +816,15 @@ export class View extends Base {
return v;
}

/**
* @deprecated
* This method will be removed at G2 V4.1. Replaced by {@link #createView()}
*/
public view(cfg?: Partial<ViewCfg>) {
console.warn('This method will be removed at G2 V4.1. Please use chart.createView() instead.')
return this.createView(cfg);
}

/**
* 删除一个子 view
* @param view
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/chart/multi-view-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('chart multi view', () => {
},
padding: 20,
});
const v2 = chart.createView({
const v2 = chart.view({
region: {
start: { x: 0.5, y: 0 },
end: { x: 1, y: 1 },
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/chart/view/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ describe('View', () => {
expect(view.getOptions().data).toEqual(data);
});

it('source', () => {
// deperated method
view.source(data);

expect(view.getOptions().data).toEqual(data);
});

it('axis', () => {
view.axis(false);
expect(view.getOptions().axes).toBe(false);
Expand Down Expand Up @@ -153,6 +160,11 @@ describe('View', () => {
expect(view.getCoordinate().getHeight()).toEqual(590);
});

it('coord', () => {
const c = view.coord('rect');
expect(c.getOption().type).toEqual('rect');
});

it('animate', () => {
// @ts-ignore 默认执行动画
expect(view.options.animate).toBe(true);
Expand Down

0 comments on commit 6356363

Please sign in to comment.