@yanqirenshi/d3.ter 0.1.5 → 0.1.7

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.
@@ -12,41 +12,62 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
12
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
13
 
14
14
  var Relationships = /*#__PURE__*/function () {
15
- function Relationships() {
15
+ function Relationships(parent) {
16
16
  _classCallCheck(this, Relationships);
17
+
18
+ this._parent = parent;
17
19
  }
18
20
 
19
21
  _createClass(Relationships, [{
22
+ key: "rectum",
23
+ value: function rectum() {
24
+ return this._parent.rectum();
25
+ }
26
+ }, {
27
+ key: "style",
28
+ value: function style() {
29
+ return this.rectum().style();
30
+ }
31
+ }, {
32
+ key: "callbacks",
33
+ value: function callbacks() {
34
+ return this._parent.callbacks;
35
+ } // public
36
+
37
+ }, {
20
38
  key: "drawRelationshipsCore",
21
- value: // public
22
- function drawRelationshipsCore(edges) {
39
+ value: function drawRelationshipsCore(edges) {
23
40
  edges.attr('x1', function (d) {
24
41
  var port = d.from;
25
42
  var entity = d.from._owner;
26
- return port.position.x + entity.position.x;
43
+ return port.position().x + entity.position.x;
27
44
  }).attr('y1', function (d) {
28
45
  var port = d.from;
29
46
  var entity = d.from._owner;
30
- return port.position.y + entity.position.y;
47
+ return port.position().y + entity.position.y;
31
48
  }).attr('x2', function (d) {
32
49
  var port = d.to;
33
50
  var entity = d.to._owner;
34
- return port.position.x + entity.position.x;
51
+ return port.position().x + entity.position.x;
35
52
  }).attr('y2', function (d) {
36
53
  var port = d.to;
37
54
  var entity = d.to._owner;
38
- return port.position.y + entity.position.y;
55
+ return port.position().y + entity.position.y;
39
56
  }).attr('stroke', '#888888').attr('stroke-width', 1);
40
57
  }
41
58
  }, {
42
59
  key: "drawRelationships",
43
60
  value: function drawRelationships(place, relationships) {
61
+ var callbacks = this.callbacks();
44
62
  var data = relationships.list.filter(function (edge) {
45
63
  return edge.from._class === 'PORT-FROM' && edge.to._class === 'PORT-TO';
46
64
  });
47
65
  var edges = place.selectAll('line.connector').data(data, function (d) {
48
66
  return d._id;
49
- }).enter().append('line').attr('class', 'connector');
67
+ }).enter().append('line').on("click", function (event, d) {
68
+ var func = callbacks.relationship.click;
69
+ if (func) func(d);
70
+ }).attr('class', 'connector');
50
71
  this.drawRelationshipsCore(edges);
51
72
  }
52
73
  }]);
package/dist/js/Port.js CHANGED
@@ -38,18 +38,19 @@ var Port = /*#__PURE__*/function (_Atman) {
38
38
 
39
39
  var _super = _createSuper(Port);
40
40
 
41
- function Port(type, entity, relatihonship_data) {
41
+ function Port(type, entity, relatihonship_data, rectum) {
42
42
  var _this;
43
43
 
44
44
  _classCallCheck(this, Port);
45
45
 
46
46
  _this = _super.call(this, type === 'from' ? 'PORT-FROM' : 'PORT-TO', relatihonship_data);
47
+ _this._rectum = rectum;
47
48
  _this._id = relatihonship_data.id + '_' + entity._id; // Idenrifier-Instance
48
49
 
49
50
  _this._owner = entity;
50
51
  _this._type = type;
51
52
  _this._core = relatihonship_data[type];
52
- _this.position = relatihonship_data.position || {
53
+ _this._position = relatihonship_data.position || {
53
54
  x: 0,
54
55
  y: 0
55
56
  };
@@ -58,210 +59,374 @@ var Port = /*#__PURE__*/function (_Atman) {
58
59
 
59
60
  _this._entity = null;
60
61
  _this.geometry = new _Geometry["default"]();
62
+ _this._cardinality_distance = 11;
63
+ _this._optionality_distance = 22;
64
+ _this._line = null;
65
+ _this._cardinality = null;
66
+ _this._optionality = null;
61
67
  return _this;
62
68
  }
63
69
 
64
70
  _createClass(Port, [{
71
+ key: "rectum",
72
+ value: function rectum() {
73
+ return this._rectum;
74
+ }
75
+ }, {
76
+ key: "style",
77
+ value: function style() {
78
+ return this.rectum().style();
79
+ }
80
+ }, {
81
+ key: "core",
82
+ value: function core() {
83
+ return this._core;
84
+ }
85
+ }, {
65
86
  key: "degree",
66
87
  value: function degree() {
67
88
  return this._core.position || 0;
68
89
  }
90
+ }, {
91
+ key: "position",
92
+ value: function position(v) {
93
+ if (arguments.length === 1) {
94
+ this._position = v;
95
+ var line = this.linePosition(this.calLinePoints());
96
+ this.cardinalityPosition(this.positionCardinality(line));
97
+ this.optionalityPosition(this.positionOptionality(line));
98
+ }
99
+
100
+ return this._position;
101
+ }
102
+ }, {
103
+ key: "positionOptionality",
104
+ value: function positionOptionality(line_port_to_entity) {
105
+ var distance = this.optionalityDistance(); // d.optionality: 1, 0
106
+
107
+ switch (this.optionality()) {
108
+ case 0:
109
+ return this.calCircle(line_port_to_entity.from, line_port_to_entity.to, distance);
110
+
111
+ case 1:
112
+ return this.calOneLine(line_port_to_entity.from, line_port_to_entity.to, distance);
113
+
114
+ default:
115
+ return null;
116
+ }
117
+ }
118
+ }, {
119
+ key: "positionCardinality",
120
+ value: function positionCardinality(line_port_to_entity) {
121
+ var distance = this.cardinalityDistance(); // cardinality: 1, 3
122
+
123
+ switch (this.cardinality()) {
124
+ case 1:
125
+ return this.calOneLine(line_port_to_entity.from, line_port_to_entity.to, distance);
126
+
127
+ case 3:
128
+ return this.calThreeLine(line_port_to_entity.from, line_port_to_entity.to, distance);
129
+
130
+ default:
131
+ return null;
132
+ }
133
+ }
134
+ }, {
135
+ key: "owner",
136
+ value: function owner() {
137
+ return this._owner;
138
+ }
139
+ }, {
140
+ key: "entity",
141
+ value: function entity() {
142
+ return this._entity;
143
+ }
144
+ }, {
145
+ key: "relationship",
146
+ value: function relationship() {
147
+ return this._relationship;
148
+ }
149
+ }, {
150
+ key: "cardinality",
151
+ value: function cardinality() {
152
+ return this.core().cardinality;
153
+ }
154
+ }, {
155
+ key: "optionality",
156
+ value: function optionality() {
157
+ return this.core().optionality;
158
+ }
159
+ }, {
160
+ key: "linePosition",
161
+ value: function linePosition(v) {
162
+ if (arguments.length === 1) this._line = v;
163
+ return this._line;
164
+ }
165
+ }, {
166
+ key: "cardinalityDistance",
167
+ value: function cardinalityDistance() {
168
+ return this.style().port.cardinality.distance;
169
+ }
170
+ }, {
171
+ key: "optionalityDistance",
172
+ value: function optionalityDistance() {
173
+ return this.style().port.optionality.distance;
174
+ }
175
+ }, {
176
+ key: "cardinalityPosition",
177
+ value: function cardinalityPosition(v) {
178
+ if (arguments.length === 1) this._cardinality = v;
179
+ return this._cardinality;
180
+ }
181
+ }, {
182
+ key: "optionalityPosition",
183
+ value: function optionalityPosition(v) {
184
+ if (arguments.length === 1) this._optionality = v;
185
+ return this._optionality;
186
+ }
69
187
  /* **************************************************************** *
70
188
  * Data manegement
71
189
  * **************************************************************** */
72
190
 
191
+ /**
192
+ * entity と port
193
+ */
194
+
73
195
  }, {
74
196
  key: "calLinePoints",
75
- value: function calLinePoints(port) {
76
- var table = port._column_instance._table;
197
+ value: function calLinePoints() {
198
+ var entity = this.owner();
199
+ var entity_position = entity.position;
200
+ var entity_size = entity.size;
77
201
  var rect = {
78
202
  position: {
79
- x: table.x,
80
- y: table.y
203
+ x: entity_position.x,
204
+ y: entity_position.y
81
205
  },
82
206
  size: {
83
- w: table.w,
84
- h: table.h
207
+ w: entity_size.w,
208
+ h: entity_size.h
85
209
  }
86
210
  };
87
211
  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;
212
+ var margin = this.style().entity.margin; // entity の四辺
213
+
214
+ var four_side_lines = geometry.getFourSideLines(rect, 4, margin); // port と entityの中心との直線。
215
+
216
+ var line_port = geometry.getPortLine(this.degree(), rect); // port と entityの中心との直線 と entity の四辺の交点。
217
+ // 交点 と どの辺 が返ってくる。
218
+
219
+ var cross_point = geometry.getCrossPoint(four_side_lines, line_port); // entity と port との距離
220
+
221
+ var len = margin + 4; // 4: ?
222
+ // point の位置を返す
223
+
92
224
  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
- }
225
+
226
+ var from_point = function from_point() {
227
+ switch (cross_point.target) {
228
+ case 'top':
229
+ return {
230
+ x: to_point.x,
231
+ y: to_point.y + len
232
+ };
233
+
234
+ case 'right':
235
+ return {
236
+ x: to_point.x - len,
237
+ y: to_point.y
238
+ };
239
+
240
+ case 'bottom':
241
+ return {
242
+ x: to_point.x,
243
+ y: to_point.y - len
244
+ };
245
+
246
+ case 'left':
247
+ return {
248
+ x: to_point.x + len,
249
+ y: to_point.y
250
+ };
251
+
252
+ default:
253
+ throw new Error('!!!');
254
+ }
255
+ };
116
256
 
117
257
  return {
118
- from: from_point,
258
+ from: from_point(),
119
259
  to: to_point
120
260
  };
121
261
  }
262
+ /** **************************************************************** *
263
+ * port と entity の間の向きを返します。
264
+ * **************************************************************** */
265
+
266
+ }, {
267
+ key: "portDirection",
268
+ value: function portDirection(from, to) {
269
+ // 縦
270
+ if (from.x === to.x) {
271
+ if (from.y < to.y) return 'DOWN';
272
+ if (from.y > to.y) return 'UP';
273
+ } // 横
274
+
275
+
276
+ if (from.y === to.y) {
277
+ if (from.x < to.x) return 'RIGHT';
278
+ if (from.x > to.x) return 'LEFT';
279
+ } // これはありえないはず。
280
+
281
+
282
+ throw new Error('Can Not Found Direction.');
283
+ }
284
+ /** **************************************************************** *
285
+ * 1 line (cardinaly: 1)
286
+ * Cardinary: n ケースの座標を計算する。
287
+ *
288
+ * Line の from, to で向きを決める。
289
+ *
290
+ * d: port
291
+ * distance: between port and entity
292
+ * **************************************************************** */
293
+
122
294
  }, {
123
295
  key: "calOneLine",
124
- value: function calOneLine(d, distance) {
296
+ value: function calOneLine(from, to, distance) {
125
297
  var r = 11;
126
298
 
127
- if (d.line.from.x === d.line.to.x) {
128
- // 縦
129
- if (d.line.from.y < d.line.to.y) {
130
- // (2)
299
+ switch (this.portDirection(from, to)) {
300
+ case 'DOWN':
131
301
  return {
132
302
  from: {
133
- x: d.line.from.x + r,
134
- y: d.line.from.y + distance
303
+ x: from.x + r,
304
+ y: from.y + distance
135
305
  },
136
306
  to: {
137
- x: d.line.from.x - r,
138
- y: d.line.from.y + distance
307
+ x: from.x - r,
308
+ y: from.y + distance
139
309
  }
140
310
  };
141
- } else if (d.line.from.y > d.line.to.y) {
142
- // (1)
311
+
312
+ case 'DOWN':
143
313
  return {
144
314
  from: {
145
- x: d.line.from.x + r,
146
- y: d.line.from.y - distance
315
+ x: from.x + r,
316
+ y: from.y - distance
147
317
  },
148
318
  to: {
149
- x: d.line.from.x - r,
150
- y: d.line.from.y - distance
319
+ x: from.x - r,
320
+ y: from.y - distance
151
321
  }
152
322
  };
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)
323
+
324
+ case 'RIGHT':
158
325
  return {
159
326
  from: {
160
- x: d.line.from.x + distance,
161
- y: d.line.from.y + r
327
+ x: from.x + distance,
328
+ y: from.y + r
162
329
  },
163
330
  to: {
164
- x: d.line.from.x + distance,
165
- y: d.line.from.y - r
331
+ x: from.x + distance,
332
+ y: from.y - r
166
333
  }
167
334
  };
168
- } else if (d.line.from.x > d.line.to.x) {
169
- // (1)
335
+
336
+ case 'LEFT':
170
337
  return {
171
338
  from: {
172
- x: d.line.from.x - distance,
173
- y: d.line.from.y + r
339
+ x: from.x - distance,
340
+ y: from.y + r
174
341
  },
175
342
  to: {
176
- x: d.line.from.x - distance,
177
- y: d.line.from.y - r
343
+ x: from.x - distance,
344
+ y: from.y - r
178
345
  }
179
346
  };
180
- }
181
- }
182
347
 
183
- return {
184
- from: {
185
- x: 0,
186
- y: 0
187
- },
188
- to: {
189
- x: 0,
190
- y: 0
191
- }
192
- };
348
+ default:
349
+ return {
350
+ from: {
351
+ x: 0,
352
+ y: 0
353
+ },
354
+ to: {
355
+ x: 0,
356
+ y: 0
357
+ }
358
+ };
359
+ }
193
360
  }
194
361
  }, {
195
362
  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
- }
363
+ value:
364
+ /**
365
+ * 3 line (cardinaly: n)
366
+ * Cardinary: n ケースの座標を計算する。
367
+ *
368
+ * Line の from, to で向きを決める。
369
+ *
370
+ * d: port
371
+ * distance: between port and entity
372
+ * **************************************************************** */
373
+ function calThreeLine(from, to, distance) {
374
+ switch (this.portDirection(from, to)) {
375
+ case 'DOWN':
376
+ return [[from.x - distance, from.y], [from.x, from.y + distance], [from.x + distance, from.y]];
212
377
 
213
- return {
214
- from: {
215
- x: 0,
216
- y: 0
217
- },
218
- to: {
219
- x: 0,
220
- y: 0
221
- }
222
- };
378
+ case 'DOWN':
379
+ return [[from.x - distance, from.y], [from.x, from.y - distance], [from.x + distance, from.y]];
380
+
381
+ case 'RIGHT':
382
+ return [[from.x, from.y - distance], [from.x + distance, from.y], [from.x, from.y + distance]];
383
+
384
+ case 'LEFT':
385
+ return [[from.x, from.y - distance], [from.x - distance, from.y], [from.x, from.y + distance]];
386
+
387
+ default:
388
+ return [[0, 0], [0, 0], [0, 0]];
389
+ }
223
390
  }
224
391
  }, {
225
392
  key: "calCircle",
226
- value: function calCircle(d) {
227
- var distance = 22;
393
+ value:
394
+ /** **************************************************************** *
395
+ * null のための 丸
396
+ * **************************************************************** */
397
+ function calCircle(from, to, distance) {
398
+ // const distance = 28;
399
+ switch (this.portDirection(from, to)) {
400
+ case 'DOWN':
401
+ return {
402
+ x: from.x,
403
+ y: from.y + distance
404
+ };
228
405
 
229
- if (d.line.from.x === d.line.to.x) {
230
- // 縦
231
- if (d.line.from.y < d.line.to.y) {
232
- // (2)
406
+ case 'DOWN':
233
407
  return {
234
- x: d.line.from.x,
235
- y: d.line.from.y + distance
408
+ x: from.x,
409
+ y: from.y - distance
236
410
  };
237
- } else if (d.line.from.y > d.line.to.y) {
238
- // (1)
411
+
412
+ case 'RIGHT':
239
413
  return {
240
- x: d.line.from.x,
241
- y: d.line.from.y - distance
414
+ x: from.x + distance,
415
+ y: from.y
242
416
  };
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)
417
+
418
+ case 'LEFT':
248
419
  return {
249
- x: d.line.from.x + distance,
250
- y: d.line.from.y
420
+ x: from.x - distance,
421
+ y: from.y
251
422
  };
252
- } else if (d.line.from.x > d.line.to.x) {
253
- // (1)
423
+
424
+ default:
254
425
  return {
255
- x: d.line.from.x - distance,
256
- y: d.line.from.y
426
+ x: 0,
427
+ y: 0
257
428
  };
258
- }
259
429
  }
260
-
261
- return {
262
- x: 0,
263
- y: 0
264
- };
265
430
  }
266
431
  }, {
267
432
  key: "addPort2Entity",
package/dist/js/Rectum.js CHANGED
@@ -73,14 +73,6 @@ var Rectum = /*#__PURE__*/function (_Colon) {
73
73
  _this.callbacks = _this.ensureCallbacks(params.callbacks);
74
74
  _this._entities = POOL.make();
75
75
  _this._relationships = POOL.make();
76
- _this._default = {
77
- line: {
78
- height: 14,
79
- font: {
80
- size: 14
81
- }
82
- }
83
- };
84
76
  return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
85
77
  }
86
78
 
@@ -145,10 +137,10 @@ var Rectum = /*#__PURE__*/function (_Colon) {
145
137
  var entity_to = _this2.getEntity(to.entity); // Port のクラスインスタンスを作成する。
146
138
 
147
139
 
148
- var port_from = new _Port["default"]('from', entity_from, r);
149
- var port_to = new _Port["default"]('to', entity_to, r); // Relationship のクラスインスタンスを作成する。
140
+ var port_from = new _Port["default"]('from', entity_from, r, _this2);
141
+ var port_to = new _Port["default"]('to', entity_to, r, _this2); // Relationship のクラスインスタンスを作成する。
150
142
 
151
- var element = new _Relationship["default"](r, port_from, port_to); // entity(from) に port をセットする。
143
+ var element = new _Relationship["default"](r, port_from, port_to, _this2); // entity(from) に port をセットする。
152
144
  // entity_from.ports.items.ht[port_from._id] = port_from;
153
145
  // entity_from.ports.items.list.push(port_from);
154
146
  // port_from._entity = entity_from;
@@ -169,6 +161,8 @@ var Rectum = /*#__PURE__*/function (_Colon) {
169
161
  }, {
170
162
  key: "data",
171
163
  value: function data(_data) {
164
+ var _this3 = this;
165
+
172
166
  this._identifiers = POOL.list2pool(_data.identifiers, function (d) {
173
167
  return new _Identifier["default"](d);
174
168
  });
@@ -180,7 +174,7 @@ var Rectum = /*#__PURE__*/function (_Colon) {
180
174
  attributes: this._attributes
181
175
  };
182
176
  this._entities = POOL.list2pool(_data.entities, function (d) {
183
- return new _Entity["default"](d).build(elements).sizing().positioning();
177
+ return new _Entity["default"](d, _this3).build(elements).sizing().positioning();
184
178
  });
185
179
  this._relationships = this.buildRelationshipsWithPort(_data.relationships);
186
180
 
@@ -196,7 +190,33 @@ var Rectum = /*#__PURE__*/function (_Colon) {
196
190
  value: function draw() {
197
191
  var fore = this.layer('foreground');
198
192
  var back = this.layer('background');
199
- new _Painter["default"](fore, back, this.callbacks).draw(this.entities(), this._relationships);
193
+ var painter = new _Painter["default"](this, fore, back, this.callbacks);
194
+ painter.draw(this.entities(), this._relationships);
195
+ }
196
+ }, {
197
+ key: "style",
198
+ value: function style() {
199
+ return {
200
+ entity: {
201
+ margin: 33
202
+ },
203
+ port: {
204
+ stroke: {
205
+ width: 1,
206
+ color: '#888888'
207
+ },
208
+ optionality: {
209
+ distance: 22,
210
+ zero: {
211
+ fill: "#fefefe"
212
+ }
213
+ },
214
+ cardinality: {
215
+ distance: 11
216
+ }
217
+ },
218
+ relationship: {}
219
+ };
200
220
  }
201
221
  }]);
202
222