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