@yanqirenshi/d3.ter 0.1.4 → 0.1.6

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.
package/dist/js/Port.js CHANGED
@@ -49,7 +49,7 @@ var Port = /*#__PURE__*/function (_Atman) {
49
49
  _this._owner = entity;
50
50
  _this._type = type;
51
51
  _this._core = relatihonship_data[type];
52
- _this.position = relatihonship_data.position || {
52
+ _this._position = relatihonship_data.position || {
53
53
  x: 0,
54
54
  y: 0
55
55
  };
@@ -58,210 +58,363 @@ var Port = /*#__PURE__*/function (_Atman) {
58
58
 
59
59
  _this._entity = null;
60
60
  _this.geometry = new _Geometry["default"]();
61
+ _this._cardinality_distance = 11;
62
+ _this._optionality_distance = 22;
63
+ _this._line = null;
64
+ _this._cardinality = null;
65
+ _this._optionality = null;
61
66
  return _this;
62
67
  }
63
68
 
64
69
  _createClass(Port, [{
70
+ key: "core",
71
+ value: function core() {
72
+ return this._core;
73
+ }
74
+ }, {
65
75
  key: "degree",
66
76
  value: function degree() {
67
77
  return this._core.position || 0;
68
78
  }
79
+ }, {
80
+ key: "position",
81
+ value: function position(v) {
82
+ if (arguments.length === 1) {
83
+ this._position = v;
84
+ var line = this.linePosition(this.calLinePoints());
85
+ this.cardinalityPosition(this.positionCardinality(line));
86
+ this.optionalityPosition(this.positionOptionality(line));
87
+ }
88
+
89
+ return this._position;
90
+ }
91
+ }, {
92
+ key: "positionOptionality",
93
+ value: function positionOptionality(line_port_to_entity) {
94
+ var distance = this.optionalityDistance(); // d.optionality: 1, 0
95
+
96
+ switch (this.optionality()) {
97
+ case 0:
98
+ return this.calCircle(line_port_to_entity.from, line_port_to_entity.to, distance);
99
+
100
+ case 1:
101
+ return this.calOneLine(line_port_to_entity.from, line_port_to_entity.to, distance);
102
+
103
+ default:
104
+ return null;
105
+ }
106
+ }
107
+ }, {
108
+ key: "positionCardinality",
109
+ value: function positionCardinality(line_port_to_entity) {
110
+ var distance = this.cardinalityDistance(); // cardinality: 1, 3
111
+
112
+ switch (this.cardinality()) {
113
+ case 1:
114
+ return this.calOneLine(line_port_to_entity.from, line_port_to_entity.to, distance);
115
+
116
+ case 3:
117
+ return this.calThreeLine(line_port_to_entity.from, line_port_to_entity.to, distance);
118
+
119
+ default:
120
+ return null;
121
+ }
122
+ }
123
+ }, {
124
+ key: "owner",
125
+ value: function owner() {
126
+ return this._owner;
127
+ }
128
+ }, {
129
+ key: "entity",
130
+ value: function entity() {
131
+ return this._entity;
132
+ }
133
+ }, {
134
+ key: "relationship",
135
+ value: function relationship() {
136
+ return this._relationship;
137
+ }
138
+ }, {
139
+ key: "cardinality",
140
+ value: function cardinality() {
141
+ return this.core().cardinality;
142
+ }
143
+ }, {
144
+ key: "optionality",
145
+ value: function optionality() {
146
+ return this.core().optionality;
147
+ }
148
+ }, {
149
+ key: "linePosition",
150
+ value: function linePosition(v) {
151
+ if (arguments.length === 1) this._line = v;
152
+ return this._line;
153
+ }
154
+ }, {
155
+ key: "cardinalityDistance",
156
+ value: function cardinalityDistance() {
157
+ return this._cardinality_distance;
158
+ }
159
+ }, {
160
+ key: "optionalityDistance",
161
+ value: function optionalityDistance() {
162
+ return this._optionality_distance;
163
+ }
164
+ }, {
165
+ key: "cardinalityPosition",
166
+ value: function cardinalityPosition(v) {
167
+ if (arguments.length === 1) this._cardinality = v;
168
+ return this._cardinality;
169
+ }
170
+ }, {
171
+ key: "optionalityPosition",
172
+ value: function optionalityPosition(v) {
173
+ if (arguments.length === 1) this._optionality = v;
174
+ return this._optionality;
175
+ }
69
176
  /* **************************************************************** *
70
177
  * Data manegement
71
178
  * **************************************************************** */
72
179
 
180
+ /**
181
+ * entity と port
182
+ */
183
+
73
184
  }, {
74
185
  key: "calLinePoints",
75
- value: function calLinePoints(port) {
76
- var table = port._column_instance._table;
186
+ value: function calLinePoints() {
187
+ var entity = this.owner();
188
+ var entity_position = entity.position;
189
+ var entity_size = entity.size;
77
190
  var rect = {
78
191
  position: {
79
- x: table.x,
80
- y: table.y
192
+ x: entity_position.x,
193
+ y: entity_position.y
81
194
  },
82
195
  size: {
83
- w: table.w,
84
- h: table.h
196
+ w: entity_size.w,
197
+ h: entity_size.h
85
198
  }
86
199
  };
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;
200
+ var geometry = this.geometry; // entity の四辺
201
+
202
+ var four_side_lines = geometry.getFourSideLines(rect, 4, 33); // port と entityの中心との直線。
203
+
204
+ var line_port = geometry.getPortLine(this.degree(), rect); // port と entityの中心との直線 と entity の四辺の交点。
205
+ // 交点 と どの辺 が返ってくる。
206
+
207
+ var cross_point = geometry.getCrossPoint(four_side_lines, line_port); // entity と port との距離
208
+
209
+ var len = 33 + 4; // 33: ?, 4: ?
210
+ // point の位置を返す
211
+
92
212
  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
- }
213
+
214
+ var from_point = function from_point() {
215
+ switch (cross_point.target) {
216
+ case 'top':
217
+ return {
218
+ x: to_point.x,
219
+ y: to_point.y + len
220
+ };
221
+
222
+ case 'right':
223
+ return {
224
+ x: to_point.x - len,
225
+ y: to_point.y
226
+ };
227
+
228
+ case 'bottom':
229
+ return {
230
+ x: to_point.x,
231
+ y: to_point.y - len
232
+ };
233
+
234
+ case 'left':
235
+ return {
236
+ x: to_point.x + len,
237
+ y: to_point.y
238
+ };
239
+
240
+ default:
241
+ throw new Error('!!!');
242
+ }
243
+ };
116
244
 
117
245
  return {
118
- from: from_point,
246
+ from: from_point(),
119
247
  to: to_point
120
248
  };
121
249
  }
250
+ /** **************************************************************** *
251
+ * port と entity の間の向きを返します。
252
+ * **************************************************************** */
253
+
254
+ }, {
255
+ key: "portDirection",
256
+ value: function portDirection(from, to) {
257
+ // 縦
258
+ if (from.x === to.x) {
259
+ if (from.y < to.y) return 'DOWN';
260
+ if (from.y > to.y) return 'UP';
261
+ } // 横
262
+
263
+
264
+ if (from.y === to.y) {
265
+ if (from.x < to.x) return 'RIGHT';
266
+ if (from.x > to.x) return 'LEFT';
267
+ } // これはありえないはず。
268
+
269
+
270
+ throw new Error('Can Not Found Direction.');
271
+ }
272
+ /** **************************************************************** *
273
+ * 1 line (cardinaly: 1)
274
+ * Cardinary: n ケースの座標を計算する。
275
+ *
276
+ * Line の from, to で向きを決める。
277
+ *
278
+ * d: port
279
+ * distance: between port and entity
280
+ * **************************************************************** */
281
+
122
282
  }, {
123
283
  key: "calOneLine",
124
- value: function calOneLine(d, distance) {
284
+ value: function calOneLine(from, to, distance) {
125
285
  var r = 11;
126
286
 
127
- if (d.line.from.x === d.line.to.x) {
128
- // 縦
129
- if (d.line.from.y < d.line.to.y) {
130
- // (2)
287
+ switch (this.portDirection(from, to)) {
288
+ case 'DOWN':
131
289
  return {
132
290
  from: {
133
- x: d.line.from.x + r,
134
- y: d.line.from.y + distance
291
+ x: from.x + r,
292
+ y: from.y + distance
135
293
  },
136
294
  to: {
137
- x: d.line.from.x - r,
138
- y: d.line.from.y + distance
295
+ x: from.x - r,
296
+ y: from.y + distance
139
297
  }
140
298
  };
141
- } else if (d.line.from.y > d.line.to.y) {
142
- // (1)
299
+
300
+ case 'DOWN':
143
301
  return {
144
302
  from: {
145
- x: d.line.from.x + r,
146
- y: d.line.from.y - distance
303
+ x: from.x + r,
304
+ y: from.y - distance
147
305
  },
148
306
  to: {
149
- x: d.line.from.x - r,
150
- y: d.line.from.y - distance
307
+ x: from.x - r,
308
+ y: from.y - distance
151
309
  }
152
310
  };
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)
311
+
312
+ case 'RIGHT':
158
313
  return {
159
314
  from: {
160
- x: d.line.from.x + distance,
161
- y: d.line.from.y + r
315
+ x: from.x + distance,
316
+ y: from.y + r
162
317
  },
163
318
  to: {
164
- x: d.line.from.x + distance,
165
- y: d.line.from.y - r
319
+ x: from.x + distance,
320
+ y: from.y - r
166
321
  }
167
322
  };
168
- } else if (d.line.from.x > d.line.to.x) {
169
- // (1)
323
+
324
+ case 'LEFT':
170
325
  return {
171
326
  from: {
172
- x: d.line.from.x - distance,
173
- y: d.line.from.y + r
327
+ x: from.x - distance,
328
+ y: from.y + r
174
329
  },
175
330
  to: {
176
- x: d.line.from.x - distance,
177
- y: d.line.from.y - r
331
+ x: from.x - distance,
332
+ y: from.y - r
178
333
  }
179
334
  };
180
- }
181
- }
182
335
 
183
- return {
184
- from: {
185
- x: 0,
186
- y: 0
187
- },
188
- to: {
189
- x: 0,
190
- y: 0
191
- }
192
- };
336
+ default:
337
+ return {
338
+ from: {
339
+ x: 0,
340
+ y: 0
341
+ },
342
+ to: {
343
+ x: 0,
344
+ y: 0
345
+ }
346
+ };
347
+ }
193
348
  }
194
349
  }, {
195
350
  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
- }
351
+ value:
352
+ /**
353
+ * 3 line (cardinaly: n)
354
+ * Cardinary: n ケースの座標を計算する。
355
+ *
356
+ * Line の from, to で向きを決める。
357
+ *
358
+ * d: port
359
+ * distance: between port and entity
360
+ * **************************************************************** */
361
+ function calThreeLine(from, to, distance) {
362
+ switch (this.portDirection(from, to)) {
363
+ case 'DOWN':
364
+ return [[from.x - distance, from.y], [from.x, from.y + distance], [from.x + distance, from.y]];
212
365
 
213
- return {
214
- from: {
215
- x: 0,
216
- y: 0
217
- },
218
- to: {
219
- x: 0,
220
- y: 0
221
- }
222
- };
366
+ case 'DOWN':
367
+ return [[from.x - distance, from.y], [from.x, from.y - distance], [from.x + distance, from.y]];
368
+
369
+ case 'RIGHT':
370
+ return [[from.x, from.y - distance], [from.x + distance, from.y], [from.x, from.y + distance]];
371
+
372
+ case 'LEFT':
373
+ return [[from.x, from.y - distance], [from.x - distance, from.y], [from.x, from.y + distance]];
374
+
375
+ default:
376
+ return [[0, 0], [0, 0], [0, 0]];
377
+ }
223
378
  }
224
379
  }, {
225
380
  key: "calCircle",
226
- value: function calCircle(d) {
227
- var distance = 22;
381
+ value:
382
+ /** **************************************************************** *
383
+ * null のための 丸
384
+ * **************************************************************** */
385
+ function calCircle(from, to, distance) {
386
+ // const distance = 28;
387
+ switch (this.portDirection(from, to)) {
388
+ case 'DOWN':
389
+ return {
390
+ x: from.x,
391
+ y: from.y + distance
392
+ };
228
393
 
229
- if (d.line.from.x === d.line.to.x) {
230
- // 縦
231
- if (d.line.from.y < d.line.to.y) {
232
- // (2)
394
+ case 'DOWN':
233
395
  return {
234
- x: d.line.from.x,
235
- y: d.line.from.y + distance
396
+ x: from.x,
397
+ y: from.y - distance
236
398
  };
237
- } else if (d.line.from.y > d.line.to.y) {
238
- // (1)
399
+
400
+ case 'RIGHT':
239
401
  return {
240
- x: d.line.from.x,
241
- y: d.line.from.y - distance
402
+ x: from.x + distance,
403
+ y: from.y
242
404
  };
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)
405
+
406
+ case 'LEFT':
248
407
  return {
249
- x: d.line.from.x + distance,
250
- y: d.line.from.y
408
+ x: from.x - distance,
409
+ y: from.y
251
410
  };
252
- } else if (d.line.from.x > d.line.to.x) {
253
- // (1)
411
+
412
+ default:
254
413
  return {
255
- x: d.line.from.x - distance,
256
- y: d.line.from.y
414
+ x: 0,
415
+ y: 0
257
416
  };
258
- }
259
417
  }
260
-
261
- return {
262
- x: 0,
263
- y: 0
264
- };
265
418
  }
266
419
  }, {
267
420
  key: "addPort2Entity",
@@ -34,24 +34,17 @@ var Name = /*#__PURE__*/function () {
34
34
  _createClass(Name, [{
35
35
  key: "set",
36
36
  value: function set(v) {
37
- console.log('set-----');
38
- console.log(v);
39
- if (arguments.lengh === 0 || !v) return this;
40
- console.log(_typeof(v));
41
-
42
- if ('string' === typeof v) {
37
+ if (arguments.lengh === 0 || !v) {
38
+ return this;
39
+ } else if ('string' === typeof v) {
43
40
  var isLogical = function isLogical(str) {
44
41
  return str.match(/^[^\x01-\x7E\xA1-\xDF]+$/);
45
42
  };
46
43
 
47
44
  if (isLogical) this.physical = v;else this.logical = v;
48
- return this;
49
- }
50
-
51
- if ("object" === _typeof(v)) {
45
+ } else if ("object" === _typeof(v)) {
52
46
  this.physical = v.physical || null;
53
47
  this.logical = v.logical || null;
54
- return this;
55
48
  }
56
49
 
57
50
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.ter",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "author": "yanqirenshi@gmail.com",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "description": "See `src/index.html`",