@yanqirenshi/d3.ter 0.0.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,430 @@
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
+ var _Pool = _interopRequireDefault(require("./Pool.js"));
13
+
14
+ var _EntityTailor2 = _interopRequireDefault(require("./EntityTailor.js"));
15
+
16
+ var _IdentifierInstance = _interopRequireDefault(require("./IdentifierInstance.js"));
17
+
18
+ var _AttributeInstance = _interopRequireDefault(require("./AttributeInstance.js"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
+
22
+ 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); }
23
+
24
+ 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; }
25
+
26
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
27
+
28
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
29
+
30
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
31
+
32
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
+
34
+ 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); } }
35
+
36
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
37
+
38
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
39
+
40
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
+
42
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
43
+
44
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
45
+
46
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
47
+
48
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
49
+
50
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
51
+
52
+ var Entity = /*#__PURE__*/function (_EntityTailor) {
53
+ _inherits(Entity, _EntityTailor);
54
+
55
+ var _super = _createSuper(Entity);
56
+
57
+ function Entity() {
58
+ var _this;
59
+
60
+ _classCallCheck(this, Entity);
61
+
62
+ _this = _super.call(this);
63
+ _this.attribute_instance = new _AttributeInstance["default"]();
64
+ _this.identifier_instance = new _IdentifierInstance["default"]();
65
+ _this._default = {
66
+ line: {
67
+ height: 14,
68
+ font: {
69
+ size: 14
70
+ }
71
+ }
72
+ };
73
+ return _this;
74
+ }
75
+ /* **************************************************************** *
76
+ *
77
+ * **************************************************************** */
78
+
79
+
80
+ _createClass(Entity, [{
81
+ key: "list2pool",
82
+ value: function list2pool(list, f) {
83
+ return new _Pool["default"]().list2pool(list, f);
84
+ }
85
+ }, {
86
+ key: "getIdentifier",
87
+ value: function getIdentifier(id, entities) {
88
+ var _iterator = _createForOfIteratorHelper(entities.list),
89
+ _step;
90
+
91
+ try {
92
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
93
+ var entity = _step.value;
94
+ if (entity.identifiers.contents.ht[id]) return entity.identifiers.contents.ht[id];
95
+ }
96
+ } catch (err) {
97
+ _iterator.e(err);
98
+ } finally {
99
+ _iterator.f();
100
+ }
101
+
102
+ return null;
103
+ }
104
+ /* **************************************************************** *
105
+ * Move
106
+ * **************************************************************** */
107
+
108
+ }, {
109
+ key: "dragStart",
110
+ value: function dragStart(d) {
111
+ console.log(d); // let e = d3.event;
112
+ // d._drag = {
113
+ // start: {
114
+ // x: e.x,
115
+ // y: e.y,
116
+ // }
117
+ // };
118
+ }
119
+ }, {
120
+ key: "dragged",
121
+ value: function dragged(d) {// let e = d3.event;
122
+ // d.position.x += e.x - d._drag.start.x;
123
+ // d.position.y += e.y - d._drag.start.y;
124
+ // this.moveEntity(d);
125
+ }
126
+ }, {
127
+ key: "dragEnd",
128
+ value: function dragEnd(entity) {// let campus = STORE.get('active.ter.campus');
129
+ // delete entity._drag;
130
+ // ACTIONS.saveTerEntityPosition(campus, entity);
131
+ }
132
+ }, {
133
+ key: "addMoveEvents2Body",
134
+ value: function addMoveEvents2Body(body) {
135
+ var _this2 = this;
136
+
137
+ return body.call(d3.drag().on("start", function (d) {
138
+ console.log(d);
139
+ return _this2.dragStart(d);
140
+ }).on("drag", function (d) {
141
+ return _this2.dragged(d);
142
+ }).on("end", function (d) {
143
+ return _this2.dragEnd(d);
144
+ }));
145
+ }
146
+ /* **************************************************************** *
147
+ * Draw this.entity
148
+ * **************************************************************** */
149
+
150
+ }, {
151
+ key: "drawGroup",
152
+ value: function drawGroup(place, data) {
153
+ return place.selectAll('g.entity').data(data, function (d) {
154
+ return d._id;
155
+ }).enter().append('g').attr('class', 'entity').attr('entity-id', function (d) {
156
+ return d._id;
157
+ }).attr('entity-code', function (d) {
158
+ return d._core.type;
159
+ }).attr('entity-type', function (d) {
160
+ return d._class;
161
+ }).attr("transform", function (d) {
162
+ return "translate(" + d.position.x + "," + d.position.y + ")";
163
+ });
164
+ }
165
+ /* ************************************ *
166
+ * Body *
167
+ * ************************************ */
168
+
169
+ }, {
170
+ key: "drawBodyCore",
171
+ value: function drawBodyCore(body) {
172
+ body.attr('class', 'entity-body').attr('width', function (d) {
173
+ return d.size.w;
174
+ }).attr('height', function (d) {
175
+ return d.size.h;
176
+ }).attr('fill', function (d) {
177
+ return d.background.color;
178
+ });
179
+ }
180
+ }, {
181
+ key: "drawBody",
182
+ value: function drawBody(groups) {
183
+ var body = groups.append('rect');
184
+ this.drawBodyCore(body);
185
+ return this.addMoveEvents2Body(body);
186
+ }
187
+ /* ************************************ *
188
+ * Name *
189
+ * ************************************ */
190
+
191
+ }, {
192
+ key: "drawNameRect",
193
+ value: function drawNameRect(rects) {
194
+ rects.attr('x', function (d) {
195
+ return d.name.position.x;
196
+ }).attr('y', function (d) {
197
+ return d.name.position.y;
198
+ }).attr('width', function (d) {
199
+ return d.name.size.w;
200
+ }).attr('height', function (d) {
201
+ return d.name.size.h;
202
+ }).attr('fill', function (d) {
203
+ return '#ffffff';
204
+ });
205
+ }
206
+ }, {
207
+ key: "drawNameText",
208
+ value: function drawNameText(texts) {
209
+ var _this3 = this;
210
+
211
+ return texts.attr('class', 'entity-title').attr("x", function (d) {
212
+ return d.padding + d.name.padding;
213
+ }).attr("y", function (d) {
214
+ return d.padding + d.name.padding + _this3._default.line.font.size;
215
+ }).text(function (d) {
216
+ return d.name.contents.logical;
217
+ });
218
+ }
219
+ }, {
220
+ key: "drawName",
221
+ value: function drawName(groups, callbacks) {
222
+ var rects = groups.append('rect').on("click", function (d) {
223
+ var func = callbacks.entity.click;
224
+ if (func) func(d);
225
+ }).attr('class', 'entity-title');
226
+ this.drawNameRect(rects);
227
+ var texts = groups.append('text').on("click", function (d) {
228
+ var func = callbacks.entity.click;
229
+ if (func) func(d);
230
+ }).attr('class', 'entity-title');
231
+ this.drawNameText(texts).each(function (d) {
232
+ if (!d._max) d._max_w = {
233
+ name: 0,
234
+ identifier: 0,
235
+ attribute: 0
236
+ };
237
+ var w = this.getBBox().width;
238
+ if (w > d._max_w.name) d._max_w.name = w;
239
+ });
240
+ }
241
+ /* ************************************ *
242
+ * Type *
243
+ * ************************************ */
244
+
245
+ }, {
246
+ key: "drawTypeRect",
247
+ value: function drawTypeRect(selection) {
248
+ selection.attr('x', function (d) {
249
+ return d.type.position.x;
250
+ }).attr('y', function (d) {
251
+ return d.type.position.y;
252
+ }).attr('width', function (d) {
253
+ return d.type.size.w;
254
+ }).attr('height', function (d) {
255
+ return d.type.size.h;
256
+ }).attr('fill', function (d) {
257
+ return '#ffffff';
258
+ });
259
+ }
260
+ }, {
261
+ key: "drawTypeText",
262
+ value: function drawTypeText(selection) {
263
+ var _this4 = this;
264
+
265
+ selection.attr("x", function (d) {
266
+ return d.padding + d.name.size.w + 11 + d.type.padding;
267
+ }).attr("y", function (d) {
268
+ return d.type.position.y + d.type.padding + _this4._default.line.font.size;
269
+ }).text(function (d) {
270
+ return d.type.contents;
271
+ });
272
+ }
273
+ }, {
274
+ key: "drawType",
275
+ value: function drawType(groups) {
276
+ var rects = groups.append('rect').attr('class', 'entity-type');
277
+ this.drawTypeRect(rects);
278
+ var texts = groups.append('text').attr('class', 'entity-type');
279
+ this.drawTypeText(texts);
280
+ }
281
+ /* ************************************ *
282
+ * Identifiers *
283
+ * ************************************ */
284
+
285
+ }, {
286
+ key: "drawIdentifiersRect",
287
+ value: function drawIdentifiersRect(rects) {
288
+ rects.attr('x', function (d) {
289
+ return d.identifiers.position.x;
290
+ }).attr('y', function (d) {
291
+ return d.identifiers.position.y;
292
+ }).attr('width', function (d) {
293
+ return d.identifiers.size.w;
294
+ }).attr('height', function (d) {
295
+ return d.identifiers.size.h;
296
+ }).attr('fill', function (d) {
297
+ return d.identifiers.background.color;
298
+ });
299
+ }
300
+ }, {
301
+ key: "drawIdentifiersText",
302
+ value: function drawIdentifiersText(texts) {
303
+ return texts.attr("x", function (d) {
304
+ return d.position.x;
305
+ }).attr("y", function (d) {
306
+ return d.position.y;
307
+ }).text(function (d) {
308
+ return d.name.logical;
309
+ });
310
+ }
311
+ }, {
312
+ key: "drawIdentifiers",
313
+ value: function drawIdentifiers(groups) {
314
+ var rects = groups.append('rect').attr('class', 'entity-identifiers');
315
+ this.drawIdentifiersRect(rects);
316
+ var texts = groups.selectAll('text.identifier').data(function (d) {
317
+ return d.identifiers.contents.list;
318
+ }).enter().append('text').attr('class', 'identifier').attr('identifier-id', function (d) {
319
+ return d._id;
320
+ });
321
+ this.drawIdentifiersText(texts).each(function (identifier) {
322
+ var w = this.getBBox().width;
323
+ if (w > identifier._entity._max_w.identifier) identifier._entity._max_w.identifier = w;
324
+ });
325
+ }
326
+ /* ************************************ *
327
+ * Attributes *
328
+ * ************************************ */
329
+
330
+ }, {
331
+ key: "drawAttributesRect",
332
+ value: function drawAttributesRect(rects) {
333
+ rects.attr('x', function (d) {
334
+ return d.attributes.position.x;
335
+ }).attr('y', function (d) {
336
+ return d.attributes.position.y;
337
+ }).attr('width', function (d) {
338
+ return d.attributes.size.w;
339
+ }).attr('height', function (d) {
340
+ return d.attributes.size.h;
341
+ }).attr('fill', function (d) {
342
+ return d.identifiers.background.color;
343
+ });
344
+ }
345
+ }, {
346
+ key: "drawAttributesText",
347
+ value: function drawAttributesText(texts) {
348
+ return texts.attr("x", function (d) {
349
+ return d.position.x;
350
+ }).attr("y", function (d) {
351
+ return d.position.y;
352
+ }).text(function (d) {
353
+ return d.name.logical;
354
+ });
355
+ }
356
+ }, {
357
+ key: "drawAttributes",
358
+ value: function drawAttributes(groups) {
359
+ var rects = groups.append('rect').attr('class', 'entity-attributes');
360
+ this.drawAttributesRect(rects);
361
+ var texts = groups.selectAll('text.attribute').data(function (d) {
362
+ return d.attributes.contents.list;
363
+ }).enter().append('text').attr('class', 'attribute').attr('attribute-id', function (d) {
364
+ return d._id;
365
+ });
366
+ this.drawAttributesText(texts).each(function (attribute) {
367
+ var w = this.getBBox().width;
368
+ if (w > attribute._entity._max_w.attribute) attribute._entity._max_w.attribute = w;
369
+ });
370
+ }
371
+ /* ************************************ *
372
+ * Port *
373
+ * ************************************ */
374
+
375
+ }, {
376
+ key: "drawPortsCore",
377
+ value: function drawPortsCore(ports) {
378
+ ports.attr('class', 'entity-port').attr('cx', function (d) {
379
+ return d.position.x;
380
+ }).attr('cy', function (d) {
381
+ return d.position.y;
382
+ }).attr('r', 4).attr('fill', '#fff').attr('stroke', '#000').attr('stroke-width', 0.5).attr('degree', function (d) {
383
+ return d._idenrifier_instance._core.position || 0;
384
+ }).attr('port-id', function (d) {
385
+ return d._id;
386
+ });
387
+ }
388
+ }, {
389
+ key: "drawPorts",
390
+ value: function drawPorts(groups) {
391
+ var ports = groups.selectAll('circle.entity-port').data(function (d) {
392
+ return d.ports.items.list;
393
+ }).enter().append('circle');
394
+ this.drawPortsCore(ports);
395
+ }
396
+ /* ************************************ *
397
+ * Draw Main *
398
+ * ************************************ */
399
+
400
+ }, {
401
+ key: "redraw",
402
+ value: function redraw(groups) {
403
+ this.drawBodyCore(groups.selectAll('rect.entity-body'));
404
+ this.drawNameRect(groups.selectAll('rect.entity-title'));
405
+ this.drawNameText(groups.selectAll('text.entity-title'));
406
+ this.drawTypeRect(groups.selectAll('rect.entity-type'));
407
+ this.drawTypeText(groups.selectAll('text.entity-type'));
408
+ this.drawIdentifiersRect(groups.selectAll('rect.entity-identifiers'));
409
+ this.drawIdentifiersText(groups.selectAll('text.identifier'));
410
+ this.drawAttributesRect(groups.selectAll('rect.entity-attributes'));
411
+ this.drawAttributesText(groups.selectAll('text.attribute'));
412
+ }
413
+ }, {
414
+ key: "draw",
415
+ value: function draw(place, entities) {
416
+ var groups = this.drawGroup(place, entities.list);
417
+ this.drawBody(groups);
418
+ this.drawName(groups, this._callbacks);
419
+ this.drawType(groups);
420
+ this.drawIdentifiers(groups);
421
+ this.drawAttributes(groups);
422
+ this.reSizing(groups, entities);
423
+ this.drawPorts(groups);
424
+ }
425
+ }]);
426
+
427
+ return Entity;
428
+ }(_EntityTailor2["default"]);
429
+
430
+ exports["default"] = Entity;