@yanqirenshi/d3.wireframe 0.2.0 → 0.3.0
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.
- package/LICENSE +21 -0
- package/README.markdown +126 -68
- package/dist/DataBackground.js +7 -9
- package/dist/DataFont.js +7 -11
- package/dist/DataPosition.js +7 -11
- package/dist/DataRectangle.js +7 -9
- package/dist/DataStroke.js +7 -9
- package/dist/Element.js +6 -12
- package/dist/ElementButton.js +15 -18
- package/dist/ElementFounder.js +23 -19
- package/dist/ElementLabel.js +11 -9
- package/dist/Rectum.js +121 -47
- package/package.json +9 -7
- package/src/DataBackground.js +15 -23
- package/src/DataFont.js +15 -25
- package/src/DataPosition.js +15 -21
- package/src/DataRectangle.js +15 -20
- package/src/DataStroke.js +15 -23
- package/src/Element.js +62 -67
- package/src/ElementButton.js +77 -84
- package/src/ElementFounder.js +130 -124
- package/src/ElementLabel.js +68 -66
- package/src/Rectum.js +115 -44
package/src/ElementButton.js
CHANGED
|
@@ -1,84 +1,77 @@
|
|
|
1
|
-
import ElementFounder from './ElementFounder';
|
|
2
|
-
import ElementLabel from './ElementLabel';
|
|
3
|
-
import ElementIcon from './ElementIcon';
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
export default class ElementButton extends ElementFounder {
|
|
8
|
-
constructor (params) {
|
|
9
|
-
super('button', params);
|
|
10
|
-
|
|
11
|
-
this.label = new ElementLabel({idm:this.idm});
|
|
12
|
-
this.icon = new ElementIcon({idm:this.idm});
|
|
13
|
-
}
|
|
14
|
-
/* **************************************************************** *
|
|
15
|
-
* Data
|
|
16
|
-
* **************************************************************** */
|
|
17
|
-
templateElement () {
|
|
18
|
-
return this.makeTemplateElement({
|
|
19
|
-
round:
|
|
20
|
-
stroke: {
|
|
21
|
-
labels: [],
|
|
22
|
-
children: [],
|
|
23
|
-
icon: null,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
makeElement (core, parent) {
|
|
27
|
-
let element = this.templateElement();
|
|
28
|
-
|
|
29
|
-
this.initElement(element, core, parent);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.fittingRectangle(element, core);
|
|
35
|
-
this.fittingPosition(element, core);
|
|
36
|
-
this.fittingBackground(element, core);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
draw (place, data, projector) {
|
|
80
|
-
// this.drawDelete(place, data);
|
|
81
|
-
this.drawUpdate(place, data);
|
|
82
|
-
this.drawAdd(place, data, projector);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
1
|
+
import ElementFounder from './ElementFounder';
|
|
2
|
+
import ElementLabel from './ElementLabel';
|
|
3
|
+
import ElementIcon from './ElementIcon';
|
|
4
|
+
|
|
5
|
+
import { BUTTON_DEFAULTS, STROKE_DEFAULTS, roundOf } from '@yanqirenshi/model.wireframe';
|
|
6
|
+
|
|
7
|
+
export default class ElementButton extends ElementFounder {
|
|
8
|
+
constructor (params) {
|
|
9
|
+
super('button', params);
|
|
10
|
+
|
|
11
|
+
this.label = new ElementLabel({idm:this.idm});
|
|
12
|
+
this.icon = new ElementIcon({idm:this.idm});
|
|
13
|
+
}
|
|
14
|
+
/* **************************************************************** *
|
|
15
|
+
* Data
|
|
16
|
+
* **************************************************************** */
|
|
17
|
+
templateElement () {
|
|
18
|
+
return this.makeTemplateElement({
|
|
19
|
+
round: BUTTON_DEFAULTS.round,
|
|
20
|
+
stroke: { ...STROKE_DEFAULTS },
|
|
21
|
+
labels: [],
|
|
22
|
+
children: [],
|
|
23
|
+
icon: null,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
makeElement (core, parent) {
|
|
27
|
+
let element = this.templateElement();
|
|
28
|
+
|
|
29
|
+
this.initElement(element, core, parent);
|
|
30
|
+
|
|
31
|
+
// 既定(角丸 10・線)は model.wireframe が持つ(#195)
|
|
32
|
+
element.round = roundOf(core);
|
|
33
|
+
|
|
34
|
+
this.fittingRectangle(element, core);
|
|
35
|
+
this.fittingPosition(element, core);
|
|
36
|
+
this.fittingBackground(element, core);
|
|
37
|
+
|
|
38
|
+
this.fittingStroke(element, core); // null なら線なし、書いていなければ既定の線
|
|
39
|
+
|
|
40
|
+
element.labels = this.label.makeElements (core.labels);
|
|
41
|
+
element.icons = this.icon.makeElements(core.icons, element);
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
return element;
|
|
45
|
+
}
|
|
46
|
+
/* **************************************************************** *
|
|
47
|
+
* Draw
|
|
48
|
+
* **************************************************************** */
|
|
49
|
+
drawAdd (place, data, projector) {
|
|
50
|
+
const g = place.selectAll(`g.${this.name}`)
|
|
51
|
+
.data([data], (d) => { return d._id; })
|
|
52
|
+
.enter()
|
|
53
|
+
.append('g')
|
|
54
|
+
.attr('class', this.name)
|
|
55
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
56
|
+
|
|
57
|
+
this.drawBase(g, projector);
|
|
58
|
+
|
|
59
|
+
this.icon.draw(g, data, projector);
|
|
60
|
+
this.label.draw(g, data, projector);
|
|
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, projector) {
|
|
73
|
+
// this.drawDelete(place, data);
|
|
74
|
+
this.drawUpdate(place, data);
|
|
75
|
+
this.drawAdd(place, data, projector);
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/ElementFounder.js
CHANGED
|
@@ -1,124 +1,130 @@
|
|
|
1
|
-
import POSITION from './DataPosition';
|
|
2
|
-
import RECTANGLE from './DataRectangle';
|
|
3
|
-
import BACKGROUND from './DataBackground';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
element
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
base = g.append('
|
|
94
|
-
.attr('class', 'base')
|
|
95
|
-
.attr('
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (!d.stroke)
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
import POSITION from './DataPosition';
|
|
2
|
+
import RECTANGLE from './DataRectangle';
|
|
3
|
+
import BACKGROUND from './DataBackground';
|
|
4
|
+
import FONT from './DataFont';
|
|
5
|
+
|
|
6
|
+
import { elementStrokeOf, visibleOf } from '@yanqirenshi/model.wireframe';
|
|
7
|
+
|
|
8
|
+
export default class ElementFounder {
|
|
9
|
+
constructor (name, params) {
|
|
10
|
+
this.name = name;
|
|
11
|
+
|
|
12
|
+
this.idm = params.idm;
|
|
13
|
+
}
|
|
14
|
+
/* **************************************************************** *
|
|
15
|
+
* Data
|
|
16
|
+
* **************************************************************** */
|
|
17
|
+
makeTemplateElement (attributes) {
|
|
18
|
+
return {
|
|
19
|
+
...{
|
|
20
|
+
element_type: this.name,
|
|
21
|
+
visible: true,
|
|
22
|
+
_id: null,
|
|
23
|
+
_core: null,
|
|
24
|
+
},
|
|
25
|
+
...attributes
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 要素から入力を引けるようにする(element._core)。
|
|
30
|
+
* 入力の側には書かない(0.2.1 までは core._element を書いていたが、読む所が無く、
|
|
31
|
+
* 入力を書き換えて JSON にできなくしていたので、0.3.0 でやめた。#195)。
|
|
32
|
+
*/
|
|
33
|
+
makeCrossReference (element, core) {
|
|
34
|
+
element._core = core;
|
|
35
|
+
}
|
|
36
|
+
initElementID (element, core) {
|
|
37
|
+
element._id = core.id || this.idm.nextID();
|
|
38
|
+
}
|
|
39
|
+
initElementVisible (element, core) {
|
|
40
|
+
// false と書いたときだけ描かない(model.wireframe の visibleOf)
|
|
41
|
+
element.visible = visibleOf(core);
|
|
42
|
+
}
|
|
43
|
+
initElementParent (element, parent) {
|
|
44
|
+
if (parent)
|
|
45
|
+
element._parent = parent;
|
|
46
|
+
}
|
|
47
|
+
initElement (element, core, parent) {
|
|
48
|
+
this.makeCrossReference(element, core);
|
|
49
|
+
this.initElementID(element, core);
|
|
50
|
+
this.initElementVisible(element, core);
|
|
51
|
+
this.initElementParent(element, parent);
|
|
52
|
+
}
|
|
53
|
+
fittingRectangle (element, core) {
|
|
54
|
+
element.rectangle = RECTANGLE.build(core.rectangle);
|
|
55
|
+
}
|
|
56
|
+
fittingPosition (element, core) {
|
|
57
|
+
element.position = POSITION.build(core.position);
|
|
58
|
+
}
|
|
59
|
+
fittingBackground (element, core) {
|
|
60
|
+
element.background = BACKGROUND.build(core.background);
|
|
61
|
+
}
|
|
62
|
+
fittingStroke (element, core) {
|
|
63
|
+
// 種類ごとの線(button は書いていなければ既定の線・null で線なし。ほかは書いていなければ線なし)。
|
|
64
|
+
// 判定は model.wireframe の elementStrokeOf(#195)
|
|
65
|
+
element.stroke = elementStrokeOf(core);
|
|
66
|
+
}
|
|
67
|
+
fittingFont (element, core) {
|
|
68
|
+
element.font = FONT.build(core.font);
|
|
69
|
+
}
|
|
70
|
+
/* **************************************************************** *
|
|
71
|
+
* Draw
|
|
72
|
+
* **************************************************************** */
|
|
73
|
+
/**
|
|
74
|
+
* グループの transform。回転ビュー(projector あり)では絶対座標を
|
|
75
|
+
* 射影して描くため translate は使わない。
|
|
76
|
+
*/
|
|
77
|
+
groupTransform (d, projector) {
|
|
78
|
+
if (projector)
|
|
79
|
+
return null;
|
|
80
|
+
|
|
81
|
+
return `translate(${d.position.x}, ${d.position.y})`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 要素の下地(base)を描く。通常はグループ局所座標の rect、
|
|
85
|
+
* 回転ビューでは絶対座標の4頂点を射影した polygon(角丸 round は
|
|
86
|
+
* 回転ビューでは省略される)。fill/stroke は共通で適用し、
|
|
87
|
+
* 追加の属性は返り値の selection に呼び出し側で付ける。
|
|
88
|
+
*/
|
|
89
|
+
drawBase (g, projector) {
|
|
90
|
+
let base = null;
|
|
91
|
+
|
|
92
|
+
if (projector) {
|
|
93
|
+
base = g.append('polygon')
|
|
94
|
+
.attr('class', 'base')
|
|
95
|
+
.attr('points', d => projector.rectPoints(
|
|
96
|
+
d.position.x, d.position.y, d.rectangle.w, d.rectangle.h,
|
|
97
|
+
projector.depthZ(d._depth)));
|
|
98
|
+
} else {
|
|
99
|
+
base = g.append('rect')
|
|
100
|
+
.attr('class', 'base')
|
|
101
|
+
.attr('width', d => d.rectangle.w)
|
|
102
|
+
.attr('height', d => d.rectangle.h)
|
|
103
|
+
.attr('rx', d => d.round || 0)
|
|
104
|
+
.attr('ry', d => d.round || 0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return base
|
|
108
|
+
.attr('fill', d => d.background.color)
|
|
109
|
+
.attr('stroke', d => this.stroke(d))
|
|
110
|
+
.attr('stroke-width', d => this.strokeWidth(d));
|
|
111
|
+
}
|
|
112
|
+
stroke (d) {
|
|
113
|
+
if (!d.stroke)
|
|
114
|
+
return null;
|
|
115
|
+
|
|
116
|
+
if (!d.stroke)
|
|
117
|
+
return '#333';
|
|
118
|
+
|
|
119
|
+
return d.stroke.color || '#333';
|
|
120
|
+
}
|
|
121
|
+
strokeWidth (d) {
|
|
122
|
+
if (!d.stroke)
|
|
123
|
+
return null;
|
|
124
|
+
|
|
125
|
+
if (!d.stroke)
|
|
126
|
+
return 1;
|
|
127
|
+
|
|
128
|
+
return d.stroke.width || 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/ElementLabel.js
CHANGED
|
@@ -1,66 +1,68 @@
|
|
|
1
|
-
import ElementFounder from './ElementFounder';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.
|
|
54
|
-
.
|
|
55
|
-
.
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
import ElementFounder from './ElementFounder';
|
|
2
|
+
|
|
3
|
+
import { LABEL_DEFAULTS } from '@yanqirenshi/model.wireframe';
|
|
4
|
+
|
|
5
|
+
export default class ElementLabel extends ElementFounder {
|
|
6
|
+
constructor (params) {
|
|
7
|
+
super('label', params);
|
|
8
|
+
}
|
|
9
|
+
/* **************************************************************** *
|
|
10
|
+
* Data
|
|
11
|
+
* **************************************************************** */
|
|
12
|
+
templateElement () {
|
|
13
|
+
return this.makeTemplateElement({
|
|
14
|
+
text: LABEL_DEFAULTS.text, // model.wireframe(#195)
|
|
15
|
+
position: null,
|
|
16
|
+
font: null,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
makeElement (core, parent) {
|
|
20
|
+
let element = this.templateElement();
|
|
21
|
+
|
|
22
|
+
this.initElement(element, core, parent);
|
|
23
|
+
|
|
24
|
+
if (core.text)
|
|
25
|
+
element.text = core.text;
|
|
26
|
+
|
|
27
|
+
this.fittingPosition(element, core);
|
|
28
|
+
this.fittingFont(element, core);
|
|
29
|
+
|
|
30
|
+
return element;
|
|
31
|
+
}
|
|
32
|
+
makeElements (labels) {
|
|
33
|
+
if (!labels)
|
|
34
|
+
return [];
|
|
35
|
+
|
|
36
|
+
return labels.map((d) => this.makeElement(d));
|
|
37
|
+
}
|
|
38
|
+
/* **************************************************************** *
|
|
39
|
+
* Draw
|
|
40
|
+
* **************************************************************** */
|
|
41
|
+
/**
|
|
42
|
+
* ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
|
|
43
|
+
* ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
|
|
44
|
+
* 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
|
|
45
|
+
*/
|
|
46
|
+
draw (place, data, projector) {
|
|
47
|
+
const project = (d) => projector.point(
|
|
48
|
+
data.position.x + d.position.x,
|
|
49
|
+
data.position.y + d.position.y,
|
|
50
|
+
projector.depthZ(data._depth));
|
|
51
|
+
|
|
52
|
+
place.selectAll('label')
|
|
53
|
+
.data(data.labels, d => d._id)
|
|
54
|
+
.enter()
|
|
55
|
+
.append("text")
|
|
56
|
+
.attr("x", d => projector ? project(d).x : d.position.x)
|
|
57
|
+
.attr("y", d => projector ? project(d).y : d.position.y)
|
|
58
|
+
.style("font-size", d => {
|
|
59
|
+
if (!projector)
|
|
60
|
+
return `${d.font.size}px`;
|
|
61
|
+
|
|
62
|
+
return `${d.font.size * project(d).k}px`;
|
|
63
|
+
})
|
|
64
|
+
.style("fill", d => d.font.color)
|
|
65
|
+
.style("font-weight", d => d.font.weight)
|
|
66
|
+
.text(d => d.text);
|
|
67
|
+
}
|
|
68
|
+
}
|