@yanqirenshi/d3.wireframe 0.1.1 → 0.2.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.
@@ -1,77 +1,67 @@
1
- import ElementFounder from './ElementFounder';
2
- import ElementLabel from './ElementLabel';
3
-
4
- export default class ElementFrame extends ElementFounder {
5
- constructor (params) {
6
- super('frame', params);
7
-
8
- this.label = new ElementLabel({idm:this.idm});
9
- }
10
- /* **************************************************************** *
11
- * Data
12
- * **************************************************************** */
13
- templateElement () {
14
- return this.makeTemplateElement({
15
- rectangle: null,
16
- position: null,
17
- background: null,
18
- stroke: null,
19
- labels: [],
20
- children: [],
21
- });
22
- }
23
- makeElement (core, parent) {
24
- let element = this.templateElement();
25
-
26
- this.initElement(element, core, parent);
27
-
28
- this.fittingRectangle(element, core);
29
- this.fittingPosition(element, core);
30
- this.fittingBackground(element, core);
31
- this.fittingStroke(element, core);
32
-
33
- element.labels = this.label.makeElements (core.labels);
34
-
35
- return element;
36
- }
37
- /* **************************************************************** *
38
- * Draw
39
- * **************************************************************** */
40
- drawAdd (place, data) {
41
- const g = place.selectAll(`g.${this.name}`)
42
- .data([data], (d) => { return d._id; })
43
- .enter()
44
- .append('g')
45
- .attr('class', this.name)
46
- .attr("transform", d => {
47
- return `translate(${d.position.x}, ${d.position.y})`;
48
- });
49
-
50
- g.append('rect')
51
- .attr('class', 'base')
52
- .attr('width', d => d.rectangle.w)
53
- .attr('height', d => d.rectangle.h)
54
- .attr('rx', d => d.round || 0)
55
- .attr('ry', d => d.round || 0)
56
- .attr('fill', d => d.background.color)
57
- .attr('stroke', d => this.stroke(d))
58
- .attr('stroke-width', d => this.strokeWidth(d));
59
-
60
- this.label.draw(g, data);
61
- }
62
- drawUpdate (place, data) {
63
- place.selectAll(`g.${this.name}`)
64
- .data([data], (d) => { return d._id; });
65
- }
66
- drawDelete (place, data) {
67
- place.selectAll(`g.${this.name}`)
68
- .data([data], (d) => { return d._id; })
69
- .exit()
70
- .remove();
71
- }
72
- draw (place, data) {
73
- // this.drawDelete(place, data);
74
- this.drawUpdate(place, data);
75
- this.drawAdd(place, data);
76
- }
77
- }
1
+ import ElementFounder from './ElementFounder';
2
+ import ElementLabel from './ElementLabel';
3
+
4
+ export default class ElementFrame extends ElementFounder {
5
+ constructor (params) {
6
+ super('frame', params);
7
+
8
+ this.label = new ElementLabel({idm:this.idm});
9
+ }
10
+ /* **************************************************************** *
11
+ * Data
12
+ * **************************************************************** */
13
+ templateElement () {
14
+ return this.makeTemplateElement({
15
+ rectangle: null,
16
+ position: null,
17
+ background: null,
18
+ stroke: null,
19
+ labels: [],
20
+ children: [],
21
+ });
22
+ }
23
+ makeElement (core, parent) {
24
+ let element = this.templateElement();
25
+
26
+ this.initElement(element, core, parent);
27
+
28
+ this.fittingRectangle(element, core);
29
+ this.fittingPosition(element, core);
30
+ this.fittingBackground(element, core);
31
+ this.fittingStroke(element, core);
32
+
33
+ element.labels = this.label.makeElements (core.labels);
34
+
35
+ return element;
36
+ }
37
+ /* **************************************************************** *
38
+ * Draw
39
+ * **************************************************************** */
40
+ drawAdd (place, data, projector) {
41
+ const g = place.selectAll(`g.${this.name}`)
42
+ .data([data], (d) => { return d._id; })
43
+ .enter()
44
+ .append('g')
45
+ .attr('class', this.name)
46
+ .attr("transform", d => this.groupTransform(d, projector));
47
+
48
+ this.drawBase(g, projector);
49
+
50
+ this.label.draw(g, data, projector);
51
+ }
52
+ drawUpdate (place, data) {
53
+ place.selectAll(`g.${this.name}`)
54
+ .data([data], (d) => { return d._id; });
55
+ }
56
+ drawDelete (place, data) {
57
+ place.selectAll(`g.${this.name}`)
58
+ .data([data], (d) => { return d._id; })
59
+ .exit()
60
+ .remove();
61
+ }
62
+ draw (place, data, projector) {
63
+ // this.drawDelete(place, data);
64
+ this.drawUpdate(place, data);
65
+ this.drawAdd(place, data, projector);
66
+ }
67
+ }
@@ -1,56 +1,72 @@
1
- import ElementFounder from './ElementFounder';
2
-
3
- export default class ElementIcon extends ElementFounder {
4
- constructor (params) {
5
- super('icon', params);
6
-
7
- this.idm = params.idm;
8
- }
9
- /* **************************************************************** *
10
- * Data
11
- * **************************************************************** */
12
- templateElement () {
13
- return this.makeTemplateElement({
14
- position: null,
15
- rectangle: null,
16
- url: null,
17
- });
18
- }
19
- makeElement (core, parent) {
20
- let element = this.templateElement();
21
-
22
- this.initElement(element, core, parent);
23
-
24
- this.fittingPosition(element, core);
25
-
26
- if (core.size)
27
- this.fittingRectangle(element, core);
28
- else
29
- element.size = parent.rectangle;
30
-
31
- if (core.url)
32
- element.url = core.url;
33
-
34
- return element;
35
- }
36
- makeElements (icons, parent) {
37
- if (!icons)
38
- return [];
39
-
40
- return icons.map(icon => this.makeElement(icon, parent));
41
- }
42
- /* **************************************************************** *
43
- * Draw
44
- * **************************************************************** */
45
- draw (place, data) {
46
- place.selectAll('image')
47
- .data(data.icons || [], d => d._id)
48
- .enter()
49
- .append('image')
50
- .attr('xlink:href', d => d.url)
51
- .attr('x', d => (d.position && d.position.x) || 0)
52
- .attr('y', d => (d.position && d.position.y) || 0)
53
- .attr('width', d => (d.size && d.size.w) || d.rectangle.w)
54
- .attr('height', d => (d.size && d.size.h) || d.rectangle.h);
55
- }
56
- }
1
+ import ElementFounder from './ElementFounder';
2
+
3
+ export default class ElementIcon extends ElementFounder {
4
+ constructor (params) {
5
+ super('icon', params);
6
+
7
+ this.idm = params.idm;
8
+ }
9
+ /* **************************************************************** *
10
+ * Data
11
+ * **************************************************************** */
12
+ templateElement () {
13
+ return this.makeTemplateElement({
14
+ position: null,
15
+ rectangle: null,
16
+ url: null,
17
+ });
18
+ }
19
+ makeElement (core, parent) {
20
+ let element = this.templateElement();
21
+
22
+ this.initElement(element, core, parent);
23
+
24
+ this.fittingPosition(element, core);
25
+
26
+ if (core.size)
27
+ this.fittingRectangle(element, core);
28
+ else
29
+ element.size = parent.rectangle;
30
+
31
+ if (core.url)
32
+ element.url = core.url;
33
+
34
+ return element;
35
+ }
36
+ makeElements (icons, parent) {
37
+ if (!icons)
38
+ return [];
39
+
40
+ return icons.map(icon => this.makeElement(icon, parent));
41
+ }
42
+ /* **************************************************************** *
43
+ * Draw
44
+ * **************************************************************** */
45
+ /**
46
+ * アイコン(画像)を描く。SVG の <image> は polygon 化できないため、
47
+ * 回転ビュー(projector あり)では要素の3隅を正確に写す近似 affine
48
+ * 行列で変形する(アイコンは小さいので誤差は実用上見えない)。
49
+ */
50
+ draw (place, data, projector) {
51
+ place.selectAll('image')
52
+ .data(data.icons || [], d => d._id)
53
+ .enter()
54
+ .append('image')
55
+ .attr('xlink:href', d => d.url)
56
+ .attr('transform', d => {
57
+ if (!projector)
58
+ return null;
59
+
60
+ const x = data.position.x + ((d.position && d.position.x) || 0);
61
+ const y = data.position.y + ((d.position && d.position.y) || 0);
62
+ const w = (d.size && d.size.w) || d.rectangle.w;
63
+ const h = (d.size && d.size.h) || d.rectangle.h;
64
+
65
+ return projector.affine(x, y, w, h, projector.depthZ(data._depth));
66
+ })
67
+ .attr('x', d => projector ? 0 : ((d.position && d.position.x) || 0))
68
+ .attr('y', d => projector ? 0 : ((d.position && d.position.y) || 0))
69
+ .attr('width', d => (d.size && d.size.w) || d.rectangle.w)
70
+ .attr('height', d => (d.size && d.size.h) || d.rectangle.h);
71
+ }
72
+ }
@@ -1,77 +1,67 @@
1
- import ElementFounder from './ElementFounder';
2
- import ElementLabel from './ElementLabel';
3
-
4
- export default class ElementImage extends ElementFounder {
5
- constructor (params) {
6
- super('image', params);
7
-
8
- this.label = new ElementLabel({idm:this.idm});
9
- }
10
- /* **************************************************************** *
11
- * Data
12
- * **************************************************************** */
13
- templateElement () {
14
- return this.makeTemplateElement({
15
- rectangle: null,
16
- position: null,
17
- background: null,
18
- stroke: null,
19
- labels: [],
20
- children: [],
21
- });
22
- }
23
- makeElement (core, parent) {
24
- let element = this.templateElement();
25
-
26
- this.initElement(element, core, parent);
27
-
28
- this.fittingRectangle(element, core);
29
- this.fittingPosition(element, core);
30
- this.fittingBackground(element, core);
31
- this.fittingStroke(element, core);
32
-
33
- element.labels = this.label.makeElements (core.labels);
34
-
35
- return element;
36
- }
37
- /* **************************************************************** *
38
- * Draw
39
- * **************************************************************** */
40
- drawAdd (place, data) {
41
- const g = place.selectAll(`g.${this.name}`)
42
- .data([data], (d) => { return d._id; })
43
- .enter()
44
- .append('g')
45
- .attr('class', this.name)
46
- .attr("transform", d => {
47
- return `translate(${d.position.x}, ${d.position.y})`;
48
- });
49
-
50
- g.append('rect')
51
- .attr('class', 'base')
52
- .attr('width', d => d.rectangle.w)
53
- .attr('height', d => d.rectangle.h)
54
- .attr('rx', d => d.round || 0)
55
- .attr('ry', d => d.round || 0)
56
- .attr('fill', d => d.background.color)
57
- .attr('stroke', d => this.stroke(d))
58
- .attr('stroke-width', d => this.strokeWidth(d));
59
-
60
- this.label.draw(g, data);
61
- }
62
- drawUpdate (place, data) {
63
- place.selectAll(`g.${this.name}`)
64
- .data([data], (d) => { return d._id; });
65
- }
66
- drawDelete (place, data) {
67
- place.selectAll(`g.${this.name}`)
68
- .data([data], (d) => { return d._id; })
69
- .exit()
70
- .remove();
71
- }
72
- draw (place, data) {
73
- // this.drawDelete(place, data);
74
- this.drawUpdate(place, data);
75
- this.drawAdd(place, data);
76
- }
77
- }
1
+ import ElementFounder from './ElementFounder';
2
+ import ElementLabel from './ElementLabel';
3
+
4
+ export default class ElementImage extends ElementFounder {
5
+ constructor (params) {
6
+ super('image', params);
7
+
8
+ this.label = new ElementLabel({idm:this.idm});
9
+ }
10
+ /* **************************************************************** *
11
+ * Data
12
+ * **************************************************************** */
13
+ templateElement () {
14
+ return this.makeTemplateElement({
15
+ rectangle: null,
16
+ position: null,
17
+ background: null,
18
+ stroke: null,
19
+ labels: [],
20
+ children: [],
21
+ });
22
+ }
23
+ makeElement (core, parent) {
24
+ let element = this.templateElement();
25
+
26
+ this.initElement(element, core, parent);
27
+
28
+ this.fittingRectangle(element, core);
29
+ this.fittingPosition(element, core);
30
+ this.fittingBackground(element, core);
31
+ this.fittingStroke(element, core);
32
+
33
+ element.labels = this.label.makeElements (core.labels);
34
+
35
+ return element;
36
+ }
37
+ /* **************************************************************** *
38
+ * Draw
39
+ * **************************************************************** */
40
+ drawAdd (place, data, projector) {
41
+ const g = place.selectAll(`g.${this.name}`)
42
+ .data([data], (d) => { return d._id; })
43
+ .enter()
44
+ .append('g')
45
+ .attr('class', this.name)
46
+ .attr("transform", d => this.groupTransform(d, projector));
47
+
48
+ this.drawBase(g, projector);
49
+
50
+ this.label.draw(g, data, projector);
51
+ }
52
+ drawUpdate (place, data) {
53
+ place.selectAll(`g.${this.name}`)
54
+ .data([data], (d) => { return d._id; });
55
+ }
56
+ drawDelete (place, data) {
57
+ place.selectAll(`g.${this.name}`)
58
+ .data([data], (d) => { return d._id; })
59
+ .exit()
60
+ .remove();
61
+ }
62
+ draw (place, data, projector) {
63
+ // this.drawDelete(place, data);
64
+ this.drawUpdate(place, data);
65
+ this.drawAdd(place, data, projector);
66
+ }
67
+ }
@@ -1,51 +1,66 @@
1
- import ElementFounder from './ElementFounder';
2
-
3
- export default class ElementLabel extends ElementFounder {
4
- constructor (params) {
5
- super('label', params);
6
- }
7
- /* **************************************************************** *
8
- * Data
9
- * **************************************************************** */
10
- templateElement () {
11
- return this.makeTemplateElement({
12
- text: '????????',
13
- position: null,
14
- font: null,
15
- });
16
- }
17
- makeElement (core, parent) {
18
- let element = this.templateElement();
19
-
20
- this.initElement(element, core, parent);
21
-
22
- if (core.text)
23
- element.text = core.text;
24
-
25
- this.fittingPosition(element, core);
26
- this.fittingFont(element, core);
27
-
28
- return element;
29
- }
30
- makeElements (labels) {
31
- if (!labels)
32
- return [];
33
-
34
- return labels.map((d) => this.makeElement(d));
35
- }
36
- /* **************************************************************** *
37
- * Draw
38
- * **************************************************************** */
39
- draw (place, data) {
40
- place.selectAll('label')
41
- .data(data.labels, d => d._id)
42
- .enter()
43
- .append("text")
44
- .attr("x", d => d.position.x)
45
- .attr("y", d => d.position.y)
46
- .style("font-size", d => `${d.font.size}px`)
47
- .style("fill", d => d.font.color)
48
- .style("font-weight", d => d.font.weight)
49
- .text(d => d.text);
50
- }
51
- }
1
+ import ElementFounder from './ElementFounder';
2
+
3
+ export default class ElementLabel extends ElementFounder {
4
+ constructor (params) {
5
+ super('label', params);
6
+ }
7
+ /* **************************************************************** *
8
+ * Data
9
+ * **************************************************************** */
10
+ templateElement () {
11
+ return this.makeTemplateElement({
12
+ text: '????????',
13
+ position: null,
14
+ font: null,
15
+ });
16
+ }
17
+ makeElement (core, parent) {
18
+ let element = this.templateElement();
19
+
20
+ this.initElement(element, core, parent);
21
+
22
+ if (core.text)
23
+ element.text = core.text;
24
+
25
+ this.fittingPosition(element, core);
26
+ this.fittingFont(element, core);
27
+
28
+ return element;
29
+ }
30
+ makeElements (labels) {
31
+ if (!labels)
32
+ return [];
33
+
34
+ return labels.map((d) => this.makeElement(d));
35
+ }
36
+ /* **************************************************************** *
37
+ * Draw
38
+ * **************************************************************** */
39
+ /**
40
+ * ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
41
+ * ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
42
+ * 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
43
+ */
44
+ draw (place, data, projector) {
45
+ const project = (d) => projector.point(
46
+ data.position.x + d.position.x,
47
+ data.position.y + d.position.y,
48
+ projector.depthZ(data._depth));
49
+
50
+ place.selectAll('label')
51
+ .data(data.labels, d => d._id)
52
+ .enter()
53
+ .append("text")
54
+ .attr("x", d => projector ? project(d).x : d.position.x)
55
+ .attr("y", d => projector ? project(d).y : d.position.y)
56
+ .style("font-size", d => {
57
+ if (!projector)
58
+ return `${d.font.size}px`;
59
+
60
+ return `${d.font.size * project(d).k}px`;
61
+ })
62
+ .style("fill", d => d.font.color)
63
+ .style("font-weight", d => d.font.weight)
64
+ .text(d => d.text);
65
+ }
66
+ }