@yanqirenshi/d3.ter 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -712,7 +712,6 @@ var EntityTailor = /*#__PURE__*/function (_Builder) {
712
712
  key: "positioningPort",
713
713
  value: function positioningPort(port) {
714
714
  var entity = this;
715
- console.log(port._relationship);
716
715
  var line_port = this.makePortLine(entity, port);
717
716
  var lines_entity = this.getEntityLines(entity);
718
717
  var point = this.getCrossPoint(lines_entity, line_port, port);
@@ -20,9 +20,12 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
20
20
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
21
 
22
22
  var Painter = /*#__PURE__*/function () {
23
- function Painter() {
23
+ function Painter(foreground, background, callbacks) {
24
24
  _classCallCheck(this, Painter);
25
25
 
26
+ this.foreground = foreground;
27
+ this.background = background;
28
+ this.callbacks = callbacks;
26
29
  this._default = {
27
30
  line: {
28
31
  height: 14,
@@ -39,48 +42,70 @@ var Painter = /*#__PURE__*/function () {
39
42
 
40
43
  _createClass(Painter, [{
41
44
  key: "dragStart",
42
- value: function dragStart(d) {// let e = d3.event;
43
- // d._drag = {
44
- // start: {
45
- // x: e.x,
46
- // y: e.y,
47
- // }
48
- // };
45
+ value: function dragStart(event, entity) {
46
+ entity._drag = {
47
+ start: {
48
+ x: event.x,
49
+ y: event.y
50
+ }
51
+ };
49
52
  }
50
53
  }, {
51
54
  key: "dragged",
52
- value: function dragged(d) {// let e = d3.event;
53
- // d.position.x += e.x - d._drag.start.x;
54
- // d.position.y += e.y - d._drag.start.y;
55
- // this.moveEntity(d);
55
+ value: function dragged(event, entity) {
56
+ entity.position.x += event.x - entity._drag.start.x;
57
+ entity.position.y += event.y - entity._drag.start.y;
58
+ this.moveEntity(entity);
59
+ this.moveEdges(entity);
56
60
  }
57
61
  }, {
58
62
  key: "dragEnd",
59
- value: function dragEnd(entity) {// let campus = STORE.get('active.ter.campus');
60
- // delete entity._drag;
61
- // ACTIONS.saveTerEntityPosition(campus, entity);
63
+ value: function dragEnd(event, entity) {
64
+ // let campus = STORE.get('active.ter.campus');
65
+ delete entity._drag; // ACTIONS.saveTerEntityPosition(campus, entity);
62
66
  }
63
67
  }, {
64
- key: "addMoveEvents2Body",
65
- value: function addMoveEvents2Body(body) {
68
+ key: "addMoveEvents",
69
+ value: function addMoveEvents(body) {
66
70
  var _this = this;
67
71
 
68
- return body.call(d3.drag().on("start", function (d) {
69
- return _this.dragStart(d);
70
- }).on("drag", function (d) {
71
- return _this.dragged(d);
72
- }).on("end", function (d) {
73
- return _this.dragEnd(d);
72
+ return body.call(d3.drag().on("start", function (e, d) {
73
+ return _this.dragStart(e, d);
74
+ }).on("drag", function (e, d) {
75
+ return _this.dragged(e, d);
76
+ }).on("end", function (e, d) {
77
+ return _this.dragEnd(e, d);
74
78
  }));
75
79
  }
80
+ }, {
81
+ key: "moveEntity",
82
+ value: function moveEntity(entity) {
83
+ var selection = this.foreground.selectAll('g.entity').data([entity], function (d) {
84
+ return d._id;
85
+ });
86
+ selection.attr('transform', function (d) {
87
+ return 'translate(' + d.position.x + ',' + d.position.y + ')';
88
+ });
89
+ }
90
+ }, {
91
+ key: "moveEdges",
92
+ value: function moveEdges(entity) {
93
+ var edges = entity.ports.items.list.map(function (p) {
94
+ return p._relationship;
95
+ });
96
+ var selection = this.background.selectAll('line.connector').data(edges, function (d) {
97
+ return d._id;
98
+ });
99
+ this.drawRelationshipsCore(selection);
100
+ }
76
101
  /* **************************************************************** *
77
102
  * Draw this.entity
78
103
  * **************************************************************** */
79
104
 
80
105
  }, {
81
106
  key: "drawGroup",
82
- value: function drawGroup(place, data) {
83
- return place.selectAll('g.entity').data(data, function (d) {
107
+ value: function drawGroup(data) {
108
+ return this.foreground.selectAll('g.entity').data(data, function (d) {
84
109
  return d._id;
85
110
  }).enter().append('g').attr('class', 'entity').attr('entity-id', function (d) {
86
111
  return d._id;
@@ -116,7 +141,7 @@ var Painter = /*#__PURE__*/function () {
116
141
  value: function drawBody(groups) {
117
142
  var body = groups.append('rect');
118
143
  this.drawBodyCore(body);
119
- return this.addMoveEvents2Body(body);
144
+ return body;
120
145
  }
121
146
  /* ************************************ *
122
147
  * Name *
@@ -146,7 +171,7 @@ var Painter = /*#__PURE__*/function () {
146
171
  value: function drawNameText(texts) {
147
172
  var _this2 = this;
148
173
 
149
- return texts.attr('class', 'entity-title').attr("x", function (d) {
174
+ texts.attr('class', 'entity-title').attr("x", function (d) {
150
175
  return d.padding + d.name.padding;
151
176
  }).attr("y", function (d) {
152
177
  return d.padding + d.name.padding + _this2._default.line.font.size;
@@ -157,16 +182,19 @@ var Painter = /*#__PURE__*/function () {
157
182
  }).text(function (d) {
158
183
  return d.name.val();
159
184
  });
185
+ this.addMoveEvents(texts);
186
+ return texts;
160
187
  }
161
188
  }, {
162
189
  key: "drawName",
163
- value: function drawName(groups, callbacks) {
164
- var rects = groups.append('rect').on("click", function (d) {
190
+ value: function drawName(groups) {
191
+ var callbacks = this.callbacks;
192
+ var rects = groups.append('rect').on("click", function (event, d) {
165
193
  var func = callbacks.entity.click;
166
194
  if (func) func(d);
167
195
  }).attr('class', 'entity-title');
168
196
  this.drawNameRect(rects);
169
- var texts = groups.append('text').on("click", function (d) {
197
+ var texts = groups.append('text').on("click", function (event, d) {
170
198
  var func = callbacks.entity.click;
171
199
  if (func) func(d);
172
200
  }).attr('class', 'entity-title');
@@ -379,7 +407,8 @@ var Painter = /*#__PURE__*/function () {
379
407
  }
380
408
  }, {
381
409
  key: "drawRelationships",
382
- value: function drawRelationships(place, relationships) {
410
+ value: function drawRelationships(relationships) {
411
+ var place = this.background;
383
412
  var data = relationships.list.filter(function (edge) {
384
413
  return edge.from._class === 'PORT-FROM' && edge.to._class === 'PORT-TO';
385
414
  });
@@ -407,10 +436,10 @@ var Painter = /*#__PURE__*/function () {
407
436
  }
408
437
  }, {
409
438
  key: "draw",
410
- value: function draw(fore, back, entities, relationsihps) {
411
- var groups = this.drawGroup(fore, entities.list);
439
+ value: function draw(entities, relationsihps) {
440
+ var groups = this.drawGroup(entities.list);
412
441
  this.drawBody(groups);
413
- this.drawName(groups, this._callbacks);
442
+ this.drawName(groups);
414
443
  this.drawType(groups);
415
444
  this.drawIdentifiers(groups);
416
445
  this.drawAttributes(groups); // resizing & redraw
@@ -420,7 +449,7 @@ var Painter = /*#__PURE__*/function () {
420
449
  });
421
450
  this.redraw(groups);
422
451
  this.drawPorts(groups);
423
- this.drawRelationships(back, relationsihps);
452
+ this.drawRelationships(relationsihps);
424
453
  }
425
454
  }]);
426
455
 
package/dist/js/Rectum.js CHANGED
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports["default"] = void 0;
9
9
 
10
+ var _deepmerge = _interopRequireDefault(require("deepmerge"));
11
+
10
12
  var _assh0le = require("@yanqirenshi/assh0le");
11
13
 
12
14
  var _Entity = _interopRequireDefault(require("./Entity.js"));
@@ -68,6 +70,7 @@ var Rectum = /*#__PURE__*/function (_Colon) {
68
70
  _classCallCheck(this, Rectum);
69
71
 
70
72
  _this = _super.call(this, params);
73
+ _this.callbacks = _this.ensureCallbacks(params.callbacks);
71
74
  _this._entities = POOL.make();
72
75
  _this._relationships = POOL.make();
73
76
  _this._default = {
@@ -82,6 +85,16 @@ var Rectum = /*#__PURE__*/function (_Colon) {
82
85
  }
83
86
 
84
87
  _createClass(Rectum, [{
88
+ key: "ensureCallbacks",
89
+ value: function ensureCallbacks(callbacks) {
90
+ var template = {
91
+ entity: {
92
+ click: null
93
+ }
94
+ };
95
+ return (0, _deepmerge["default"])(template, callbacks);
96
+ }
97
+ }, {
85
98
  key: "entities",
86
99
  value: function entities() {
87
100
  return this._entities;
@@ -181,7 +194,7 @@ var Rectum = /*#__PURE__*/function (_Colon) {
181
194
  value: function draw() {
182
195
  var fore = this.layer('foreground');
183
196
  var back = this.layer('background');
184
- new _Painter["default"]().draw(fore, back, this.entities(), this._relationships);
197
+ new _Painter["default"](fore, back, this.callbacks).draw(this.entities(), this._relationships);
185
198
  }
186
199
  }]);
187
200
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.ter",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "author": "yanqirenshi@gmail.com",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "description": "See `src/index.html`",
@@ -26,7 +26,8 @@
26
26
  "react-dom": "^17.0.1"
27
27
  },
28
28
  "dependencies": {
29
- "@yanqirenshi/assh0le": "0.2.10"
29
+ "@yanqirenshi/assh0le": "0.2.10",
30
+ "deepmerge": "^4.2.2"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@babel/cli": "^7.12.10",