Skip to content

Commit

Permalink
Merge pull request #1584 from antvis/unify-init
Browse files Browse the repository at this point in the history
统一使用 init 作为初始化含义
  • Loading branch information
hustcc authored Oct 28, 2019
2 parents 6addd00 + 69e7420 commit 22f7e84
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/chart/__components__/mock-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export class MockComponent extends Component {
this.text = text;
this.attributes = attributes;

this.initial();
this.init();
}

protected initial() {
protected init() {
this.container.addShape('text', {
attrs: {
x: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/chart/__components__/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export class Text extends Component {
this.isHorizontal = isHorizontal;
this.attributes = attributes;

this.initial();
this.init();
}

protected initial() {
protected init() {
let attrs: LooseObject = {
x: 0,
y: 0,
Expand Down
20 changes: 10 additions & 10 deletions src/chart/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class View extends EE {
// 接受父 view 传入的参数
this.options = { ...this.options, ...options };

this.initial();
this.init();
}

/**
Expand Down Expand Up @@ -190,13 +190,13 @@ export default class View extends EE {
/**
* 初始化
*/
public initial() {
public init() {
// 事件委托机制
this.initialEvents();
this.initEvents();

// 递归初始化子 view
_.each(this.views, (view: View) => {
view.initial();
view.init();
});
}

Expand All @@ -214,7 +214,7 @@ export default class View extends EE {
}

/**
* 清空,之后可以再走 initial 流程,正常使用
* 清空,之后可以再走 init 流程,正常使用
*/
public clear() {
this.emit(ViewLifeCircle.BEFORE_CLEAR);
Expand Down Expand Up @@ -609,7 +609,7 @@ export default class View extends EE {
this.createCoordinate();
}
// 4. 初始化 Geometry
this.initialGeometries();
this.initGeometries();
// 5. 渲染组件 component
this.renderComponents();
// 6. 递归 views,进行布局
Expand Down Expand Up @@ -637,7 +637,7 @@ export default class View extends EE {
* 当前 view 只委托自己 view 中的 Component 和 Geometry 事件,并向上冒泡
* @private
*/
private initialEvents() {
private initEvents() {
// 三层 group 中的 shape 事件都会通过 G 冒泡上来的
this.foregroundGroup.on('*', this.onEvents);
this.middleGroup.on('*', this.onEvents);
Expand Down Expand Up @@ -730,7 +730,7 @@ export default class View extends EE {
* 初始化 Geometries
* @private
*/
private initialGeometries() {
private initGeometries() {
// 实例化 Geometry,然后 view 将所有的 scale 管理起来
_.each(this.geometries, (geometry: Geometry) => {
// 使用 coordinate 引用,可以保持 coordinate 的同步更新
Expand All @@ -741,7 +741,7 @@ export default class View extends EE {
// 保持 scales 引用不要变化
geometry.scales = this.scales;

geometry.initial();
geometry.init();
});

// Geometry 初始化之后,生成了 scale,然后进行调整 scale 配置
Expand Down Expand Up @@ -880,7 +880,7 @@ export default class View extends EE {
private renderFacet() {
if (this.facetInstance) {
// 计算分面数据
this.facetInstance.initial();
this.facetInstance.init();
// 渲染组件和 views
this.facetInstance.render();
}
Expand Down
2 changes: 1 addition & 1 deletion src/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default abstract class Component extends EE {
}

/** 初始化节点 */
protected abstract initial();
protected abstract init();

// 代理 G.shape 事件,然后自己 emit 出来
protected abstract proxyEvents();
Expand Down
4 changes: 2 additions & 2 deletions src/facet/facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FacetCfg, FacetComponent, FacetData } from './interface';
*
* 生命周期:
*
* 初始化 initial
* 初始化 init
* 1. 初始化容器
* 2. 数据分面,生成分面布局信息
*
Expand Down Expand Up @@ -52,7 +52,7 @@ export default abstract class Facet<C extends FacetCfg = FacetCfg, F extends Fac
/**
* 初始化过程
*/
public initial() {
public init() {
// 初始化容器
this.container = this.createContainer();

Expand Down
2 changes: 1 addition & 1 deletion src/geometry/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default class Geometry {
*/
public label() {}

public initial() {
public init() {
// TODO: @simaq 是否可以移除设置矩阵这一步?
// 需要修改 @antv/coord 模块,将点与当前矩阵相乘
const coordinate = this.coordinate;
Expand Down
4 changes: 2 additions & 2 deletions src/geometry/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class Interval extends Geometry {

private defaultSize: number;

public initial() {
super.initial();
public init() {
super.init();
this.adjustYScale();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/geometry/base-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ describe('Geometry', () => {
});

it('init()', () => {
geometry.initial();
geometry.init();

// attrs 的生成
const attrs = geometry.attributes;
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/geometry/interval-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Interval', () => {
expect(interval.visible).toBe(true);
});

test('initial()', () => {
test('init()', () => {
interval = new Interval({
data,
scaleDefs: {
Expand All @@ -46,7 +46,7 @@ describe('Interval', () => {
});

interval.position('a*b').color('a');
interval.initial();
interval.init();

const attributes = interval.attributes;
expect(attributes).toContainKeys(['position', 'color']);
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('Interval', () => {
test('interval.size(20)', () => {
interval.size(20); // 指定 interval 的宽度

interval.initial();
interval.init();
interval.paint();

expect(interval.defaultSize).toBe(undefined);
Expand All @@ -115,7 +115,7 @@ describe('Interval', () => {
interval.theme.minColumnWidth = 40;

interval.size(null);
interval.initial();
interval.init();
interval.paint();

canvas.draw();
Expand All @@ -131,7 +131,7 @@ describe('Interval', () => {
interval.theme.maxColumnWidth = 10;
interval.theme.minColumnWidth = null;

interval.initial();
interval.init();
interval.paint();

canvas.draw();
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('Interval', () => {
interval.position('a*b');

it('yScale min adjust when user define min', () => {
interval.initial();
interval.init();
// 为了观察最终的绘制结果
interval.paint();
canvas.draw();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/geometry/line-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Line', () => {
});

line.position('x*y');
line.initial();
line.init();
line.paint();
canvas.draw();

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/geometry/path-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Path', () => {
});

path.position('x*y').size(4);
path.initial();
path.init();
path.paint();
canvas.draw();

Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Path', () => {
});

path.position('x*y').size(4);
path.initial();
path.init();
path.paint();
canvas.draw();

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/geometry/util/shape-size-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Calculate shape size', () => {
});

interval.position('a*b').color('a');
interval.initial();
interval.init();

test('default', () => {
const normalizedSize = getDefaultSize(interval);
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Calculate shape size', () => {
theme: Theme,
});
interval.position('a*b');
interval.initial();
interval.init();
// interval.paint();
// canvas.draw();

Expand All @@ -109,7 +109,7 @@ describe('Calculate shape size', () => {
theme: Theme,
});
interval.position('a*b');
interval.initial();
interval.init();
// interval.paint();
// canvas.draw();
expect(getDefaultSize(interval)).toBe(0.125);
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('Calculate shape size', () => {
type: 'dodge',
});

interval.initial();
interval.init();

const normalizedSize = getDefaultSize(interval);
expect(normalizedSize).toBe(1 / 12);
Expand All @@ -164,7 +164,7 @@ describe('Calculate shape size', () => {
dodgeBy: 'a',
});

interval.initial();
interval.init();
const normalizedSize = getDefaultSize(interval);
expect(normalizedSize).toBe(1 / 18);
});
Expand All @@ -188,7 +188,7 @@ describe('Calculate shape size', () => {
},
});
interval.position('a*b');
interval.initial();
interval.init();

test('polar interval', () => {
const normalizedSize = getDefaultSize(interval);
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('Calculate shape size', () => {
.color('a')
.adjust('stack');

interval.initial();
interval.init();

const normalizedSize = getDefaultSize(interval);
expect(normalizedSize).toBe(0.9999999);
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('Calculate shape size', () => {
fields: ['c'],
});

interval.initial();
interval.init();

const normalizedSize = getDefaultSize(interval);
expect(normalizedSize).toBe((1 / 6) * Theme.roseWidthRatio);
Expand Down Expand Up @@ -307,7 +307,7 @@ describe('Calculate shape size', () => {
fields: ['c'],
});

interval.initial();
interval.init();
// interval.paint();
// canvas.draw();

Expand Down

0 comments on commit 22f7e84

Please sign in to comment.