@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.
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports["default"] = void 0;
9
7
 
10
- var d3 = _interopRequireWildcard(require("d3"));
8
+ var _Ports = _interopRequireDefault(require("./Painters/Ports.js"));
9
+
10
+ var _Relationships = _interopRequireDefault(require("./Painters/Relationships.js"));
11
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); }
12
+ var _Entity = _interopRequireDefault(require("./Painters/Entity.js"));
13
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; }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
15
 
16
16
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
17
 
@@ -34,422 +34,42 @@ var Painter = /*#__PURE__*/function () {
34
34
  }
35
35
  }
36
36
  };
37
+ this._painters = {
38
+ ports: new _Ports["default"](),
39
+ relationships: new _Relationships["default"](),
40
+ entity: new _Entity["default"](this)
41
+ };
37
42
  }
38
- /* **************************************************************** *
39
- * Move
40
- * **************************************************************** */
41
-
42
43
 
43
44
  _createClass(Painter, [{
44
- key: "dragStart",
45
- value: function dragStart(event, entity) {
46
- entity._drag = {
47
- start: {
48
- x: event.x,
49
- y: event.y
50
- }
51
- };
52
- }
53
- }, {
54
- key: "dragged",
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);
60
- }
61
- }, {
62
- key: "dragEnd",
63
- value: function dragEnd(event, entity) {
64
- // let campus = STORE.get('active.ter.campus');
65
- delete entity._drag; // ACTIONS.saveTerEntityPosition(campus, entity);
66
- }
67
- }, {
68
- key: "addMoveEvents",
69
- value: function addMoveEvents(body) {
70
- var _this = this;
71
-
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);
78
- }));
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
- }
101
- /* **************************************************************** *
102
- * Draw this.entity
103
- * **************************************************************** */
104
-
105
- }, {
106
- key: "drawGroup",
107
- value: function drawGroup(data) {
108
- return this.foreground.selectAll('g.entity').data(data, function (d) {
109
- return d._id;
110
- }).enter().append('g').attr('class', 'entity').attr('entity-id', function (d) {
111
- return d._id;
112
- }).attr('entity-code', function (d) {
113
- return d._core.type;
114
- }).attr('entity-type', function (d) {
115
- return d._class;
116
- }).attr("transform", function (d) {
117
- return "translate(" + d.position.x + "," + d.position.y + ")";
118
- });
119
- }
120
- /* ************************************ *
121
- * Body *
122
- * ************************************ */
123
-
124
- }, {
125
- key: "drawBodyCore",
126
- value: function drawBodyCore(body) {
127
- body.attr('class', 'entity-body').attr('width', function (d) {
128
- return d.size.w;
129
- }).attr('height', function (d) {
130
- return d.size.h;
131
- }).attr('rx', function (d) {
132
- return 5;
133
- }).attr('ry', function (d) {
134
- return 5;
135
- }).attr('fill', function (d) {
136
- return d.background.color;
137
- });
138
- }
139
- }, {
140
- key: "drawBody",
141
- value: function drawBody(groups) {
142
- var body = groups.append('rect');
143
- this.drawBodyCore(body);
144
- return body;
145
- }
146
- /* ************************************ *
147
- * Name *
148
- * ************************************ */
149
-
150
- }, {
151
- key: "drawNameRect",
152
- value: function drawNameRect(rects) {
153
- rects.attr('x', function (d) {
154
- return d.name.position.x;
155
- }).attr('y', function (d) {
156
- return d.name.position.y;
157
- }).attr('width', function (d) {
158
- return d.name.size.w;
159
- }).attr('height', function (d) {
160
- return d.name.size.h;
161
- }).attr('rx', function (d) {
162
- return 3;
163
- }).attr('ry', function (d) {
164
- return 3;
165
- }).attr('fill', function (d) {
166
- return d.background.color;
167
- });
168
- }
169
- }, {
170
- key: "drawNameText",
171
- value: function drawNameText(texts) {
172
- var _this2 = this;
173
-
174
- texts.attr('class', 'entity-title').attr("x", function (d) {
175
- return d.padding + d.name.padding;
176
- }).attr("y", function (d) {
177
- return d.padding + d.name.padding + _this2._default.line.font.size;
178
- }).attr("fill", function (d) {
179
- return '#fff';
180
- }).attr("font-size", function (d) {
181
- return 24;
182
- }).text(function (d) {
183
- return d.name.val();
184
- });
185
- this.addMoveEvents(texts);
186
- return texts;
187
- }
188
- }, {
189
- key: "drawName",
190
- value: function drawName(groups) {
191
- var callbacks = this.callbacks;
192
- var rects = groups.append('rect').on("click", function (event, d) {
193
- var func = callbacks.entity.click;
194
- if (func) func(d);
195
- }).attr('class', 'entity-title');
196
- this.drawNameRect(rects);
197
- var texts = groups.append('text').on("click", function (event, d) {
198
- var func = callbacks.entity.click;
199
- if (func) func(d);
200
- }).attr('class', 'entity-title');
201
- this.drawNameText(texts).each(function (d) {
202
- if (!d._max) d._max_w = {
203
- name: 0,
204
- identifier: 0,
205
- attribute: 0
206
- };
207
- var w = this.getBBox().width;
208
- if (w > d._max_w.name) d._max_w.name = w;
209
- });
210
- }
211
- /* ************************************ *
212
- * Type *
213
- * ************************************ */
214
-
215
- }, {
216
- key: "drawTypeRect",
217
- value: function drawTypeRect(selection) {
218
- selection.attr('x', function (d) {
219
- return d.type.position.x;
220
- }).attr('y', function (d) {
221
- return d.type.position.y;
222
- }).attr('width', function (d) {
223
- return d.type.size.w;
224
- }).attr('height', function (d) {
225
- return d.type.size.h;
226
- }).attr('rx', function (d) {
227
- return 3;
228
- }).attr('ry', function (d) {
229
- return 3;
230
- }).attr('fill', function (d) {
231
- return d.background.color;
232
- });
45
+ key: "ports",
46
+ value: function ports() {
47
+ return this._painters.ports;
233
48
  }
234
49
  }, {
235
- key: "drawTypeText",
236
- value: function drawTypeText(selection) {
237
- var _this3 = this;
238
-
239
- return selection.attr("x", function (d) {
240
- return d.padding + d.name.size.w + 11 + d.type.padding;
241
- }).attr("y", function (d) {
242
- return d.type.position.y + d.type.padding + _this3._default.line.font.size;
243
- }).attr("fill", function (d) {
244
- return '#fff';
245
- }).text(function (d) {
246
- return d.type.contents;
247
- });
50
+ key: "relationships",
51
+ value: function relationships() {
52
+ return this._painters.relationships;
248
53
  }
249
54
  }, {
250
- key: "drawType",
251
- value: function drawType(groups) {
252
- var rects = groups.append('rect').attr('class', 'entity-type');
253
- this.drawTypeRect(rects);
254
- var texts = groups.append('text').attr('class', 'entity-type');
255
- this.drawTypeText(texts).each(function (d) {
256
- var w = this.getBBox().width;
257
- if (w > (d.type._max_w || 0)) d.type._max_w = w;
258
- });
55
+ key: "entity",
56
+ value: function entity() {
57
+ return this._painters.entity;
259
58
  }
260
59
  /* ************************************ *
261
- * Identifiers *
262
- * ************************************ */
263
-
264
- }, {
265
- key: "drawIdentifiersRect",
266
- value: function drawIdentifiersRect(rects) {
267
- rects.attr('x', function (d) {
268
- return d.identifiers.position.x;
269
- }).attr('y', function (d) {
270
- return d.identifiers.position.y;
271
- }).attr('width', function (d) {
272
- return d.identifiers.size.w;
273
- }).attr('height', function (d) {
274
- return d.identifiers.size.h;
275
- }).attr('rx', function (d) {
276
- return 2;
277
- }).attr('ry', function (d) {
278
- return 2;
279
- }).attr('fill', function (d) {
280
- return d.identifiers.background.color;
281
- });
282
- }
283
- }, {
284
- key: "drawIdentifiersText",
285
- value: function drawIdentifiersText(texts) {
286
- return texts.attr("x", function (d) {
287
- return d.position.x;
288
- }).attr("y", function (d) {
289
- return d.position.y;
290
- }).text(function (d) {
291
- return d.name.val();
292
- });
293
- }
294
- }, {
295
- key: "drawIdentifiers",
296
- value: function drawIdentifiers(groups) {
297
- var rects = groups.append('rect').attr('class', 'entity-identifiers');
298
- this.drawIdentifiersRect(rects);
299
- var texts = groups.selectAll('text.identifier').data(function (d) {
300
- return d.identifiers.contents.list;
301
- }).enter().append('text').attr('class', 'identifier').attr('identifier-id', function (d) {
302
- return d._id;
303
- });
304
- this.drawIdentifiersText(texts).each(function (identifier) {
305
- var w = this.getBBox().width;
306
- if (w > identifier._entity._max_w.identifier) identifier._entity._max_w.identifier = w;
307
- });
308
- }
309
- /* ************************************ *
310
- * Attributes *
311
- * ************************************ */
312
-
313
- }, {
314
- key: "drawAttributesRect",
315
- value: function drawAttributesRect(rects) {
316
- rects.attr('x', function (d) {
317
- return d.attributes.position.x;
318
- }).attr('y', function (d) {
319
- return d.attributes.position.y;
320
- }).attr('width', function (d) {
321
- return d.attributes.size.w;
322
- }).attr('height', function (d) {
323
- return d.attributes.size.h;
324
- }).attr('rx', function (d) {
325
- return 3;
326
- }).attr('ry', function (d) {
327
- return 3;
328
- }).attr('fill', function (d) {
329
- return d.identifiers.background.color;
330
- });
331
- }
332
- }, {
333
- key: "drawAttributesText",
334
- value: function drawAttributesText(texts) {
335
- return texts.attr("x", function (d) {
336
- return d.position.x;
337
- }).attr("y", function (d) {
338
- return d.position.y;
339
- }).text(function (d) {
340
- return d.name.val();
341
- });
342
- }
343
- }, {
344
- key: "drawAttributes",
345
- value: function drawAttributes(groups) {
346
- var rects = groups.append('rect').attr('class', 'entity-attributes');
347
- this.drawAttributesRect(rects);
348
- var texts = groups.selectAll('text.attribute').data(function (d) {
349
- return d.attributes.contents.list;
350
- }).enter().append('text').attr('class', 'attribute').attr('attribute-id', function (d) {
351
- return d._id;
352
- });
353
- this.drawAttributesText(texts).each(function (attribute) {
354
- var w = this.getBBox().width;
355
- if (w > attribute._entity._max_w.attribute) attribute._entity._max_w.attribute = w;
356
- });
357
- }
358
- /* ************************************ *
359
- * Port *
360
- * ************************************ */
361
-
362
- }, {
363
- key: "drawPortsCore",
364
- value: function drawPortsCore(ports) {
365
- ports.attr('class', 'entity-port').attr('cx', function (d) {
366
- return d.position.x;
367
- }).attr('cy', function (d) {
368
- return d.position.y;
369
- }).attr('r', 4).attr('fill', '#fff').attr('stroke', '#000').attr('stroke-width', 0.5).attr('degree', function (d) {
370
- return d._owner._core.position || 0;
371
- }).attr('port-id', function (d) {
372
- return d._id;
373
- });
374
- }
375
- }, {
376
- key: "drawPorts",
377
- value: function drawPorts(groups) {
378
- var ports = groups.selectAll('circle.entity-port').data(function (d) {
379
- return d.ports.items.list;
380
- }).enter().append('circle');
381
- this.drawPortsCore(ports);
382
- }
383
- /* ************************************ *
384
- * relationships *
60
+ * Draw Main *
385
61
  * ************************************ */
386
62
 
387
- }, {
388
- key: "drawRelationshipsCore",
389
- value: function drawRelationshipsCore(edges) {
390
- edges.attr('x1', function (d) {
391
- var port = d.from;
392
- var entity = d.from._entity;
393
- return port.position.x + entity.position.x;
394
- }).attr('y1', function (d) {
395
- var port = d.from;
396
- var entity = d.from._entity;
397
- return port.position.y + entity.position.y;
398
- }).attr('x2', function (d) {
399
- var port = d.to;
400
- var entity = d.to._entity;
401
- return port.position.x + entity.position.x;
402
- }).attr('y2', function (d) {
403
- var port = d.to;
404
- var entity = d.to._entity;
405
- return port.position.y + entity.position.y;
406
- }).attr('stroke', '#888888').attr('stroke-width', 1);
407
- }
408
- }, {
409
- key: "drawRelationships",
410
- value: function drawRelationships(relationships) {
411
- var place = this.background;
412
- var data = relationships.list.filter(function (edge) {
413
- return edge.from._class === 'PORT-FROM' && edge.to._class === 'PORT-TO';
414
- });
415
- var edges = place.selectAll('line.connector').data(data, function (d) {
416
- return d._id;
417
- }).enter().append('line').attr('class', 'connector');
418
- this.drawRelationshipsCore(edges);
419
- }
420
63
  /* ************************************ *
421
64
  * Draw Main *
422
65
  * ************************************ */
423
66
 
424
- }, {
425
- key: "redraw",
426
- value: function redraw(groups) {
427
- this.drawBodyCore(groups.selectAll('rect.entity-body'));
428
- this.drawNameRect(groups.selectAll('rect.entity-title'));
429
- this.drawNameText(groups.selectAll('text.entity-title'));
430
- this.drawTypeRect(groups.selectAll('rect.entity-type'));
431
- this.drawTypeText(groups.selectAll('text.entity-type'));
432
- this.drawIdentifiersRect(groups.selectAll('rect.entity-identifiers'));
433
- this.drawIdentifiersText(groups.selectAll('text.identifier'));
434
- this.drawAttributesRect(groups.selectAll('rect.entity-attributes'));
435
- this.drawAttributesText(groups.selectAll('text.attribute'));
436
- }
437
67
  }, {
438
68
  key: "draw",
439
69
  value: function draw(entities, relationsihps) {
440
- var groups = this.drawGroup(entities.list);
441
- this.drawBody(groups);
442
- this.drawName(groups);
443
- this.drawType(groups);
444
- this.drawIdentifiers(groups);
445
- this.drawAttributes(groups); // resizing & redraw
446
-
447
- groups.each(function (entity) {
448
- return entity.reSizing().positioning();
449
- });
450
- this.redraw(groups);
451
- this.drawPorts(groups);
452
- this.drawRelationships(relationsihps);
70
+ var groups = this.entity().draw(entities.list);
71
+ this.ports().drawPorts(groups);
72
+ this.relationships().drawRelationships(this.background, relationsihps);
453
73
  }
454
74
  }]);
455
75