@yanqirenshi/d3.ter 0.1.0 → 0.1.2

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.
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+
10
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
+
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+
14
+ var Relationships = /*#__PURE__*/function () {
15
+ function Relationships() {
16
+ _classCallCheck(this, Relationships);
17
+ }
18
+
19
+ _createClass(Relationships, [{
20
+ key: "drawRelationshipsCore",
21
+ value: // public
22
+ function drawRelationshipsCore(edges) {
23
+ edges.attr('x1', function (d) {
24
+ var port = d.from;
25
+ var entity = d.from._owner;
26
+ return port.position.x + entity.position.x;
27
+ }).attr('y1', function (d) {
28
+ var port = d.from;
29
+ var entity = d.from._owner;
30
+ return port.position.y + entity.position.y;
31
+ }).attr('x2', function (d) {
32
+ var port = d.to;
33
+ var entity = d.to._owner;
34
+ return port.position.x + entity.position.x;
35
+ }).attr('y2', function (d) {
36
+ var port = d.to;
37
+ var entity = d.to._owner;
38
+ return port.position.y + entity.position.y;
39
+ }).attr('stroke', '#888888').attr('stroke-width', 1);
40
+ }
41
+ }, {
42
+ key: "drawRelationships",
43
+ value: function drawRelationships(place, relationships) {
44
+ var data = relationships.list.filter(function (edge) {
45
+ return edge.from._class === 'PORT-FROM' && edge.to._class === 'PORT-TO';
46
+ });
47
+ var edges = place.selectAll('line.connector').data(data, function (d) {
48
+ return d._id;
49
+ }).enter().append('line').attr('class', 'connector');
50
+ this.drawRelationshipsCore(edges);
51
+ }
52
+ }]);
53
+
54
+ return Relationships;
55
+ }();
56
+
57
+ exports["default"] = Relationships;
package/dist/js/Port.js CHANGED
@@ -9,6 +9,8 @@ exports["default"] = void 0;
9
9
 
10
10
  var _Atman2 = _interopRequireDefault(require("./Atman.js"));
11
11
 
12
+ var _Geometry = _interopRequireDefault(require("./Geometry.js"));
13
+
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
15
 
14
16
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -36,29 +38,243 @@ var Port = /*#__PURE__*/function (_Atman) {
36
38
 
37
39
  var _super = _createSuper(Port);
38
40
 
39
- function Port(type, owner, data) {
41
+ function Port(type, entity, relatihonship_data) {
40
42
  var _this;
41
43
 
42
44
  _classCallCheck(this, Port);
43
45
 
44
- _this = _super.call(this, type === 'from' ? 'PORT-FROM' : 'PORT-TO', data);
45
- _this._id = owner._id; // Idenrifier-Instance
46
+ _this = _super.call(this, type === 'from' ? 'PORT-FROM' : 'PORT-TO', relatihonship_data);
47
+ _this._id = relatihonship_data.id + '_' + entity._id; // Idenrifier-Instance
46
48
 
47
- _this._owner = owner;
49
+ _this._owner = entity;
48
50
  _this._type = type;
49
- _this._core = data[type];
50
- _this.position = data.position || {
51
+ _this._core = relatihonship_data[type];
52
+ _this.position = relatihonship_data.position || {
51
53
  x: 0,
52
54
  y: 0
53
55
  };
54
56
 
55
- owner._ports.push(_assertThisInitialized(_this));
57
+ _this.addPort2Entity(entity);
56
58
 
57
59
  _this._entity = null;
60
+ _this.geometry = new _Geometry["default"]();
58
61
  return _this;
59
62
  }
60
63
 
61
64
  _createClass(Port, [{
65
+ key: "degree",
66
+ value: function degree() {
67
+ return this._core.position || 0;
68
+ }
69
+ /* **************************************************************** *
70
+ * Data manegement
71
+ * **************************************************************** */
72
+
73
+ }, {
74
+ key: "calLinePoints",
75
+ value: function calLinePoints(port) {
76
+ var table = port._column_instance._table;
77
+ var rect = {
78
+ position: {
79
+ x: table.x,
80
+ y: table.y
81
+ },
82
+ size: {
83
+ w: table.w,
84
+ h: table.h
85
+ }
86
+ };
87
+ var geometry = this.geometry;
88
+ var four_side_lines = geometry.getFourSideLines(rect);
89
+ var line_port = geometry.getPortLine(port, rect);
90
+ var cross_point = geometry.getCrossPoint(four_side_lines, line_port);
91
+ var len = 33 + 4;
92
+ var to_point = cross_point.point;
93
+ var from_point;
94
+
95
+ if (cross_point.target === 'top') {
96
+ from_point = {
97
+ x: to_point.x,
98
+ y: to_point.y + len
99
+ };
100
+ } else if (cross_point.target === 'right') {
101
+ from_point = {
102
+ x: to_point.x - len,
103
+ y: to_point.y
104
+ };
105
+ } else if (cross_point.target === 'bottom') {
106
+ from_point = {
107
+ x: to_point.x,
108
+ y: to_point.y - len
109
+ };
110
+ } else if (cross_point.target === 'left') {
111
+ from_point = {
112
+ x: to_point.x + len,
113
+ y: to_point.y
114
+ };
115
+ }
116
+
117
+ return {
118
+ from: from_point,
119
+ to: to_point
120
+ };
121
+ }
122
+ }, {
123
+ key: "calOneLine",
124
+ value: function calOneLine(d, distance) {
125
+ var r = 11;
126
+
127
+ if (d.line.from.x === d.line.to.x) {
128
+ // 縦
129
+ if (d.line.from.y < d.line.to.y) {
130
+ // (2)
131
+ return {
132
+ from: {
133
+ x: d.line.from.x + r,
134
+ y: d.line.from.y + distance
135
+ },
136
+ to: {
137
+ x: d.line.from.x - r,
138
+ y: d.line.from.y + distance
139
+ }
140
+ };
141
+ } else if (d.line.from.y > d.line.to.y) {
142
+ // (1)
143
+ return {
144
+ from: {
145
+ x: d.line.from.x + r,
146
+ y: d.line.from.y - distance
147
+ },
148
+ to: {
149
+ x: d.line.from.x - r,
150
+ y: d.line.from.y - distance
151
+ }
152
+ };
153
+ }
154
+ } else if (d.line.from.y === d.line.to.y) {
155
+ // 横
156
+ if (d.line.from.x < d.line.to.x) {
157
+ // (2)
158
+ return {
159
+ from: {
160
+ x: d.line.from.x + distance,
161
+ y: d.line.from.y + r
162
+ },
163
+ to: {
164
+ x: d.line.from.x + distance,
165
+ y: d.line.from.y - r
166
+ }
167
+ };
168
+ } else if (d.line.from.x > d.line.to.x) {
169
+ // (1)
170
+ return {
171
+ from: {
172
+ x: d.line.from.x - distance,
173
+ y: d.line.from.y + r
174
+ },
175
+ to: {
176
+ x: d.line.from.x - distance,
177
+ y: d.line.from.y - r
178
+ }
179
+ };
180
+ }
181
+ }
182
+
183
+ return {
184
+ from: {
185
+ x: 0,
186
+ y: 0
187
+ },
188
+ to: {
189
+ x: 0,
190
+ y: 0
191
+ }
192
+ };
193
+ }
194
+ }, {
195
+ key: "calThreeLine",
196
+ value: function calThreeLine(d, distance) {
197
+ if (d.line.from.x === d.line.to.x) {
198
+ // 縦
199
+ if (d.line.from.y < d.line.to.y) {
200
+ return [[d.line.from.x - distance, d.line.from.y], [d.line.from.x, d.line.from.y + distance], [d.line.from.x + distance, d.line.from.y]];
201
+ } else if (d.line.from.y > d.line.to.y) {
202
+ return [[d.line.from.x - distance, d.line.from.y], [d.line.from.x, d.line.from.y - distance], [d.line.from.x + distance, d.line.from.y]];
203
+ }
204
+ } else if (d.line.from.y === d.line.to.y) {
205
+ // 横
206
+ if (d.line.from.x < d.line.to.x) {
207
+ return [[d.line.from.x, d.line.from.y - distance], [d.line.from.x + distance, d.line.from.y], [d.line.from.x, d.line.from.y + distance]];
208
+ } else if (d.line.from.x > d.line.to.x) {
209
+ return [[d.line.from.x, d.line.from.y - distance], [d.line.from.x - distance, d.line.from.y], [d.line.from.x, d.line.from.y + distance]];
210
+ }
211
+ }
212
+
213
+ return {
214
+ from: {
215
+ x: 0,
216
+ y: 0
217
+ },
218
+ to: {
219
+ x: 0,
220
+ y: 0
221
+ }
222
+ };
223
+ }
224
+ }, {
225
+ key: "calCircle",
226
+ value: function calCircle(d) {
227
+ var distance = 22;
228
+
229
+ if (d.line.from.x === d.line.to.x) {
230
+ // 縦
231
+ if (d.line.from.y < d.line.to.y) {
232
+ // (2)
233
+ return {
234
+ x: d.line.from.x,
235
+ y: d.line.from.y + distance
236
+ };
237
+ } else if (d.line.from.y > d.line.to.y) {
238
+ // (1)
239
+ return {
240
+ x: d.line.from.x,
241
+ y: d.line.from.y - distance
242
+ };
243
+ }
244
+ } else if (d.line.from.y === d.line.to.y) {
245
+ // 横
246
+ if (d.line.from.x < d.line.to.x) {
247
+ // (2)
248
+ return {
249
+ x: d.line.from.x + distance,
250
+ y: d.line.from.y
251
+ };
252
+ } else if (d.line.from.x > d.line.to.x) {
253
+ // (1)
254
+ return {
255
+ x: d.line.from.x - distance,
256
+ y: d.line.from.y
257
+ };
258
+ }
259
+ }
260
+
261
+ return {
262
+ x: 0,
263
+ y: 0
264
+ };
265
+ }
266
+ }, {
267
+ key: "addPort2Entity",
268
+ value:
269
+ /* **************************************************************** *
270
+ *
271
+ * **************************************************************** */
272
+ function addPort2Entity(entity) {
273
+ var port = this;
274
+ entity.ports.items.ht[port.id()] = port;
275
+ entity.ports.items.list.push(port);
276
+ }
277
+ }, {
62
278
  key: "position_degree",
63
279
  value: function position_degree() {
64
280
  return this._core.position % 360;
package/dist/js/Rectum.js CHANGED
@@ -125,44 +125,46 @@ var Rectum = /*#__PURE__*/function (_Colon) {
125
125
 
126
126
  return null;
127
127
  }
128
+ }, {
129
+ key: "getEntity",
130
+ value: function getEntity(id) {
131
+ var entities = this.entities();
132
+ return entities.ht[id] || null;
133
+ }
128
134
  }, {
129
135
  key: "buildRelationshipsWithPort",
130
136
  value: function buildRelationshipsWithPort(relationships) {
131
- var entities = this.entities();
132
- var out = {
133
- list: [],
134
- ht: {}
135
- };
137
+ var _this2 = this;
136
138
 
137
- var _iterator2 = _createForOfIteratorHelper(relationships),
138
- _step2;
139
+ return relationships.reduce(function (out, r) {
140
+ var from = r.from;
141
+ var to = r.to; // entity identifier を取得する。
139
142
 
140
- try {
141
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
142
- var r = _step2.value;
143
- var id_from = this.getIdentifier(r.from.id, entities);
144
- var id_to = this.getIdentifier(r.to.id, entities);
145
- var port_from = new _Port["default"]('from', id_from, r);
146
- var port_to = new _Port["default"]('to', id_to, r);
147
- var element = new _Relationship["default"](r, port_from, port_to);
148
- var entity_from = id_from._entity;
149
- var entity_to = id_to._entity;
150
- port_from._entity = entity_from;
151
- port_to._entity = entity_to;
152
- entity_from.ports.items.ht[port_from._id] = port_from;
153
- entity_from.ports.items.list.push(port_from);
154
- entity_to.ports.items.ht[port_to._id] = port_to;
155
- entity_to.ports.items.list.push(port_to);
156
- out.list.push(element);
157
- out.ht[element._id] = element;
158
- }
159
- } catch (err) {
160
- _iterator2.e(err);
161
- } finally {
162
- _iterator2.f();
163
- }
143
+ var entity_from = _this2.getEntity(from.entity);
144
+
145
+ var entity_to = _this2.getEntity(to.entity); // Port のクラスインスタンスを作成する。
146
+
147
+
148
+ var port_from = new _Port["default"]('from', entity_from, r);
149
+ var port_to = new _Port["default"]('to', entity_to, r); // Relationship のクラスインスタンスを作成する。
164
150
 
165
- return out;
151
+ var element = new _Relationship["default"](r, port_from, port_to); // entity(from) に port をセットする。
152
+ // entity_from.ports.items.ht[port_from._id] = port_from;
153
+ // entity_from.ports.items.list.push(port_from);
154
+ // port_from._entity = entity_from;
155
+ // entity(to) に port をセットする。
156
+ // entity_to.ports.items.ht[port_to._id] = port_to;
157
+ // entity_to.ports.items.list.push(port_to);
158
+ // port_to._entity = entity_to;
159
+ // out
160
+
161
+ out.list.push(element);
162
+ out.ht[element._id] = element;
163
+ return out;
164
+ }, {
165
+ list: [],
166
+ ht: {}
167
+ });
166
168
  }
167
169
  }, {
168
170
  key: "data",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.ter",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "author": "yanqirenshi@gmail.com",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "description": "See `src/index.html`",