@yanqirenshi/d3.deployment 0.0.7 → 0.2.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.
@@ -0,0 +1,307 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _assh0le = require("@yanqirenshi/assh0le");
9
+
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+
12
+ 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); } }
13
+
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
15
+
16
+ var Node = /*#__PURE__*/function () {
17
+ function Node() {
18
+ _classCallCheck(this, Node);
19
+
20
+ this.label = new _assh0le.Label();
21
+ this.rectangle = new _assh0le.Rectangle();
22
+ this.position = new _assh0le.Position();
23
+ this.stroke = new _assh0le.Stroke();
24
+ this.background = new _assh0le.Background();
25
+ this.padding = new _assh0le.Padding();
26
+ } ///// ////////////////////////////////////////////////////////////////
27
+ ///// Utility
28
+ ///// ////////////////////////////////////////////////////////////////
29
+
30
+
31
+ _createClass(Node, [{
32
+ key: "getFourSides",
33
+ value: function getFourSides(data) {
34
+ var port_r = 4;
35
+ var margin = 4 + port_r;
36
+ var x = data._position.x;
37
+ var y = data._position.y;
38
+ var w = data._size.w;
39
+ var h = data._size.h;
40
+ var top_left = {
41
+ x: x - margin,
42
+ y: y - margin
43
+ };
44
+ var top_right = {
45
+ x: x + w + margin,
46
+ y: y - margin
47
+ };
48
+ var bottom_rigth = {
49
+ x: x + w + margin,
50
+ y: y + h + margin
51
+ };
52
+ var bottom_left = {
53
+ x: x - margin,
54
+ y: y + h + margin
55
+ };
56
+ return [{
57
+ from: top_left,
58
+ to: top_right
59
+ }, {
60
+ from: top_right,
61
+ to: bottom_rigth
62
+ }, {
63
+ from: bottom_rigth,
64
+ to: bottom_left
65
+ }, {
66
+ from: bottom_left,
67
+ to: top_left
68
+ }];
69
+ } ///// ////////////////////////////////////////////////////////////////
70
+ ///// Adjust
71
+ ///// ////////////////////////////////////////////////////////////////
72
+
73
+ }, {
74
+ key: "dataTemplate",
75
+ value: function dataTemplate() {
76
+ return {
77
+ type: '',
78
+ label: {
79
+ contents: '',
80
+ position: {
81
+ x: 20,
82
+ y: 20
83
+ },
84
+ font: {
85
+ size: 16,
86
+ color: '#333333'
87
+ }
88
+ },
89
+ position: null,
90
+ size: null,
91
+ background: null,
92
+ border: null,
93
+ link: null,
94
+ children: [],
95
+ _id: null,
96
+ _core: null,
97
+ _class: 'NODE'
98
+ };
99
+ }
100
+ }, {
101
+ key: "normalizeBase",
102
+ value: function normalizeBase(data) {
103
+ var core = data._core;
104
+ if (core.id || core.id === 0) data._id = core.id;
105
+ if (core.type) data.type = core.type;
106
+ if (core.link) data.link = core.link;else data.link = {
107
+ url: null
108
+ };
109
+ }
110
+ }, {
111
+ key: "normalize",
112
+ value: function normalize(data) {
113
+ var _this = this;
114
+
115
+ if (!data) return null;
116
+ var new_data = this.dataTemplate();
117
+ new_data._core = data;
118
+ var children = data.children;
119
+ if (children && children.length > 0) new_data.children = children.map(function (child) {
120
+ return _this.normalize(child);
121
+ });
122
+ this.normalizeBase(new_data);
123
+ new_data.label = this.label.build(new_data._core.label);
124
+ new_data.size = this.rectangle.build(new_data._core.size);
125
+ new_data.position = this.position.build(new_data._core.position);
126
+ new_data.border = this.stroke.build(new_data._core.border) || this.stroke.template();
127
+ new_data.padding = this.padding.build(new_data._core.padding);
128
+ new_data.background = this.background.build(new_data._core.background);
129
+ data._node = new_data;
130
+ return new_data;
131
+ } ///// ////////////////////////////////////////////////////////////////
132
+ ///// Filter
133
+ ///// ////////////////////////////////////////////////////////////////
134
+
135
+ }, {
136
+ key: "addFilterShadow",
137
+ value: function addFilterShadow(svg) {
138
+ var filter = svg.append("defs").append("filter").attr("id", "drop-shadow").attr("height", "130%");
139
+ filter.append("feGaussianBlur").attr("in", "SourceAlpha").attr("stdDeviation", 5).attr("result", "blur");
140
+ filter.append("feOffset").attr("in", "blur").attr("dx", 5).attr("dy", 5).attr("result", "offsetBlur");
141
+ var feMerge = filter.append("feMerge");
142
+ feMerge.append("feMergeNode").attr("in", "offsetBlur");
143
+ feMerge.append("feMergeNode").attr("in", "SourceGraphic");
144
+ } ///// ////////////////////////////////////////////////////////////////
145
+ ///// Draw
146
+ ///// ////////////////////////////////////////////////////////////////
147
+
148
+ }, {
149
+ key: "drawGroup",
150
+ value: function drawGroup(place, data, type) {
151
+ return place.selectAll('g.' + type).data([data], function (d) {
152
+ return d._id;
153
+ }).enter().append('g').attr('class', type).attr("transform", function (d) {
154
+ return "translate(" + d._position.x + "," + d._position.y + ")";
155
+ }).attr('level', function (d) {
156
+ return d._level;
157
+ });
158
+ }
159
+ }, {
160
+ key: "drawBody",
161
+ value: function drawBody(groups) {
162
+ groups.append('rect').attr('class', 'node-body').attr('width', function (d) {
163
+ return d._size.w;
164
+ }).attr('height', function (d) {
165
+ return d._size.h;
166
+ }).attr('rx', function (d) {
167
+ return d.border && d.border.r || 0;
168
+ }).attr('ry', function (d) {
169
+ return d.border && d.border.r || 0;
170
+ }).attr('fill', function (d) {
171
+ return d.background.color;
172
+ }).attr('stroke', function (d) {
173
+ return d.border.color;
174
+ }).attr('stroke-width', function (d) {
175
+ return d.border.width;
176
+ }).style("filter", function (d) {
177
+ return d.type === 'NODE' ? 'url(#drop-shadow)' : '';
178
+ });
179
+ }
180
+ }, {
181
+ key: "drawLabel",
182
+ value: function drawLabel(groups) {
183
+ groups.append('text').attr('class', 'node-label').attr('x', function (d) {
184
+ return d.label.position.x;
185
+ }).attr('y', function (d) {
186
+ return d.label.position.y;
187
+ }).style('fill', function (d) {
188
+ return d.label.font.color;
189
+ }).attr('stroke', function (d) {
190
+ return 'none';
191
+ }).style('font-size', function (d) {
192
+ return d.label.font.size;
193
+ }).text(function (d) {
194
+ return d.label.text;
195
+ });
196
+ }
197
+ }, {
198
+ key: "drawIcon",
199
+ value: function drawIcon(groups) {
200
+ var icon_groups = groups.append('g').attr('class', 'icon-group').attr("transform", function (d) {
201
+ return "translate(" + (d.size.w - 24 - 20) + "," + 15 + ")";
202
+ });
203
+ icon_groups.append('rect').attr('class', 'node-body').attr('width', function (d) {
204
+ return 18;
205
+ }).attr('height', function (d) {
206
+ return 24;
207
+ }).attr('x', function (d) {
208
+ return 6;
209
+ }).attr('y', function (d) {
210
+ return 0;
211
+ }).attr('fill', function (d) {
212
+ return '#fff';
213
+ }).attr('stroke', function (d) {
214
+ return '#333';
215
+ }).attr('stroke-width', function (d) {
216
+ return 1;
217
+ });
218
+ icon_groups.append('rect').attr('class', 'node-body').attr('width', function (d) {
219
+ return 12;
220
+ }).attr('height', function (d) {
221
+ return 6;
222
+ }).attr('x', function (d) {
223
+ return 0;
224
+ }).attr('y', function (d) {
225
+ return 3;
226
+ }).attr('fill', function (d) {
227
+ return '#fff';
228
+ }).attr('stroke', function (d) {
229
+ return '#333';
230
+ }).attr('stroke-width', function (d) {
231
+ return 1;
232
+ });
233
+ icon_groups.append('rect').attr('class', 'node-body').attr('width', function (d) {
234
+ return 12;
235
+ }).attr('height', function (d) {
236
+ return 6;
237
+ }).attr('x', function (d) {
238
+ return 0;
239
+ }).attr('y', function (d) {
240
+ return 15;
241
+ }).attr('fill', function (d) {
242
+ return '#fff';
243
+ }).attr('stroke', function (d) {
244
+ return '#333';
245
+ }).attr('stroke-width', function (d) {
246
+ return 1;
247
+ });
248
+ }
249
+ }, {
250
+ key: "drawLink",
251
+ value: function drawLink(groups) {
252
+ var a_element = groups.append('a').attr('class', 'link-alt').attr('href', function (d) {
253
+ var url = d.link.url;
254
+ if (!url) return null;
255
+ if (typeof url === "function") return url(d);
256
+ return url;
257
+ }).attr('target', '_blank').attr('rel', 'noopener noreferrer').style('color', '#888888');
258
+ a_element.append('text').attr('x', function (d) {
259
+ return 10;
260
+ }).attr('y', function (d) {
261
+ return d.size.h - 10;
262
+ }).style("font-size", function (d) {
263
+ return '12px';
264
+ }).style("display", function (d) {
265
+ if (!d.link.url) return 'none';
266
+ return 'block';
267
+ }).text(function (d) {
268
+ if (!d.link.url) return '';
269
+ return 'link';
270
+ });
271
+ }
272
+ }, {
273
+ key: "drawComponent",
274
+ value: function drawComponent(place, data) {
275
+ var groups = this.drawGroup(place, data, 'component');
276
+ this.drawBody(groups, data);
277
+ this.drawIcon(groups, data);
278
+ this.drawLabel(groups, data);
279
+ this.drawLink(groups, data);
280
+ }
281
+ }, {
282
+ key: "drawNode",
283
+ value: function drawNode(place, data) {
284
+ var groups = this.drawGroup(place, data, 'node');
285
+ this.drawBody(groups, data);
286
+ this.drawLabel(groups, data);
287
+ this.drawLink(groups, data);
288
+ }
289
+ }, {
290
+ key: "draw",
291
+ value: function draw(place, data) {
292
+ if (data.type === 'NODE') {
293
+ this.drawNode(place, data);
294
+ return;
295
+ }
296
+
297
+ if (data.type === 'COMPONENT') {
298
+ this.drawComponent(place, data);
299
+ return;
300
+ }
301
+ }
302
+ }]);
303
+
304
+ return Node;
305
+ }();
306
+
307
+ exports["default"] = Node;
@@ -0,0 +1,64 @@
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); return Constructor; }
13
+
14
+ var Port = /*#__PURE__*/function () {
15
+ function Port() {
16
+ _classCallCheck(this, Port);
17
+ }
18
+
19
+ _createClass(Port, [{
20
+ key: "dataTemplate",
21
+ value: function dataTemplate() {
22
+ return {
23
+ node: null,
24
+ edge: null,
25
+ _id: null,
26
+ _core: null,
27
+ _class: 'PORT'
28
+ };
29
+ }
30
+ }, {
31
+ key: "normalize",
32
+ value: function normalize(data) {
33
+ var tmp = this.dataTemplate();
34
+ tmp._core = data;
35
+ return data;
36
+ } ///// ////////////////////////////////////////////////////////////////
37
+ ///// Draw
38
+ ///// ////////////////////////////////////////////////////////////////
39
+
40
+ }, {
41
+ key: "draw",
42
+ value: function draw(place, data) {
43
+ place.selectAll('circle.port').data([data], function (d) {
44
+ return d._id;
45
+ }).enter().append('circle').attr('class', 'port').attr('cx', function (d) {
46
+ return d.position.x;
47
+ }).attr('cy', function (d) {
48
+ return d.position.y;
49
+ }).attr('r', function (d) {
50
+ return 6;
51
+ }).attr('level', function (d) {
52
+ return d._level;
53
+ }).style('fill', function (d) {
54
+ return '#fff';
55
+ }).style("stroke", function (d) {
56
+ return '#888';
57
+ });
58
+ }
59
+ }]);
60
+
61
+ return Port;
62
+ }();
63
+
64
+ exports["default"] = Port;