@yanqirenshi/d3.ter 0.0.9 → 0.1.1

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,408 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var d3 = _interopRequireWildcard(require("d3"));
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ 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); } }
19
+
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
+
22
+ var Entity = /*#__PURE__*/function () {
23
+ function Entity(parent) {
24
+ _classCallCheck(this, Entity);
25
+
26
+ this._parent = parent;
27
+ }
28
+
29
+ _createClass(Entity, [{
30
+ key: "foreground",
31
+ value: function foreground() {
32
+ return this._parent.foreground;
33
+ }
34
+ }, {
35
+ key: "background",
36
+ value: function background() {
37
+ return this._parent.background;
38
+ }
39
+ }, {
40
+ key: "callbacks",
41
+ value: function callbacks() {
42
+ return this._parent.callbacks;
43
+ }
44
+ }, {
45
+ key: "default",
46
+ value: function _default() {
47
+ return this._parent._default;
48
+ }
49
+ /* **************************************************************** *
50
+ * Move
51
+ * TODO: これは Painter に持っていくべきかも。全部じゃないにしても。
52
+ * **************************************************************** */
53
+
54
+ }, {
55
+ key: "dragStart",
56
+ value: function dragStart(event, entity) {
57
+ entity._drag = {
58
+ start: {
59
+ x: event.x,
60
+ y: event.y
61
+ }
62
+ };
63
+ }
64
+ }, {
65
+ key: "dragged",
66
+ value: function dragged(event, entity) {
67
+ entity.position.x += event.x - entity._drag.start.x;
68
+ entity.position.y += event.y - entity._drag.start.y;
69
+ this.moveEntity(entity);
70
+ this.moveEdges(entity);
71
+ }
72
+ }, {
73
+ key: "dragEnd",
74
+ value: function dragEnd(event, entity) {
75
+ // let campus = STORE.get('active.ter.campus');
76
+ delete entity._drag; // ACTIONS.saveTerEntityPosition(campus, entity);
77
+ }
78
+ }, {
79
+ key: "addMoveEvents",
80
+ value: function addMoveEvents(body) {
81
+ var _this = this;
82
+
83
+ return body.call(d3.drag().on("start", function (e, d) {
84
+ return _this.dragStart(e, d);
85
+ }).on("drag", function (e, d) {
86
+ return _this.dragged(e, d);
87
+ }).on("end", function (e, d) {
88
+ return _this.dragEnd(e, d);
89
+ }));
90
+ }
91
+ }, {
92
+ key: "moveEntity",
93
+ value: function moveEntity(entity) {
94
+ var selection = this.foreground().selectAll('g.entity').data([entity], function (d) {
95
+ return d._id;
96
+ });
97
+ selection.attr('transform', function (d) {
98
+ return 'translate(' + d.position.x + ',' + d.position.y + ')';
99
+ });
100
+ }
101
+ }, {
102
+ key: "moveEdges",
103
+ value: function moveEdges(entity) {
104
+ var edges = entity.ports.items.list.map(function (p) {
105
+ return p._relationship;
106
+ });
107
+ var selection = this.background().selectAll('line.connector').data(edges, function (d) {
108
+ return d._id;
109
+ }); // TODO: ここは分離したいな。
110
+
111
+ this._parent.relationships().drawRelationshipsCore(selection);
112
+ }
113
+ /* **************************************************************** *
114
+ * Draw this.entity
115
+ * **************************************************************** */
116
+
117
+ }, {
118
+ key: "drawGroup",
119
+ value: function drawGroup(entities) {
120
+ return this.foreground().selectAll('g.entity').data(entities, function (d) {
121
+ return d._id;
122
+ }).enter().append('g').attr('class', 'entity').attr('entity-id', function (d) {
123
+ return d._id;
124
+ }).attr('entity-code', function (d) {
125
+ return d._core.type;
126
+ }).attr('entity-type', function (d) {
127
+ return d._class;
128
+ }).attr("transform", function (d) {
129
+ return "translate(" + d.position.x + "," + d.position.y + ")";
130
+ });
131
+ }
132
+ /* ************************************ *
133
+ * Body *
134
+ * ************************************ */
135
+
136
+ }, {
137
+ key: "drawBodyCore",
138
+ value: function drawBodyCore(body) {
139
+ body.attr('class', 'entity-body').attr('width', function (d) {
140
+ return d.size.w;
141
+ }).attr('height', function (d) {
142
+ return d.size.h;
143
+ }).attr('rx', function (d) {
144
+ return 5;
145
+ }).attr('ry', function (d) {
146
+ return 5;
147
+ }).attr('fill', function (d) {
148
+ return d.background.color;
149
+ });
150
+ }
151
+ }, {
152
+ key: "drawBody",
153
+ value: function drawBody(groups) {
154
+ var body = groups.append('rect');
155
+ this.drawBodyCore(body);
156
+ return body;
157
+ }
158
+ /* ************************************ *
159
+ * Name *
160
+ * ************************************ */
161
+
162
+ }, {
163
+ key: "drawNameRect",
164
+ value: function drawNameRect(rects) {
165
+ rects.attr('x', function (d) {
166
+ return d.name.position.x;
167
+ }).attr('y', function (d) {
168
+ return d.name.position.y;
169
+ }).attr('width', function (d) {
170
+ return d.name.size.w;
171
+ }).attr('height', function (d) {
172
+ return d.name.size.h;
173
+ }).attr('rx', function (d) {
174
+ return 3;
175
+ }).attr('ry', function (d) {
176
+ return 3;
177
+ }).attr('fill', function (d) {
178
+ return d.background.color;
179
+ });
180
+ }
181
+ }, {
182
+ key: "drawNameText",
183
+ value: function drawNameText(texts) {
184
+ var _this2 = this;
185
+
186
+ texts.attr('class', 'entity-title').attr("x", function (d) {
187
+ return d.padding + d.name.padding;
188
+ }).attr("y", function (d) {
189
+ return d.padding + d.name.padding + _this2["default"]().line.font.size;
190
+ }).attr("fill", function (d) {
191
+ return '#fff';
192
+ }).attr("font-size", function (d) {
193
+ return 24;
194
+ }).text(function (d) {
195
+ return d.name.val();
196
+ });
197
+ this.addMoveEvents(texts);
198
+ return texts;
199
+ }
200
+ }, {
201
+ key: "drawName",
202
+ value: function drawName(groups) {
203
+ var callbacks = this.callbacks();
204
+ var rects = groups.append('rect').on("click", function (event, d) {
205
+ var func = callbacks.entity.click;
206
+ if (func) func(d);
207
+ }).attr('class', 'entity-title');
208
+ this.drawNameRect(rects);
209
+ var texts = groups.append('text').on("click", function (event, d) {
210
+ var func = callbacks.entity.click;
211
+ if (func) func(d);
212
+ }).attr('class', 'entity-title');
213
+ this.drawNameText(texts).each(function (d) {
214
+ if (!d._max) d._max_w = {
215
+ name: 0,
216
+ identifier: 0,
217
+ attribute: 0
218
+ };
219
+ var w = this.getBBox().width;
220
+ if (w > d._max_w.name) d._max_w.name = w;
221
+ });
222
+ }
223
+ /* ************************************ *
224
+ * Type *
225
+ * ************************************ */
226
+
227
+ }, {
228
+ key: "drawTypeRect",
229
+ value: function drawTypeRect(selection) {
230
+ selection.attr('x', function (d) {
231
+ return d.type.position.x;
232
+ }).attr('y', function (d) {
233
+ return d.type.position.y;
234
+ }).attr('width', function (d) {
235
+ return d.type.size.w;
236
+ }).attr('height', function (d) {
237
+ return d.type.size.h;
238
+ }).attr('rx', function (d) {
239
+ return 3;
240
+ }).attr('ry', function (d) {
241
+ return 3;
242
+ }).attr('fill', function (d) {
243
+ return d.background.color;
244
+ });
245
+ }
246
+ }, {
247
+ key: "drawTypeText",
248
+ value: function drawTypeText(selection) {
249
+ var _this3 = this;
250
+
251
+ return selection.attr("x", function (d) {
252
+ return d.padding + d.name.size.w + 11 + d.type.padding;
253
+ }).attr("y", function (d) {
254
+ return d.type.position.y + d.type.padding + _this3["default"]().line.font.size;
255
+ }).attr("fill", function (d) {
256
+ return '#fff';
257
+ }).text(function (d) {
258
+ return d.type.contents;
259
+ });
260
+ }
261
+ }, {
262
+ key: "drawType",
263
+ value: function drawType(groups) {
264
+ var rects = groups.append('rect').attr('class', 'entity-type');
265
+ this.drawTypeRect(rects);
266
+ var texts = groups.append('text').attr('class', 'entity-type');
267
+ this.drawTypeText(texts).each(function (d) {
268
+ var w = this.getBBox().width;
269
+ if (w > (d.type._max_w || 0)) d.type._max_w = w;
270
+ });
271
+ }
272
+ /* ************************************ *
273
+ * Identifiers *
274
+ * ************************************ */
275
+
276
+ }, {
277
+ key: "drawIdentifiersRect",
278
+ value: function drawIdentifiersRect(rects) {
279
+ rects.attr('x', function (d) {
280
+ return d.identifiers.position.x;
281
+ }).attr('y', function (d) {
282
+ return d.identifiers.position.y;
283
+ }).attr('width', function (d) {
284
+ return d.identifiers.size.w;
285
+ }).attr('height', function (d) {
286
+ return d.identifiers.size.h;
287
+ }).attr('rx', function (d) {
288
+ return 2;
289
+ }).attr('ry', function (d) {
290
+ return 2;
291
+ }).attr('fill', function (d) {
292
+ return d.identifiers.background.color;
293
+ });
294
+ }
295
+ }, {
296
+ key: "drawIdentifiersText",
297
+ value: function drawIdentifiersText(texts) {
298
+ return texts.attr("x", function (d) {
299
+ return d.position.x;
300
+ }).attr("y", function (d) {
301
+ return d.position.y;
302
+ }).text(function (d) {
303
+ return d.name.val();
304
+ });
305
+ }
306
+ }, {
307
+ key: "drawIdentifiers",
308
+ value: function drawIdentifiers(groups) {
309
+ var rects = groups.append('rect').attr('class', 'entity-identifiers');
310
+ this.drawIdentifiersRect(rects);
311
+ var texts = groups.selectAll('text.identifier').data(function (d) {
312
+ return d.identifiers.contents.list;
313
+ }).enter().append('text').attr('class', 'identifier').attr('identifier-id', function (d) {
314
+ return d._id;
315
+ });
316
+ this.drawIdentifiersText(texts).each(function (identifier) {
317
+ var w = this.getBBox().width;
318
+ if (w > identifier._entity._max_w.identifier) identifier._entity._max_w.identifier = w;
319
+ });
320
+ }
321
+ /* ************************************ *
322
+ * Attributes *
323
+ * ************************************ */
324
+
325
+ }, {
326
+ key: "drawAttributesRect",
327
+ value: function drawAttributesRect(rects) {
328
+ rects.attr('x', function (d) {
329
+ return d.attributes.position.x;
330
+ }).attr('y', function (d) {
331
+ return d.attributes.position.y;
332
+ }).attr('width', function (d) {
333
+ return d.attributes.size.w;
334
+ }).attr('height', function (d) {
335
+ return d.attributes.size.h;
336
+ }).attr('rx', function (d) {
337
+ return 3;
338
+ }).attr('ry', function (d) {
339
+ return 3;
340
+ }).attr('fill', function (d) {
341
+ return d.identifiers.background.color;
342
+ });
343
+ }
344
+ }, {
345
+ key: "drawAttributesText",
346
+ value: function drawAttributesText(texts) {
347
+ return texts.attr("x", function (d) {
348
+ return d.position.x;
349
+ }).attr("y", function (d) {
350
+ return d.position.y;
351
+ }).text(function (d) {
352
+ return d.name.val();
353
+ });
354
+ }
355
+ }, {
356
+ key: "drawAttributes",
357
+ value: function drawAttributes(groups) {
358
+ var rects = groups.append('rect').attr('class', 'entity-attributes');
359
+ this.drawAttributesRect(rects);
360
+ var texts = groups.selectAll('text.attribute').data(function (d) {
361
+ return d.attributes.contents.list;
362
+ }).enter().append('text').attr('class', 'attribute').attr('attribute-id', function (d) {
363
+ return d._id;
364
+ });
365
+ this.drawAttributesText(texts).each(function (attribute) {
366
+ var w = this.getBBox().width;
367
+ if (w > attribute._entity._max_w.attribute) attribute._entity._max_w.attribute = w;
368
+ });
369
+ }
370
+ /* ************************************ *
371
+ * Main
372
+ * ************************************ */
373
+
374
+ }, {
375
+ key: "redraw",
376
+ value: function redraw(groups) {
377
+ this.drawBodyCore(groups.selectAll('rect.entity-body'));
378
+ this.drawNameRect(groups.selectAll('rect.entity-title'));
379
+ this.drawNameText(groups.selectAll('text.entity-title'));
380
+ this.drawTypeRect(groups.selectAll('rect.entity-type'));
381
+ this.drawTypeText(groups.selectAll('text.entity-type'));
382
+ this.drawIdentifiersRect(groups.selectAll('rect.entity-identifiers'));
383
+ this.drawIdentifiersText(groups.selectAll('text.identifier'));
384
+ this.drawAttributesRect(groups.selectAll('rect.entity-attributes'));
385
+ this.drawAttributesText(groups.selectAll('text.attribute'));
386
+ }
387
+ }, {
388
+ key: "draw",
389
+ value: function draw(entities) {
390
+ var groups = this.drawGroup(entities);
391
+ this.drawBody(groups);
392
+ this.drawName(groups);
393
+ this.drawType(groups);
394
+ this.drawIdentifiers(groups);
395
+ this.drawAttributes(groups); // resizing & redraw
396
+
397
+ groups.each(function (entity) {
398
+ return entity.reSizing().positioning();
399
+ });
400
+ this.redraw(groups);
401
+ return groups;
402
+ }
403
+ }]);
404
+
405
+ return Entity;
406
+ }();
407
+
408
+ exports["default"] = Entity;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var d3 = _interopRequireWildcard(require("d3"));
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ 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); } }
19
+
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
+
22
+ var Ports = /*#__PURE__*/function () {
23
+ function Ports() {
24
+ _classCallCheck(this, Ports);
25
+ }
26
+
27
+ _createClass(Ports, [{
28
+ key: "drawPortsCore",
29
+ value: // protected
30
+ function drawPortsCore(ports) {
31
+ ports.attr('class', 'entity-port').attr('cx', function (d) {
32
+ return d.position.x;
33
+ }).attr('cy', function (d) {
34
+ return d.position.y;
35
+ }).attr('r', 4).attr('fill', '#fff').attr('stroke', '#000').attr('stroke-width', 0.5).attr('degree', function (d) {
36
+ return d._owner._core.position || 0;
37
+ }).attr('port-id', function (d) {
38
+ return d._id;
39
+ });
40
+ } // public
41
+
42
+ }, {
43
+ key: "drawPorts",
44
+ value: function drawPorts(groups) {
45
+ var ports = groups.selectAll('circle.entity-port').data(function (d) {
46
+ return d.ports.items.list;
47
+ }).enter().append('circle');
48
+ this.drawPortsCore(ports);
49
+ }
50
+ }]);
51
+
52
+ return Ports;
53
+ }();
54
+
55
+ exports["default"] = Ports;
@@ -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;