Skip to content

Commit 99edd9c

Browse files
committed
Life Cycle: Add instance parameters
1 parent ff17ae8 commit 99edd9c

File tree

11 files changed

+90
-70
lines changed

11 files changed

+90
-70
lines changed

dist/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ var CRender = /** @class */ (function () {
321321
CRender.prototype.drawGraphProcessor = function (graph) {
322322
var _a, _b;
323323
graph.style.setCtx(this);
324-
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph);
324+
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
325325
graph.draw();
326-
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph);
326+
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
327327
graph.style.restoreCtx(this);
328328
};
329329
CRender.prototype.add = function (graph, wait) {
@@ -339,12 +339,12 @@ var CRender = /** @class */ (function () {
339339
};
340340
CRender.prototype.graphAddProcessor = function (graph) {
341341
var _a, _b;
342-
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph);
342+
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
343343
graph.render = this;
344344
graph.setGraphCenter();
345345
this.graphs.push(graph);
346346
this.sortGraphsByIndex();
347-
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph);
347+
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
348348
};
349349
CRender.prototype.delGraph = function (graph, wait) {
350350
if (wait === void 0) { wait = false; }
@@ -363,9 +363,9 @@ var CRender = /** @class */ (function () {
363363
var index = graphs.findIndex(function (_) { return _ === graph; });
364364
if (index === -1)
365365
return;
366-
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph);
366+
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
367367
graphs.splice(index, 1);
368-
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph);
368+
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
369369
};
370370
CRender.prototype.delAllGraph = function () {
371371
this.delGraph(this.graphs);
@@ -489,9 +489,9 @@ var CRender = /** @class */ (function () {
489489
var _a, _b;
490490
if (!graph.move)
491491
return;
492-
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e);
492+
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e, graph);
493493
graph.move(e);
494-
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e);
494+
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e, graph);
495495
graph.setGraphCenter(e);
496496
};
497497
CRender.prototype.graphHoverCheckProcessor = function (graph, point) {

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/guide/graph.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ clone(add: boolean = true): this {
300300
/**
301301
* @description 图形添加前被调用
302302
*/
303-
beforeAdd?: () => any
303+
beforeAdd?: (graph: Graph) => any
304304
```
305305

306306
### added
@@ -309,7 +309,7 @@ beforeAdd?: () => any
309309
/**
310310
* @description 图形添加后被调用
311311
*/
312-
added?: () => any
312+
added?: (graph: Graph) => any
313313
```
314314

315315
### beforeDraw
@@ -318,7 +318,7 @@ added?: () => any
318318
/**
319319
* @description 图形渲染前被调用
320320
*/
321-
beforeDraw?: () => any
321+
beforeDraw?: (graph: Graph) => any
322322
```
323323

324324
### drawed
@@ -327,7 +327,7 @@ beforeDraw?: () => any
327327
/**
328328
* @description 图形渲染后被调用
329329
*/
330-
drawed?: () => any
330+
drawed?: (graph: Graph) => any
331331
```
332332

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

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

353353
### beforeDelete
@@ -356,7 +356,7 @@ moved?: (e: MouseEvent) => any
356356
/**
357357
* @description 图形删除前被调用
358358
*/
359-
beforeDelete?: () => any
359+
beforeDelete?: (graph: Graph) => any
360360
```
361361

362362
### deleted
@@ -365,7 +365,7 @@ beforeDelete?: () => any
365365
/**
366366
* @description 图形删除后被调用
367367
*/
368-
deleted?: () => any
368+
deleted?: (graph: Graph) => any
369369
```
370370

371371
## 覆盖默认行为

es/core/crender.class.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
173173
var _graph$beforeDraw, _graph$drawed;
174174

175175
graph.style.setCtx(this);
176-
(_graph$beforeDraw = graph.beforeDraw) === null || _graph$beforeDraw === void 0 ? void 0 : _graph$beforeDraw.call(graph);
176+
(_graph$beforeDraw = graph.beforeDraw) === null || _graph$beforeDraw === void 0 ? void 0 : _graph$beforeDraw.call(graph, graph);
177177
graph.draw();
178-
(_graph$drawed = graph.drawed) === null || _graph$drawed === void 0 ? void 0 : _graph$drawed.call(graph);
178+
(_graph$drawed = graph.drawed) === null || _graph$drawed === void 0 ? void 0 : _graph$drawed.call(graph, graph);
179179
graph.style.restoreCtx(this);
180180
}
181181
}, {
@@ -196,12 +196,12 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
196196
value: function graphAddProcessor(graph) {
197197
var _graph$beforeAdd, _graph$added;
198198

199-
(_graph$beforeAdd = graph.beforeAdd) === null || _graph$beforeAdd === void 0 ? void 0 : _graph$beforeAdd.call(graph);
199+
(_graph$beforeAdd = graph.beforeAdd) === null || _graph$beforeAdd === void 0 ? void 0 : _graph$beforeAdd.call(graph, graph);
200200
graph.render = this;
201201
graph.setGraphCenter();
202202
this.graphs.push(graph);
203203
this.sortGraphsByIndex();
204-
(_graph$added = graph.added) === null || _graph$added === void 0 ? void 0 : _graph$added.call(graph);
204+
(_graph$added = graph.added) === null || _graph$added === void 0 ? void 0 : _graph$added.call(graph, graph);
205205
}
206206
}, {
207207
key: "delGraph",
@@ -228,9 +228,9 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
228228
return _ === graph;
229229
});
230230
if (index === -1) return;
231-
(_graph$beforeDelete = graph.beforeDelete) === null || _graph$beforeDelete === void 0 ? void 0 : _graph$beforeDelete.call(graph);
231+
(_graph$beforeDelete = graph.beforeDelete) === null || _graph$beforeDelete === void 0 ? void 0 : _graph$beforeDelete.call(graph, graph);
232232
graphs.splice(index, 1);
233-
(_graph$deleted = graph.deleted) === null || _graph$deleted === void 0 ? void 0 : _graph$deleted.call(graph);
233+
(_graph$deleted = graph.deleted) === null || _graph$deleted === void 0 ? void 0 : _graph$deleted.call(graph, graph);
234234
}
235235
}, {
236236
key: "delAllGraph",
@@ -403,9 +403,9 @@ var CRender = (_class = (_temp = /*#__PURE__*/function () {
403403
var _graph$beforeMove, _graph$moved;
404404

405405
if (!graph.move) return;
406-
(_graph$beforeMove = graph.beforeMove) === null || _graph$beforeMove === void 0 ? void 0 : _graph$beforeMove.call(graph, e);
406+
(_graph$beforeMove = graph.beforeMove) === null || _graph$beforeMove === void 0 ? void 0 : _graph$beforeMove.call(graph, e, graph);
407407
graph.move(e);
408-
(_graph$moved = graph.moved) === null || _graph$moved === void 0 ? void 0 : _graph$moved.call(graph, e);
408+
(_graph$moved = graph.moved) === null || _graph$moved === void 0 ? void 0 : _graph$moved.call(graph, e, graph);
409409
graph.setGraphCenter(e);
410410
}
411411
}, {

es/core/graph.class.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,35 @@ export default class Graph<Shape = any> {
100100
/**
101101
* @description Life Cycle when graph before add
102102
*/
103-
beforeAdd?: () => any;
103+
beforeAdd?: (graph: Graph) => any;
104104
/**
105105
* @description Life Cycle when graph added
106106
*/
107-
added?: () => any;
107+
added?: (graph: Graph) => any;
108108
/**
109109
* @description Life Cycle when graph before draw
110110
*/
111-
beforeDraw?: () => any;
111+
beforeDraw?: (graph: Graph) => any;
112112
/**
113113
* @description Life Cycle when graph drawed
114114
*/
115-
drawed?: () => any;
115+
drawed?: (graph: Graph) => any;
116116
/**
117117
* @description Life Cycle when graph before move
118118
*/
119-
beforeMove?: (e: MouseEvent) => any;
119+
beforeMove?: (e: MouseEvent, graph: Graph) => any;
120120
/**
121121
* @description Life Cycle when graph moved
122122
*/
123-
moved?: (e: MouseEvent) => any;
123+
moved?: (e: MouseEvent, graph: Graph) => any;
124124
/**
125125
* @description Life Cycle when graph before delete
126126
*/
127-
beforeDelete?: () => any;
127+
beforeDelete?: (graph: Graph) => any;
128128
/**
129129
* @description Life Cycle when graph deleted
130130
*/
131-
deleted?: () => any;
131+
deleted?: (graph: Graph) => any;
132132
constructor(config: GraphConfig<Shape>);
133133
static mergeDefaultShape<Shape>(defaultShape: Shape, config: GraphConfig<Partial<Shape>>, checker?: (config: GraphConfig<Shape>) => void): GraphConfig<Shape>;
134134
private checkRender;

es/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

es/types/core/graph.d.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { StyleConfig } from './style';
22
import { EaseCurve } from '@jiaminghi/transition/types/types/core/index';
33
import { RgbaValue } from '@jiaminghi/color/types/types';
4+
import { Graph } from '../..';
45
export declare type HoverRect = [number, number, number, number];
56
export declare type Point = [number, number];
67
export declare type HoverCheck = (point: Point) => boolean;
@@ -85,27 +86,35 @@ export declare type GraphConfig<Shape = any> = {
8586
/**
8687
* @description Life cycle beforeAdd
8788
*/
88-
beforeAdd?: () => any;
89+
beforeAdd?: (graph: Graph) => any;
8990
/**
9091
* @description Life cycle added
9192
*/
92-
added?: () => any;
93+
added?: (graph: Graph) => any;
9394
/**
9495
* Life Cycle when graph before draw
9596
*/
96-
beforeDraw?: () => any;
97+
beforeDraw?: (graph: Graph) => any;
9798
/**
9899
* Life Cycle when graph drawed
99100
*/
100-
drawed?: () => any;
101+
drawed?: (graph: Graph) => any;
101102
/**
102103
* Life Cycle when graph before move
103104
*/
104-
beforeMove?: (e: MouseEvent) => any;
105+
beforeMove?: (e: MouseEvent, graph: Graph) => any;
105106
/**
106107
* @description Life Cycle when graph moved
107108
*/
108-
moved?: (e: MouseEvent) => any;
109+
moved?: (e: MouseEvent, graph: Graph) => any;
110+
/**
111+
* @description Life Cycle when graph before delete
112+
*/
113+
beforeDelete?: (graph: Graph) => any;
114+
/**
115+
* @description Life Cycle when graph deleted
116+
*/
117+
deleted?: (graph: Graph) => any;
109118
};
110119
export declare enum Status {
111120
STATIC = "STATIC",

lib/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ var CRender = /** @class */ (function () {
325325
CRender.prototype.drawGraphProcessor = function (graph) {
326326
var _a, _b;
327327
graph.style.setCtx(this);
328-
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph);
328+
(_a = graph.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
329329
graph.draw();
330-
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph);
330+
(_b = graph.drawed) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
331331
graph.style.restoreCtx(this);
332332
};
333333
CRender.prototype.add = function (graph, wait) {
@@ -343,12 +343,12 @@ var CRender = /** @class */ (function () {
343343
};
344344
CRender.prototype.graphAddProcessor = function (graph) {
345345
var _a, _b;
346-
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph);
346+
(_a = graph.beforeAdd) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
347347
graph.render = this;
348348
graph.setGraphCenter();
349349
this.graphs.push(graph);
350350
this.sortGraphsByIndex();
351-
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph);
351+
(_b = graph.added) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
352352
};
353353
CRender.prototype.delGraph = function (graph, wait) {
354354
if (wait === void 0) { wait = false; }
@@ -367,9 +367,9 @@ var CRender = /** @class */ (function () {
367367
var index = graphs.findIndex(function (_) { return _ === graph; });
368368
if (index === -1)
369369
return;
370-
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph);
370+
(_a = graph.beforeDelete) === null || _a === void 0 ? void 0 : _a.call(graph, graph);
371371
graphs.splice(index, 1);
372-
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph);
372+
(_b = graph.deleted) === null || _b === void 0 ? void 0 : _b.call(graph, graph);
373373
};
374374
CRender.prototype.delAllGraph = function () {
375375
this.delGraph(this.graphs);
@@ -493,9 +493,9 @@ var CRender = /** @class */ (function () {
493493
var _a, _b;
494494
if (!graph.move)
495495
return;
496-
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e);
496+
(_a = graph.beforeMove) === null || _a === void 0 ? void 0 : _a.call(graph, e, graph);
497497
graph.move(e);
498-
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e);
498+
(_b = graph.moved) === null || _b === void 0 ? void 0 : _b.call(graph, e, graph);
499499
graph.setGraphCenter(e);
500500
};
501501
CRender.prototype.graphHoverCheckProcessor = function (graph, point) {

src/core/crender.class.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ export default class CRender {
145145
private drawGraphProcessor(graph: Graph): void {
146146
graph.style.setCtx(this)
147147

148-
graph.beforeDraw?.()
148+
graph.beforeDraw?.(graph)
149149

150150
graph.draw()
151151

152-
graph.drawed?.()
152+
graph.drawed?.(graph)
153153

154154
graph.style.restoreCtx(this)
155155
}
@@ -166,15 +166,15 @@ export default class CRender {
166166

167167
@bound
168168
private graphAddProcessor(graph: Graph): void {
169-
graph.beforeAdd?.()
169+
graph.beforeAdd?.(graph)
170170

171171
graph.render = this
172172
graph.setGraphCenter()
173173

174174
this.graphs.push(graph)
175175
this.sortGraphsByIndex()
176176

177-
graph.added?.()
177+
graph.added?.(graph)
178178
}
179179

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

197-
graph.beforeDelete?.()
197+
graph.beforeDelete?.(graph)
198198

199199
graphs.splice(index, 1)
200200

201-
graph.deleted?.()
201+
graph.deleted?.(graph)
202202
}
203203

204204
delAllGraph(): void {
@@ -358,11 +358,11 @@ export default class CRender {
358358
private graphMoveProcessor(graph: Graph, e: MouseEvent): void {
359359
if (!graph.move) return
360360

361-
graph.beforeMove?.(e)
361+
graph.beforeMove?.(e, graph)
362362

363363
graph.move(e)
364364

365-
graph.moved?.(e)
365+
graph.moved?.(e, graph)
366366

367367
graph.setGraphCenter(e)
368368
}

0 commit comments

Comments
 (0)