Skip to content

Commit

Permalink
Life Cycle: Add instance parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaming743 committed Sep 23, 2020
1 parent ff17ae8 commit 99edd9c
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 70 deletions.
16 changes: 8 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ var CRender = /** @class */ (function () {
CRender.prototype.drawGraphProcessor = function (graph) {
var _a, _b;
graph.style.setCtx(this);
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph);
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
graph.draw();
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph);
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
graph.style.restoreCtx(this);
};
CRender.prototype.add = function (graph, wait) {
Expand All @@ -339,12 +339,12 @@ var CRender = /** @class */ (function () {
};
CRender.prototype.graphAddProcessor = function (graph) {
var _a, _b;
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph);
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
graph.render = this;
graph.setGraphCenter();
this.graphs.push(graph);
this.sortGraphsByIndex();
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph);
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
};
CRender.prototype.delGraph = function (graph, wait) {
if (wait === void 0) { wait = false; }
Expand All @@ -363,9 +363,9 @@ var CRender = /** @class */ (function () {
var index = graphs.findIndex(function (_) { return _ === graph; });
if (index === -1)
return;
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph);
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
graphs.splice(index, 1);
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph);
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
};
CRender.prototype.delAllGraph = function () {
this.delGraph(this.graphs);
Expand Down Expand Up @@ -489,9 +489,9 @@ var CRender = /** @class */ (function () {
var _a, _b;
if (!graph.move)
return;
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e);
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e, graph);
graph.move(e);
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e);
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e, graph);
graph.setGraphCenter(e);
};
CRender.prototype.graphHoverCheckProcessor = function (graph, point) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/guide/graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ clone(add: boolean = true): this {
/**
* @description 图形添加前被调用
*/
beforeAdd?: () => any
beforeAdd?: (graph: Graph) => any
```

### added
Expand All @@ -309,7 +309,7 @@ beforeAdd?: () => any
/**
* @description 图形添加后被调用
*/
added?: () => any
added?: (graph: Graph) => any
```

### beforeDraw
Expand All @@ -318,7 +318,7 @@ added?: () => any
/**
* @description 图形渲染前被调用
*/
beforeDraw?: () => any
beforeDraw?: (graph: Graph) => any
```

### drawed
Expand All @@ -327,7 +327,7 @@ beforeDraw?: () => any
/**
* @description 图形渲染后被调用
*/
drawed?: () => any
drawed?: (graph: Graph) => any
```

### beforeMove
Expand All @@ -337,7 +337,7 @@ drawed?: () => any
* @description 图形移动前被调用
* @param {MouseEvent} e 鼠标事件
*/
beforeMove?: (e: MouseEvent) => any
beforeMove?: (e: MouseEvent, graph: Graph) => any
```

### moved
Expand All @@ -347,7 +347,7 @@ beforeMove?: (e: MouseEvent) => any
* @description 图形移动后被调用
* @param {MouseEvent} e 鼠标事件
*/
moved?: (e: MouseEvent) => any
moved?: (e: MouseEvent, graph: Graph) => any
```

### beforeDelete
Expand All @@ -356,7 +356,7 @@ moved?: (e: MouseEvent) => any
/**
* @description 图形删除前被调用
*/
beforeDelete?: () => any
beforeDelete?: (graph: Graph) => any
```

### deleted
Expand All @@ -365,7 +365,7 @@ beforeDelete?: () => any
/**
* @description 图形删除后被调用
*/
deleted?: () => any
deleted?: (graph: Graph) => any
```

## 覆盖默认行为
Expand Down
16 changes: 8 additions & 8 deletions es/core/crender.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
var _graph$beforeDraw, _graph$drawed;

graph.style.setCtx(this);
(_graph$beforeDraw = graph.beforeDraw) === null || _graph$beforeDraw === void 0 ? void 0 : _graph$beforeDraw.call(graph);
(_graph$beforeDraw = graph.beforeDraw) === null || _graph$beforeDraw === void 0 ? void 0 : _graph$beforeDraw.call(graph, graph);
graph.draw();
(_graph$drawed = graph.drawed) === null || _graph$drawed === void 0 ? void 0 : _graph$drawed.call(graph);
(_graph$drawed = graph.drawed) === null || _graph$drawed === void 0 ? void 0 : _graph$drawed.call(graph, graph);
graph.style.restoreCtx(this);
}
}, {
Expand All @@ -196,12 +196,12 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
value: function graphAddProcessor(graph) {
var _graph$beforeAdd, _graph$added;

(_graph$beforeAdd = graph.beforeAdd) === null || _graph$beforeAdd === void 0 ? void 0 : _graph$beforeAdd.call(graph);
(_graph$beforeAdd = graph.beforeAdd) === null || _graph$beforeAdd === void 0 ? void 0 : _graph$beforeAdd.call(graph, graph);
graph.render = this;
graph.setGraphCenter();
this.graphs.push(graph);
this.sortGraphsByIndex();
(_graph$added = graph.added) === null || _graph$added === void 0 ? void 0 : _graph$added.call(graph);
(_graph$added = graph.added) === null || _graph$added === void 0 ? void 0 : _graph$added.call(graph, graph);
}
}, {
key: "delGraph",
Expand All @@ -228,9 +228,9 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
return _ === graph;
});
if (index === -1) return;
(_graph$beforeDelete = graph.beforeDelete) === null || _graph$beforeDelete === void 0 ? void 0 : _graph$beforeDelete.call(graph);
(_graph$beforeDelete = graph.beforeDelete) === null || _graph$beforeDelete === void 0 ? void 0 : _graph$beforeDelete.call(graph, graph);
graphs.splice(index, 1);
(_graph$deleted = graph.deleted) === null || _graph$deleted === void 0 ? void 0 : _graph$deleted.call(graph);
(_graph$deleted = graph.deleted) === null || _graph$deleted === void 0 ? void 0 : _graph$deleted.call(graph, graph);
}
}, {
key: "delAllGraph",
Expand Down Expand Up @@ -403,9 +403,9 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
var _graph$beforeMove, _graph$moved;

if (!graph.move) return;
(_graph$beforeMove = graph.beforeMove) === null || _graph$beforeMove === void 0 ? void 0 : _graph$beforeMove.call(graph, e);
(_graph$beforeMove = graph.beforeMove) === null || _graph$beforeMove === void 0 ? void 0 : _graph$beforeMove.call(graph, e, graph);
graph.move(e);
(_graph$moved = graph.moved) === null || _graph$moved === void 0 ? void 0 : _graph$moved.call(graph, e);
(_graph$moved = graph.moved) === null || _graph$moved === void 0 ? void 0 : _graph$moved.call(graph, e, graph);
graph.setGraphCenter(e);
}
}, {
Expand Down
16 changes: 8 additions & 8 deletions es/core/graph.class.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,35 @@ export default class Graph<Shape = any> {
/**
* @description Life Cycle when graph before add
*/
beforeAdd?: () => any;
beforeAdd?: (graph: Graph) => any;
/**
* @description Life Cycle when graph added
*/
added?: () => any;
added?: (graph: Graph) => any;
/**
* @description Life Cycle when graph before draw
*/
beforeDraw?: () => any;
beforeDraw?: (graph: Graph) => any;
/**
* @description Life Cycle when graph drawed
*/
drawed?: () => any;
drawed?: (graph: Graph) => any;
/**
* @description Life Cycle when graph before move
*/
beforeMove?: (e: MouseEvent) => any;
beforeMove?: (e: MouseEvent, graph: Graph) => any;
/**
* @description Life Cycle when graph moved
*/
moved?: (e: MouseEvent) => any;
moved?: (e: MouseEvent, graph: Graph) => any;
/**
* @description Life Cycle when graph before delete
*/
beforeDelete?: () => any;
beforeDelete?: (graph: Graph) => any;
/**
* @description Life Cycle when graph deleted
*/
deleted?: () => any;
deleted?: (graph: Graph) => any;
constructor(config: GraphConfig<Shape>);
static mergeDefaultShape<Shape>(defaultShape: Shape, config: GraphConfig<Partial<Shape>>, checker?: (config: GraphConfig<Shape>) => void): GraphConfig<Shape>;
private checkRender;
Expand Down
2 changes: 1 addition & 1 deletion es/index.mjs

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions es/types/core/graph.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StyleConfig } from './style';
import { EaseCurve } from '@jiaminghi/transition/types/types/core/index';
import { RgbaValue } from '@jiaminghi/color/types/types';
import { Graph } from '../..';
export declare type HoverRect = [number, number, number, number];
export declare type Point = [number, number];
export declare type HoverCheck = (point: Point) => boolean;
Expand Down Expand Up @@ -85,27 +86,35 @@ export declare type GraphConfig<Shape = any> = {
/**
* @description Life cycle beforeAdd
*/
beforeAdd?: () => any;
beforeAdd?: (graph: Graph) => any;
/**
* @description Life cycle added
*/
added?: () => any;
added?: (graph: Graph) => any;
/**
* Life Cycle when graph before draw
*/
beforeDraw?: () => any;
beforeDraw?: (graph: Graph) => any;
/**
* Life Cycle when graph drawed
*/
drawed?: () => any;
drawed?: (graph: Graph) => any;
/**
* Life Cycle when graph before move
*/
beforeMove?: (e: MouseEvent) => any;
beforeMove?: (e: MouseEvent, graph: Graph) => any;
/**
* @description Life Cycle when graph moved
*/
moved?: (e: MouseEvent) => any;
moved?: (e: MouseEvent, graph: Graph) => any;
/**
* @description Life Cycle when graph before delete
*/
beforeDelete?: (graph: Graph) => any;
/**
* @description Life Cycle when graph deleted
*/
deleted?: (graph: Graph) => any;
};
export declare enum Status {
STATIC = "STATIC",
Expand Down
16 changes: 8 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ var CRender = /** @class */ (function () {
CRender.prototype.drawGraphProcessor = function (graph) {
var _a, _b;
graph.style.setCtx(this);
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph);
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
graph.draw();
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph);
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
graph.style.restoreCtx(this);
};
CRender.prototype.add = function (graph, wait) {
Expand All @@ -343,12 +343,12 @@ var CRender = /** @class */ (function () {
};
CRender.prototype.graphAddProcessor = function (graph) {
var _a, _b;
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph);
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
graph.render = this;
graph.setGraphCenter();
this.graphs.push(graph);
this.sortGraphsByIndex();
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph);
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
};
CRender.prototype.delGraph = function (graph, wait) {
if (wait === void 0) { wait = false; }
Expand All @@ -367,9 +367,9 @@ var CRender = /** @class */ (function () {
var index = graphs.findIndex(function (_) { return _ === graph; });
if (index === -1)
return;
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph);
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
graphs.splice(index, 1);
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph);
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
};
CRender.prototype.delAllGraph = function () {
this.delGraph(this.graphs);
Expand Down Expand Up @@ -493,9 +493,9 @@ var CRender = /** @class */ (function () {
var _a, _b;
if (!graph.move)
return;
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e);
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e, graph);
graph.move(e);
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e);
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e, graph);
graph.setGraphCenter(e);
};
CRender.prototype.graphHoverCheckProcessor = function (graph, point) {
Expand Down
16 changes: 8 additions & 8 deletions src/core/crender.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ export default class CRender {
private drawGraphProcessor(graph: Graph): void {
graph.style.setCtx(this)

graph.beforeDraw?.()
graph.beforeDraw?.(graph)

graph.draw()

graph.drawed?.()
graph.drawed?.(graph)

graph.style.restoreCtx(this)
}
Expand All @@ -166,15 +166,15 @@ export default class CRender {

@bound
private graphAddProcessor(graph: Graph): void {
graph.beforeAdd?.()
graph.beforeAdd?.(graph)

graph.render = this
graph.setGraphCenter()

this.graphs.push(graph)
this.sortGraphsByIndex()

graph.added?.()
graph.added?.(graph)
}

delGraph(graph: Graph | Graph[], wait: boolean = false): void {
Expand All @@ -194,11 +194,11 @@ export default class CRender {
const index = graphs.findIndex(_ => _ === graph)
if (index === -1) return

graph.beforeDelete?.()
graph.beforeDelete?.(graph)

graphs.splice(index, 1)

graph.deleted?.()
graph.deleted?.(graph)
}

delAllGraph(): void {
Expand Down Expand Up @@ -358,11 +358,11 @@ export default class CRender {
private graphMoveProcessor(graph: Graph, e: MouseEvent): void {
if (!graph.move) return

graph.beforeMove?.(e)
graph.beforeMove?.(e, graph)

graph.move(e)

graph.moved?.(e)
graph.moved?.(e, graph)

graph.setGraphCenter(e)
}
Expand Down
Loading

0 comments on commit 99edd9c

Please sign in to comment.