dcim-topology2d 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. package/chart-diagram/src/echarts/index.js +3 -6
  2. package/core/index.d.ts +1 -0
  3. package/core/index.js +1 -0
  4. package/core/src/activeLayer.d.ts +2 -10
  5. package/core/src/activeLayer.js +42 -41
  6. package/core/src/animateLayer.d.ts +3 -7
  7. package/core/src/animateLayer.js +10 -12
  8. package/core/src/calling.d.ts +1 -4
  9. package/core/src/calling.js +38 -41
  10. package/core/src/canvas.d.ts +1 -6
  11. package/core/src/canvas.js +17 -18
  12. package/core/src/common.d.ts +5 -5
  13. package/core/src/common.js +146 -109
  14. package/core/src/core.d.ts +3 -4
  15. package/core/src/core.js +222 -251
  16. package/core/src/divLayer.d.ts +2 -7
  17. package/core/src/divLayer.js +25 -25
  18. package/core/src/healps/changeData.js +20 -3
  19. package/core/src/hoverLayer.d.ts +2 -9
  20. package/core/src/hoverLayer.js +31 -34
  21. package/core/src/models/index.d.ts +0 -1
  22. package/core/src/models/index.js +0 -1
  23. package/core/src/offscreen.d.ts +1 -4
  24. package/core/src/offscreen.js +10 -8
  25. package/core/src/options.js +1 -0
  26. package/core/src/preview.d.ts +1 -13
  27. package/core/src/preview.js +26 -27
  28. package/core/src/renderLayer.d.ts +1 -3
  29. package/core/src/renderLayer.js +26 -31
  30. package/core/src/store/common.d.ts +9 -0
  31. package/core/src/store/common.js +5 -0
  32. package/core/src/store/data.d.ts +126 -0
  33. package/core/src/store/data.js +80 -0
  34. package/core/src/store/index.d.ts +2 -0
  35. package/core/src/store/index.js +2 -0
  36. package/core/src/utils/conversion.d.ts +7 -0
  37. package/core/src/utils/conversion.js +54 -0
  38. package/core/src/utils/dom.d.ts +4 -3
  39. package/package.json +1 -1
  40. package/core/src/models/data.d.ts +0 -26
  41. package/core/src/models/data.js +0 -77
  42. package/core/src/models/data.js.map +0 -1
  43. package/core/src/mqtt.d.ts +0 -14
  44. package/core/src/mqtt.js +0 -82
  45. package/core/src/mqtt.js.map +0 -1
  46. package/core/src/socket.d.ts +0 -10
  47. package/core/src/socket.js +0 -51
  48. package/core/src/socket.js.map +0 -1
@@ -72,17 +72,14 @@ export function echarts(ctx, node) {
72
72
  option.yAxis[0].splitLine = node.appearance.splitLine;
73
73
 
74
74
  }else if(node.appearance.type === 'gauge') {
75
- const pointerColor = node.appearance.pointerColor;
76
- node.appearance.pointer.length = `${node.appearance.pointer.length}%`;
77
75
  option.series[0].min = node.appearance.min;
78
76
  option.series[0].max = node.appearance.max;
79
- option.series[0].itemStyle.color = pointerColor ? pointerColor : node.appearance.axisLabel.color;
80
77
  option.series[0].splitNumber = node.appearance.splitNumber;
81
78
  option.series[0].pointer = node.appearance.pointer;
82
79
  option.series[0].axisLabel = node.appearance.axisLabel;
83
80
  option.series[0].axisLine.lineStyle = node.appearance.axisLine.lineStyle;
84
- option.series[0].detail = node.appearance.detail;
85
- //option.series[0].data = node.appearance.data;
81
+ if(node.appearance.detail) option.series[0].detail = node.appearance.detail;
82
+ if(node.appearance.data) option.series[0].data = node.appearance.data;
86
83
  if(option.isGaugeLinear) {
87
84
  option.series[0].axisLine.lineStyle.color = [
88
85
  [1, new echarts.graphic.LinearGradient(0, 0, 1, 0, option.linearColors)]
@@ -94,7 +91,7 @@ export function echarts(ctx, node) {
94
91
  }
95
92
  option.title = node.appearance.title;
96
93
  option.backgroundColor = node.appearance.backgroundColor;
97
- echartsData[node.id].chart.clear();
94
+ if(window.location.pathname.includes('workspace')) echartsData[node.id].chart.clear();
98
95
  echartsData[node.id].chart.setOption(option);
99
96
  echartsData[node.id].chart.resize();
100
97
  node.elementRendered = true;
package/core/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './src/utils';
6
6
  export * from './src/models';
7
7
  export * from './src/middles';
8
8
  export * from './src/healps';
9
+ export * from './src/store';
package/core/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './src/utils';
6
6
  export * from './src/models';
7
7
  export * from './src/middles';
8
8
  export * from './src/healps';
9
+ export * from './src/store';
9
10
  //# sourceMappingURL=index.js.map
10
11
  import axios from 'axios'
11
12
  if(axios.defaults.headers.common) axios.defaults.headers.common['Authorization'] = getToken();
@@ -1,15 +1,7 @@
1
- import { Options } from './options';
2
- import { Pen } from './models/pen';
3
- import { Node } from './models/node';
4
- import { Line } from './models/line';
5
- import { Rect } from './models/rect';
6
- import { Point } from './models/point';
7
- import { TopologyData } from './models/data';
1
+ import { Pen, Node, Line, Rect, Point } from './models';
8
2
  import { Layer } from './layer';
9
3
  import { Topology } from './core';
10
4
  export declare class ActiveLayer extends Layer {
11
- options: Options;
12
- protected data: TopologyData;
13
5
  rotateCPs: Point[];
14
6
  sizeCPs: Point[];
15
7
  rect: Rect;
@@ -26,7 +18,7 @@ export declare class ActiveLayer extends Layer {
26
18
  dockWatchers: Point[];
27
19
  topology: Topology;
28
20
  rotating: boolean;
29
- constructor(options: Options, TID: String);
21
+ constructor(TID: String);
30
22
  calcControlPoints(): void;
31
23
  locked(): boolean;
32
24
  getPoints(): Point[];
@@ -1,8 +1,8 @@
1
1
  var __extends = (this && this.__extends) || (function () {
2
2
  var extendStatics = function (d, b) {
3
3
  extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
6
  return extendStatics(d, b);
7
7
  };
8
8
  return function (d, b) {
@@ -12,22 +12,16 @@ var __extends = (this && this.__extends) || (function () {
12
12
  };
13
13
  })();
14
14
  import { Store } from 'le5le-store';
15
- import { PenType } from './models/pen';
16
- import { Node } from './models/node';
17
- import { Line } from './models/line';
18
- import { Rect } from './models/rect';
19
- import { Point } from './models/point';
20
- import { Lock } from './models/status';
15
+ import { PenType, Node, Line, Rect, Point, Lock } from './models';
21
16
  import { drawLineFns } from './middles';
22
17
  import { getBezierPoint } from './middles/lines/curve';
23
18
  import { Layer } from './layer';
24
19
  import { flatNodes } from './utils';
20
+ import { commonStore } from './store'
25
21
  var ActiveLayer = /** @class */ (function (_super) {
26
22
  __extends(ActiveLayer, _super);
27
- function ActiveLayer(options, TID) {
28
- if (options === void 0) { options = {}; }
23
+ function ActiveLayer(TID) {
29
24
  var _this = _super.call(this, TID) || this;
30
- _this.options = options;
31
25
  _this.rotateCPs = [];
32
26
  _this.sizeCPs = [];
33
27
  _this.pens = [];
@@ -42,11 +36,11 @@ var ActiveLayer = /** @class */ (function (_super) {
42
36
  // nodes移动时,停靠点的参考位置
43
37
  _this.dockWatchers = [];
44
38
  _this.rotating = false;
45
- _this.data = Store.get(_this.generateStoreKey('topology-data'));
46
39
  Store.set(_this.generateStoreKey('LT:ActiveLayer'), _this);
47
40
  return _this;
48
41
  }
49
42
  ActiveLayer.prototype.calcControlPoints = function () {
43
+ var globalStore = commonStore[this.TID];
50
44
  if (this.pens.length === 1 && this.pens[0] instanceof Node) {
51
45
  this.rect = this.pens[0].rect;
52
46
  this.sizeCPs = this.pens[0].rect.toPoints();
@@ -74,7 +68,7 @@ var ActiveLayer = /** @class */ (function (_super) {
74
68
  }
75
69
  }
76
70
  }
77
- if (this.options.hideRotateCP || this.pens[0].hideRotateCP) {
71
+ if (globalStore.options.hideRotateCP || this.pens[0].hideRotateCP) {
78
72
  this.rotateCPs = [new Point(-1000, -1000), new Point(-1000, -1000)];
79
73
  }
80
74
  return;
@@ -102,9 +96,10 @@ var ActiveLayer = /** @class */ (function (_super) {
102
96
  this.rect = new Rect(x1, y1, x2 - x1, y2 - y1);
103
97
  this.sizeCPs = [new Point(x1, y1), new Point(x2, y1), new Point(x2, y2), new Point(x1, y2)];
104
98
  this.rotateCPs = [new Point(x1 + (x2 - x1) / 2, y1 - 35), new Point(x1 + (x2 - x1) / 2, y1)];
105
- if (this.options.hideRotateCP) {
99
+ if (globalStore.options.hideRotateCP) {
106
100
  this.rotateCPs = [new Point(-1000, -1000), new Point(-1000, -1000)];
107
101
  }
102
+ globalStore = null;
108
103
  };
109
104
  ActiveLayer.prototype.locked = function () {
110
105
  for (var _i = 0, _a = this.pens; _i < _a.length; _i++) {
@@ -192,10 +187,10 @@ var ActiveLayer = /** @class */ (function (_super) {
192
187
  }
193
188
  var offsetX = p2.x - p1.x;
194
189
  var offsetY = p2.y - p1.y;
195
- if (this.options.onlySizeX) {
190
+ if (commonStore[this.TID].options.onlySizeX) {
196
191
  offsetY = 0;
197
192
  }
198
- if (this.options.onlySizeY) {
193
+ if (commonStore[this.TID].options.onlySizeY) {
199
194
  offsetX = 0;
200
195
  }
201
196
  var lines = [];
@@ -283,6 +278,7 @@ var ActiveLayer = /** @class */ (function (_super) {
283
278
  if (this.nodeRects.length !== this.pens.length) {
284
279
  return;
285
280
  }
281
+ var globalStore = commonStore[this.TID];
286
282
  var i = 0;
287
283
  for (var _i = 0, _a = this.pens; _i < _a.length; _i++) {
288
284
  var item = _a[_i];
@@ -301,7 +297,7 @@ var ActiveLayer = /** @class */ (function (_super) {
301
297
  item.calcChildrenRect();
302
298
  if (item.parentId && !item.locked) {
303
299
  var parent_1 = void 0;
304
- for (var _c = 0, _d = this.data.pens; _c < _d.length; _c++) {
300
+ for (var _c = 0, _d = globalStore.data.pens; _c < _d.length; _c++) {
305
301
  var n = _d[_c];
306
302
  if (n.id === item.parentId) {
307
303
  parent_1 = n;
@@ -321,7 +317,7 @@ var ActiveLayer = /** @class */ (function (_super) {
321
317
  var offsetX_1 = this.nodeRects[i].x + x - item.from.x;
322
318
  var offsetY_1 = this.nodeRects[i].y + y - item.from.y;
323
319
  if (item.parentId) {
324
- var items = find(item.parentId, this.data.pens);
320
+ var items = find(item.parentId, globalStore.data.pens);
325
321
  items.forEach(function (l) {
326
322
  l.translate(offsetX_1, offsetY_1);
327
323
  });
@@ -338,7 +334,7 @@ var ActiveLayer = /** @class */ (function (_super) {
338
334
  ActiveLayer.prototype.getLinesOfNode = function (node) {
339
335
  var result = [];
340
336
  var nodesLines = flatNodes([node]);
341
- for (var _i = 0, _a = this.data.pens; _i < _a.length; _i++) {
337
+ for (var _i = 0, _a = commonStore[this.TID].data.pens; _i < _a.length; _i++) {
342
338
  var pen = _a[_i];
343
339
  if (!(pen instanceof Line)) {
344
340
  continue;
@@ -365,9 +361,10 @@ var ActiveLayer = /** @class */ (function (_super) {
365
361
  if (!pens) {
366
362
  pens = this.pens;
367
363
  }
364
+ var globalStore = commonStore[this.TID];
368
365
  var nodesLines = flatNodes(pens);
369
366
  var lines = [];
370
- nodesLines.lines.push.apply(nodesLines.lines, this.data.pens.filter(function (pen) { return pen.type; }));
367
+ nodesLines.lines.push.apply(nodesLines.lines, globalStore.data.pens.filter(function (pen) { return pen.type; }));
371
368
  for (var _i = 0, _a = nodesLines.lines; _i < _a.length; _i++) {
372
369
  var line = _a[_i];
373
370
  for (var _b = 0, _c = nodesLines.nodes; _b < _c.length; _b++) {
@@ -383,7 +380,7 @@ var ActiveLayer = /** @class */ (function (_super) {
383
380
  line.to.y = item.rotatedAnchors[line.to.anchorIndex].y;
384
381
  ++cnt;
385
382
  }
386
- if (cnt && !this.data.manualCps) {
383
+ if (cnt && !globalStore.data.manualCps) {
387
384
  line.calcControlPoints();
388
385
  }
389
386
  line.textRect = null;
@@ -392,6 +389,7 @@ var ActiveLayer = /** @class */ (function (_super) {
392
389
  }
393
390
  }
394
391
  Store.set(this.generateStoreKey('LT:updateLines'), lines);
392
+ globalStore = null;
395
393
  };
396
394
  ActiveLayer.prototype.offsetRotate = function (angle) {
397
395
  this.rotating = true;
@@ -492,7 +490,9 @@ var ActiveLayer = /** @class */ (function (_super) {
492
490
  };
493
491
  ActiveLayer.prototype.render = function (ctx) {
494
492
  var _this = this;
495
- if (this.data.locked > Lock.Readonly) {
493
+ if(!commonStore || !commonStore[_this.TID]) return;
494
+ var globalStore = commonStore[_this.TID];
495
+ if (globalStore.data.locked > Lock.Readonly) {
496
496
  return;
497
497
  }
498
498
 
@@ -508,7 +508,7 @@ var ActiveLayer = /** @class */ (function (_super) {
508
508
  this.calcControlPoints();
509
509
  }
510
510
  ctx.save();
511
- ctx.strokeStyle = this.options.activeColor;
511
+ ctx.strokeStyle = globalStore.options.activeColor;
512
512
  ctx.fillStyle = '#fff';
513
513
  ctx.lineWidth = 1;
514
514
  var TID = this.TID;
@@ -528,7 +528,7 @@ var ActiveLayer = /** @class */ (function (_super) {
528
528
  tmp.strokeStyle = '#ffffff';
529
529
  tmp.lineWidth += 2;
530
530
  tmp.render(ctx);
531
- tmp.strokeStyle = this.options.activeColor;
531
+ tmp.strokeStyle = globalStore.options.activeColor;
532
532
  tmp.lineWidth -= 2;
533
533
  }
534
534
  }
@@ -543,11 +543,11 @@ var ActiveLayer = /** @class */ (function (_super) {
543
543
  bk.strokeStyle = '#ffffff';
544
544
  bk.render(ctx);
545
545
  }
546
- tmp.strokeStyle = this.options.activeColor;
547
- tmp.fromArrowColor = this.options.activeColor;
548
- tmp.toArrowColor = this.options.activeColor;
546
+ tmp.strokeStyle = globalStore.options.activeColor;
547
+ tmp.fromArrowColor = globalStore.options.activeColor;
548
+ tmp.toArrowColor = globalStore.options.activeColor;
549
549
  tmp.render(ctx);
550
- if (!this.data.locked && !item.locked) {
550
+ if (!globalStore.data.locked && !item.locked) {
551
551
  drawLineFns[item.name].drawControlPointsFn(ctx, item);
552
552
  }
553
553
  }
@@ -573,7 +573,7 @@ var ActiveLayer = /** @class */ (function (_super) {
573
573
  ctx.closePath();
574
574
  ctx.stroke();
575
575
  ctx.restore();
576
- if (this.data.locked || this.locked()) {
576
+ if (globalStore.data.locked || this.locked()) {
577
577
  ctx.restore();
578
578
  return;
579
579
  }
@@ -589,7 +589,7 @@ var ActiveLayer = /** @class */ (function (_super) {
589
589
  ctx.fill();
590
590
  ctx.stroke();
591
591
  // Draw size control points.绘制拖拽框四角的点
592
- if (!this.options.hideSizeCP && (this.pens.length > 1 || !this.pens[0].hideSizeCP)) {
592
+ if (!globalStore.options.hideSizeCP && (this.pens.length > 1 || !this.pens[0].hideSizeCP)) {
593
593
  ctx.lineWidth = 1;
594
594
  for (var _b = 0, _c = this.sizeCPs; _b < _c.length; _b++) {
595
595
  var item = _c[_b];
@@ -606,6 +606,7 @@ var ActiveLayer = /** @class */ (function (_super) {
606
606
  }
607
607
  }
608
608
  ctx.restore();
609
+ globalStore = null;
609
610
  };
610
611
  ActiveLayer.prototype.getDockWatchers = function () {
611
612
  if (this.pens.length === 1) {
@@ -622,7 +623,7 @@ var ActiveLayer = /** @class */ (function (_super) {
622
623
  ActiveLayer.prototype.handleArbitrayGraphSize = function (type,item, offsetX, offsetY, l, sizeX, sizeY, nodeRectsCircles) {
623
624
  if(item.name !== 'arbitraryGraph') return
624
625
 
625
- switch (type) {
626
+ switch (type) {
626
627
 
627
628
  case 0:
628
629
 
@@ -634,7 +635,7 @@ var ActiveLayer = /** @class */ (function (_super) {
634
635
 
635
636
  }
636
637
 
637
- break;
638
+ break;
638
639
 
639
640
  case 1:
640
641
 
@@ -646,19 +647,19 @@ var ActiveLayer = /** @class */ (function (_super) {
646
647
 
647
648
  }
648
649
 
649
- break;
650
+ break;
650
651
 
651
652
  case 2:
652
653
 
653
- for(let c=0, length = item.rect.circles.length; c<length; c++ ) {
654
+ for(let c=0, length = item.rect.circles.length; c<length; c++ ) {
655
+
656
+ item.rect.circles[c].x=item.rect.circles[c].x*sizeX+item.rect.x*(1-sizeX);
654
657
 
655
- item.rect.circles[c].x=item.rect.circles[c].x*sizeX+item.rect.x*(1-sizeX);
656
-
657
- item.rect.circles[c].y=item.rect.circles[c].y*sizeY+item.rect.y*(1-sizeY);
658
+ item.rect.circles[c].y=item.rect.circles[c].y*sizeY+item.rect.y*(1-sizeY);
658
659
 
659
- }
660
+ }
660
661
 
661
- break;
662
+ break;
662
663
 
663
664
  case 3:
664
665
 
@@ -670,10 +671,10 @@ var ActiveLayer = /** @class */ (function (_super) {
670
671
 
671
672
  }
672
673
 
673
- break
674
+ break
674
675
  }
675
676
  };
676
677
  return ActiveLayer;
677
678
  }(Layer));
678
679
  export { ActiveLayer };
679
- //# sourceMappingURL=activeLayer.js.map
680
+ //# sourceMappingURL=activeLayer.js.map
@@ -1,17 +1,13 @@
1
- import { Pen } from './models/pen';
2
- import { Line } from './models/line';
3
- import { TopologyData } from './models/data';
4
- import { Options } from './options';
1
+ import { Pen, Line } from './models';
5
2
  import { Layer } from './layer';
6
3
  export declare class AnimateLayer extends Layer {
7
- options: Options;
8
- protected data: TopologyData;
4
+ // @ts-ignore
9
5
  pens: Map<any, any>;
10
6
  private timer;
11
7
  private lastNow;
12
8
  private subscribeUpdate;
13
9
  private subscribePlay;
14
- constructor(options: Options, TID: String);
10
+ constructor(TID: String);
15
11
  getAnimateLine(item: Pen): Line;
16
12
  findLine(pen: Pen): Pen;
17
13
  readyPlay(tag?: string, auto?: boolean, pens?: Pen[]): void;
@@ -12,23 +12,19 @@ var __extends = (this && this.__extends) || (function () {
12
12
  };
13
13
  })();
14
14
  import { Store } from 'le5le-store';
15
- import { PenType } from './models/pen';
16
- import { Node } from './models/node';
17
- import { Line } from './models/line';
15
+ import { PenType, Node, Line } from './models';
18
16
  import { Layer } from './layer';
19
17
  import { s8 } from './utils';
18
+ import { commonStore } from './store'
20
19
  var AnimateLayer = /** @class */ (function (_super) {
21
20
  __extends(AnimateLayer, _super);
22
- function AnimateLayer(options, TID) {
23
- if (options === void 0) { options = {}; }
21
+ function AnimateLayer(TID) {
24
22
  var _this = _super.call(this, TID) || this;
25
- _this.options = options;
26
23
  _this.pens = new Map();
27
24
  _this.lastNow = 0;
28
- _this.data = Store.get(_this.generateStoreKey('topology-data'));
29
25
  Store.set(_this.generateStoreKey('LT:AnimateLayer'), _this);
30
- if (!_this.options.animateColor) {
31
- _this.options.animateColor = '#ff6600';
26
+ if (!commonStore[TID].options.animateColor) {
27
+ commonStore[TID].options.animateColor = '#ff6600';
32
28
  }
33
29
  _this.subscribeUpdate = Store.subscribe(_this.generateStoreKey('LT:updateLines'), function (lines) {
34
30
  _this.updateLines(lines);
@@ -55,7 +51,7 @@ var AnimateLayer = /** @class */ (function (_super) {
55
51
  l.animateStart = item.animateStart;
56
52
  l.lineCap = 'round';
57
53
  l.fillStyle = '#fff';
58
- l.strokeStyle = l.animateColor || this.options.animateColor;
54
+ l.strokeStyle = l.animateColor || commonStore[this.TID].options.animateColor;
59
55
  l.length = l.getLen();
60
56
  if (!l.fromArrowColor) {
61
57
  l.fromArrowColor = l.strokeStyle || '#222';
@@ -66,7 +62,7 @@ var AnimateLayer = /** @class */ (function (_super) {
66
62
  return l;
67
63
  };
68
64
  AnimateLayer.prototype.findLine = function (pen) {
69
- for (var _i = 0, _a = this.data.pens; _i < _a.length; _i++) {
65
+ for (var _i = 0, _a = commonStore[this.TID].data.pens; _i < _a.length; _i++) {
70
66
  var item = _a[_i];
71
67
  if (item.id === pen.data) {
72
68
  return item;
@@ -75,11 +71,13 @@ var AnimateLayer = /** @class */ (function (_super) {
75
71
  };
76
72
  AnimateLayer.prototype.readyPlay = function (tag, auto, pens) {
77
73
  var _this = this;
74
+ if(!commonStore || !commonStore[_this.TID]) return;
78
75
  var readyPens = new Map();
79
76
  if (!pens) {
80
- pens = this.data.pens;
77
+ pens = commonStore[_this.TID].data.pens;
81
78
  }
82
79
  pens.forEach(function (pen) {
80
+ if(!(pen instanceof Node)) pen = new Node(pen);
83
81
  pen.setTID(_this.TID);
84
82
  if (!pen.visible || readyPens.get(pen.id)) {
85
83
  return;
@@ -2,12 +2,9 @@
2
2
  import {Options, Padding} from './options';
3
3
  import { Offscreen } from './offscreen';
4
4
  import { RenderLayer } from './renderLayer';
5
- import { Pen, Node, Point, TopologyData, Rect } from './models';
5
+ import { Pen, Point, Rect } from './models';
6
6
  export declare class Calling {
7
7
  id: String;
8
- data: TopologyData;
9
- options: Options;
10
- parentElem: HTMLElement;
11
8
  canvas: RenderLayer;
12
9
  offscreen: Offscreen;
13
10
  private subcribeImage;
@@ -1,33 +1,29 @@
1
1
  import {Store} from 'le5le-store';
2
- import {DefalutOptions} from './options';
3
2
  import {Offscreen} from './offscreen';
4
3
  import {RenderLayer} from './renderLayer';
5
- import {Node, Point, TopologyData, Rect} from './models';
4
+ import {Node} from './models';
6
5
  import {s8, getRect, formatPadding} from './utils';
6
+ import { useStore, clearStore } from './store'
7
7
  var Calling = (function () {
8
8
  function Calling(parent, options) {
9
9
  var _this = this;
10
- this.data = new TopologyData();
11
10
  this.lastTranlated = {x: 0, y: 0};
12
11
  this.rendering = false;
13
12
  this.id = s8();
14
- Store.set(this.generateStoreKey('topology-data'), this.data);
13
+ this.store = useStore(this.id);
15
14
  if (!options) {
16
15
  options = {};
17
16
  }
18
- var font = Object.assign({}, DefalutOptions.font, options.font);
19
- options.font = font;
20
- this.options = Object.assign({}, DefalutOptions, options);
17
+ Object.assign(this.store.options, options);
21
18
  if (typeof parent === 'string') {
22
- this.parentElem = document.getElementById(parent);
19
+ this.store.parentElem = document.getElementById(parent);
23
20
  } else {
24
- this.parentElem = parent;
21
+ this.store.parentElem = parent;
25
22
  }
26
- this.parentElem.style.position = 'relative';
27
- this.parentElem.style.overflow = 'auto';
28
- var id = this.id;
29
- this.offscreen = new Offscreen(this.parentElem, this.options, id);
30
- this.canvas = new RenderLayer(this.parentElem, this.options, id);
23
+ this.store.parentElem.style.position = 'relative';
24
+ this.store.parentElem.style.overflow = 'auto';
25
+ this.offscreen = new Offscreen(this.id);
26
+ this.canvas = new RenderLayer(this.id);
31
27
  this.subcribeImage = Store.subscribe(this.generateStoreKey('LT:imageLoaded'), function () {
32
28
  if (_this.imageTimer) {
33
29
  clearTimeout(_this.imageTimer);
@@ -68,19 +64,19 @@ var Calling = (function () {
68
64
  data = JSON.parse(data);
69
65
  }
70
66
  this.openCount = 0
71
- this.data.scale = data.scale || 1;
72
- this.data.pens = [];
67
+ this.store.data.scale = data.scale || 1;
68
+ this.store.data.pens = [];
73
69
  // for old data.
74
70
  if (data.nodes) {
75
71
  for (var _i = 0, _a = data.nodes; _i < _a.length; _i++) {
76
72
  var item = _a[_i];
77
73
  item.rect.x = 0;
78
74
  item.rect.y = 0;
79
- this.data.pens.push(new Node(item));
75
+ this.store.data.pens.push(new Node(item));
80
76
  }
81
77
  for (var _b = 0, _c = data.lines; _b < _c.length; _b++) {
82
78
  var item = _c[_b];
83
- this.data.pens.push(new Line(item));
79
+ this.store.data.pens.push(new Line(item));
84
80
  }
85
81
  }
86
82
  // end.
@@ -88,32 +84,32 @@ var Calling = (function () {
88
84
  for (var _d = 0, _e = data.pens; _d < _e.length; _d++) {
89
85
  var item = _e[_d];
90
86
  if (!item.from) {
91
- this.data.pens.push(new Node(item));
87
+ this.store.data.pens.push(new Node(item));
92
88
  } else {
93
- this.data.pens.push(new Line(item));
89
+ this.store.data.pens.push(new Line(item));
94
90
  }
95
91
  }
96
92
  }
97
- this.data.bkImageRect = data.bkImageRect || null;
98
- this.data.bkImage = data.bkImage || '';
99
- this.data.mqttOptions = data.mqttOptions || {clientId: s8()};
100
- this.data.mqttTopics = data.mqttTopics || '';
93
+ this.store.data.bkImageRect = data.bkImageRect || null;
94
+ this.store.data.bkImage = data.bkImage || '';
95
+ this.store.data.mqttOptions = data.mqttOptions || {clientId: s8()};
96
+ this.store.data.mqttTopics = data.mqttTopics || '';
101
97
  if (typeof data.data === 'object') {
102
- this.data.data = data.data;
98
+ this.store.data.data = data.data;
103
99
  } else {
104
- this.data.data = data.data || '';
100
+ this.store.data.data = data.data || '';
105
101
  }
106
- this.parentElem.scrollLeft = 0;
107
- this.parentElem.scrollTop = 0;
102
+ this.store.parentElem.scrollLeft = 0;
103
+ this.store.parentElem.scrollTop = 0;
108
104
  this.overflow();
109
105
  this.render(true);
110
106
  };
111
107
  Calling.prototype.overflow = function () {
112
- this.options.isFitview ? this.fitView() : this.bottomView();
108
+ this.store.options.isFitview ? this.fitView() : this.bottomView();
113
109
  };
114
110
  Calling.prototype.getRect = function (pens) {
115
111
  if (!pens) {
116
- pens = this.data.pens;
112
+ pens = this.store.data.pens;
117
113
  }
118
114
  return getRect(pens);
119
115
  };
@@ -124,7 +120,7 @@ var Calling = (function () {
124
120
  }
125
121
  var offsetX = x - this.lastTranlated.x;
126
122
  var offsetY = y - this.lastTranlated.y;
127
- for (var _i = 0, _a = this.data.pens; _i < _a.length; _i++) {
123
+ for (var _i = 0, _a = this.store.data.pens; _i < _a.length; _i++) {
128
124
  var item = _a[_i];
129
125
  item.translate(offsetX, offsetY);
130
126
  }
@@ -135,13 +131,13 @@ var Calling = (function () {
135
131
  // > 1, expand
136
132
  // < 1, reduce
137
133
  Calling.prototype.scale = function (scale, center, w, h) {
138
- if (this.data.scale * scale < this.options.minScale ||
139
- this.data.scale * scale > this.options.maxScale) {
134
+ if (this.store.data.scale * scale < this.store.options.minScale ||
135
+ this.store.data.scale * scale > this.store.options.maxScale) {
140
136
  return;
141
137
  }
142
- this.data.scale *= scale;
138
+ this.store.data.scale *= scale;
143
139
  !center && (center = this.getRect().center);
144
- for (var _i = 0, _a = this.data.pens; _i < _a.length; _i++) {
140
+ for (var _i = 0, _a = this.store.data.pens; _i < _a.length; _i++) {
145
141
  var item = _a[_i];
146
142
  item.scale(scale, center, w, h);
147
143
  }
@@ -150,7 +146,7 @@ var Calling = (function () {
150
146
  var rect = this.getRect();
151
147
  var viewCenter = this.getViewCenter(padding);
152
148
  var center = rect.center;
153
- var parentElem = this.canvas.parentElem;
149
+ var parentElem = this.store.parentElem;
154
150
  var x = (parentElem.offsetWidth - rect.width) / 2;
155
151
  var y = parentElem.scrollHeight - rect.height;
156
152
  var w = parentElem.offsetWidth / rect.width;
@@ -160,7 +156,7 @@ var Calling = (function () {
160
156
  ratio = h;
161
157
  }
162
158
  this.canvas.canvas.style.transform = `translate(${x}px, ${y}px)`;
163
- for (var _i = 0, _a = this.data.pens; _i < _a.length; _i++) {
159
+ for (var _i = 0, _a = this.store.data.pens; _i < _a.length; _i++) {
164
160
  var item = _a[_i];
165
161
  if(item.rect.x > 0) {
166
162
  item.rect.ex = item.rect.ex - item.rect.x;
@@ -181,7 +177,7 @@ var Calling = (function () {
181
177
  var viewCenter = this.getViewCenter(padding);
182
178
  var center = rect.center;
183
179
  this.translate(viewCenter.x - center.x, viewCenter.y - center.y);
184
- var parentElem = this.canvas.parentElem;
180
+ var parentElem = this.store.parentElem;
185
181
  var x = (parentElem.scrollWidth - parentElem.offsetWidth) / 2;
186
182
  var y = (parentElem.scrollHeight - parentElem.offsetHeight) / 2;
187
183
  parentElem.scrollTo(x, y);
@@ -191,7 +187,7 @@ var Calling = (function () {
191
187
  if (!this.hasView())
192
188
  return;
193
189
  // 1. 重置画布尺寸为容器尺寸
194
- var parentElem = this.canvas.parentElem;
190
+ var parentElem = this.store.parentElem;
195
191
  var width = parentElem.offsetWidth, height = parentElem.offsetHeight;
196
192
  this.resize({
197
193
  width: width,
@@ -200,7 +196,7 @@ var Calling = (function () {
200
196
  // 2. 图形居中
201
197
  this.centerView(viewPadding);
202
198
  // 3. 获取设置的留白值
203
- var padding = formatPadding(viewPadding || this.options.viewPadding);
199
+ var padding = formatPadding(viewPadding || this.store.options.viewPadding);
204
200
  // 4. 获取图形尺寸
205
201
  var rect = this.getRect();
206
202
  // 6. 计算缩放比
@@ -217,7 +213,7 @@ var Calling = (function () {
217
213
  return !(rect.width === 99999 || rect.height === 99999);
218
214
  };
219
215
  Calling.prototype.getViewCenter = function (viewPadding) {
220
- var padding = formatPadding(viewPadding || this.options.viewPadding);
216
+ var padding = formatPadding(viewPadding || this.store.options.viewPadding);
221
217
  var _a = this.canvas, width = _a.width, height = _a.height;
222
218
  return {
223
219
  x: (width - padding[1] - padding[3]) / 2 + padding[3],
@@ -228,6 +224,7 @@ var Calling = (function () {
228
224
  return this.id + "-" + key;
229
225
  };
230
226
  Calling.prototype.destroy = function () {
227
+ clearStore(this.store);
231
228
  this.subcribeImage.unsubscribe();
232
229
  this.canvas.destroy();
233
230
  //优化
@@ -1,15 +1,10 @@
1
- import { TopologyData } from './models/data';
2
- import { Options } from './options';
3
1
  import { Layer } from './layer';
4
2
  export declare class Canvas extends Layer {
5
- parentElem: HTMLElement;
6
- options: Options;
7
3
  static dpiRatio: number;
8
- protected data: TopologyData;
9
4
  canvas: HTMLCanvasElement;
10
5
  width: number;
11
6
  height: number;
12
- constructor(parentElem: HTMLElement, options: Options, TID: String);
7
+ constructor(TID: String);
13
8
  resize(size?: {
14
9
  width: number;
15
10
  height: number;