@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.
- package/LICENSE +21 -0
- package/README.markdown +68 -68
- package/dist/Digestion.js +20 -20
- package/dist/Drawer.js +20 -20
- package/dist/Element.js +8 -8
- package/dist/ElementButton.js +11 -25
- package/dist/ElementDialog.js +10 -24
- package/dist/ElementFounder.js +48 -4
- package/dist/ElementFrame.js +10 -24
- package/dist/ElementIcon.js +19 -7
- package/dist/ElementImage.js +10 -24
- package/dist/ElementLabel.js +17 -8
- package/dist/ElementModal.js +13 -15
- package/dist/Projector.js +115 -0
- package/dist/Rectum.js +149 -16
- package/dist/components/D3Wireframe.js +5 -1
- package/dist/index.js +7 -0
- package/package.json +7 -6
- package/src/DataBackground.js +23 -23
- package/src/DataFont.js +25 -25
- package/src/DataPosition.js +21 -21
- package/src/DataRectangle.js +20 -20
- package/src/DataStroke.js +23 -23
- package/src/Digestion.js +273 -273
- package/src/Drawer.js +270 -270
- package/src/Element.js +67 -67
- package/src/ElementButton.js +84 -94
- package/src/ElementDialog.js +67 -77
- package/src/ElementFounder.js +124 -85
- package/src/ElementFrame.js +67 -77
- package/src/ElementIcon.js +72 -56
- package/src/ElementImage.js +67 -77
- package/src/ElementLabel.js +66 -51
- package/src/ElementModal.js +61 -65
- package/src/Projector.js +100 -0
- package/src/Rectum.js +122 -3
- package/src/components/D3Wireframe.js +5 -1
- package/src/index.js +2 -0
package/src/Element.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import ElementFrame from './ElementFrame';
|
|
2
|
-
import ElementImage from './ElementImage';
|
|
3
|
-
import ElementButton from './ElementButton';
|
|
4
|
-
import ElementModal from './ElementModal';
|
|
5
|
-
import ElementDialog from './ElementDialog';
|
|
6
|
-
|
|
7
|
-
export default class Element {
|
|
8
|
-
constructor () {
|
|
9
|
-
this._id = 0;
|
|
10
|
-
|
|
11
|
-
const params = { idm: this };
|
|
12
|
-
|
|
13
|
-
this.element_classes = {
|
|
14
|
-
frame: new ElementFrame(params),
|
|
15
|
-
image: new ElementImage(params),
|
|
16
|
-
button: new ElementButton(params),
|
|
17
|
-
modal: new ElementModal(params),
|
|
18
|
-
dialog: new ElementDialog(params),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
nextID () {
|
|
22
|
-
return ++this._id;
|
|
23
|
-
};
|
|
24
|
-
/* **************************************************************** *
|
|
25
|
-
* Element Class
|
|
26
|
-
* **************************************************************** */
|
|
27
|
-
elementClass (data) {
|
|
28
|
-
const element_type = data.element_type;
|
|
29
|
-
|
|
30
|
-
const element_class = this.element_classes[data.element_type];
|
|
31
|
-
|
|
32
|
-
if (!element_class)
|
|
33
|
-
throw new Error('Not supported yet. element_type=' + element_type);
|
|
34
|
-
|
|
35
|
-
return element_class;
|
|
36
|
-
}
|
|
37
|
-
/* **************************************************************** *
|
|
38
|
-
* Element Class
|
|
39
|
-
* **************************************************************** */
|
|
40
|
-
makeElement (core) {
|
|
41
|
-
const element_class = this.elementClass(core);
|
|
42
|
-
|
|
43
|
-
const element = element_class.makeElement(core);
|
|
44
|
-
|
|
45
|
-
const children = core.children || [];
|
|
46
|
-
element.children = children
|
|
47
|
-
.map(d => this.makeElement(d))
|
|
48
|
-
.filter(d => d.visible);
|
|
49
|
-
|
|
50
|
-
return element;
|
|
51
|
-
}
|
|
52
|
-
mergeCore (core, element) {
|
|
53
|
-
const element_class = this.elementClass(core);
|
|
54
|
-
|
|
55
|
-
return element_class.merge(core, element);
|
|
56
|
-
}
|
|
57
|
-
/* **************************************************************** *
|
|
58
|
-
* Draw
|
|
59
|
-
* **************************************************************** */
|
|
60
|
-
draw (place, list) {
|
|
61
|
-
for (let data of list) {
|
|
62
|
-
const ec = this.elementClass(data);
|
|
63
|
-
|
|
64
|
-
ec.draw(place, data);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
1
|
+
import ElementFrame from './ElementFrame';
|
|
2
|
+
import ElementImage from './ElementImage';
|
|
3
|
+
import ElementButton from './ElementButton';
|
|
4
|
+
import ElementModal from './ElementModal';
|
|
5
|
+
import ElementDialog from './ElementDialog';
|
|
6
|
+
|
|
7
|
+
export default class Element {
|
|
8
|
+
constructor () {
|
|
9
|
+
this._id = 0;
|
|
10
|
+
|
|
11
|
+
const params = { idm: this };
|
|
12
|
+
|
|
13
|
+
this.element_classes = {
|
|
14
|
+
frame: new ElementFrame(params),
|
|
15
|
+
image: new ElementImage(params),
|
|
16
|
+
button: new ElementButton(params),
|
|
17
|
+
modal: new ElementModal(params),
|
|
18
|
+
dialog: new ElementDialog(params),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
nextID () {
|
|
22
|
+
return ++this._id;
|
|
23
|
+
};
|
|
24
|
+
/* **************************************************************** *
|
|
25
|
+
* Element Class
|
|
26
|
+
* **************************************************************** */
|
|
27
|
+
elementClass (data) {
|
|
28
|
+
const element_type = data.element_type;
|
|
29
|
+
|
|
30
|
+
const element_class = this.element_classes[data.element_type];
|
|
31
|
+
|
|
32
|
+
if (!element_class)
|
|
33
|
+
throw new Error('Not supported yet. element_type=' + element_type);
|
|
34
|
+
|
|
35
|
+
return element_class;
|
|
36
|
+
}
|
|
37
|
+
/* **************************************************************** *
|
|
38
|
+
* Element Class
|
|
39
|
+
* **************************************************************** */
|
|
40
|
+
makeElement (core) {
|
|
41
|
+
const element_class = this.elementClass(core);
|
|
42
|
+
|
|
43
|
+
const element = element_class.makeElement(core);
|
|
44
|
+
|
|
45
|
+
const children = core.children || [];
|
|
46
|
+
element.children = children
|
|
47
|
+
.map(d => this.makeElement(d))
|
|
48
|
+
.filter(d => d.visible);
|
|
49
|
+
|
|
50
|
+
return element;
|
|
51
|
+
}
|
|
52
|
+
mergeCore (core, element) {
|
|
53
|
+
const element_class = this.elementClass(core);
|
|
54
|
+
|
|
55
|
+
return element_class.merge(core, element);
|
|
56
|
+
}
|
|
57
|
+
/* **************************************************************** *
|
|
58
|
+
* Draw
|
|
59
|
+
* **************************************************************** */
|
|
60
|
+
draw (place, list, projector) {
|
|
61
|
+
for (let data of list) {
|
|
62
|
+
const ec = this.elementClass(data);
|
|
63
|
+
|
|
64
|
+
ec.draw(place, data, projector);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/ElementButton.js
CHANGED
|
@@ -1,94 +1,84 @@
|
|
|
1
|
-
import ElementFounder from './ElementFounder';
|
|
2
|
-
import ElementLabel from './ElementLabel';
|
|
3
|
-
import ElementIcon from './ElementIcon';
|
|
4
|
-
|
|
5
|
-
import STROKE from './DataStroke';
|
|
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:10,
|
|
20
|
-
stroke: { color: '#afafb0', width: 1 },
|
|
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
|
-
if (core.round)
|
|
32
|
-
element.round = core.round;
|
|
33
|
-
|
|
34
|
-
this.fittingRectangle(element, core);
|
|
35
|
-
this.fittingPosition(element, core);
|
|
36
|
-
this.fittingBackground(element, core);
|
|
37
|
-
|
|
38
|
-
if (core.stroke===null)
|
|
39
|
-
element.stroke = null;
|
|
40
|
-
else
|
|
41
|
-
this.fittingStroke(element, core);
|
|
42
|
-
|
|
43
|
-
element.labels = this.label.makeElements (core.labels);
|
|
44
|
-
element.icons = this.icon.makeElements(core.icons, element);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return element;
|
|
48
|
-
}
|
|
49
|
-
mergeCore (core, element) {
|
|
50
|
-
element._core = core;
|
|
51
|
-
core._element = element;
|
|
52
|
-
}
|
|
53
|
-
/* **************************************************************** *
|
|
54
|
-
* Draw
|
|
55
|
-
* **************************************************************** */
|
|
56
|
-
drawAdd (place, data) {
|
|
57
|
-
const g = place.selectAll(`g.${this.name}`)
|
|
58
|
-
.data([data], (d) => { return d._id; })
|
|
59
|
-
.enter()
|
|
60
|
-
.append('g')
|
|
61
|
-
.attr('class', this.name)
|
|
62
|
-
.attr("transform", d =>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.data([data], (d) => { return d._id; })
|
|
86
|
-
.exit()
|
|
87
|
-
.remove();
|
|
88
|
-
}
|
|
89
|
-
draw (place, data) {
|
|
90
|
-
// this.drawDelete(place, data);
|
|
91
|
-
this.drawUpdate(place, data);
|
|
92
|
-
this.drawAdd(place, data);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import ElementFounder from './ElementFounder';
|
|
2
|
+
import ElementLabel from './ElementLabel';
|
|
3
|
+
import ElementIcon from './ElementIcon';
|
|
4
|
+
|
|
5
|
+
import STROKE from './DataStroke';
|
|
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:10,
|
|
20
|
+
stroke: { color: '#afafb0', width: 1 },
|
|
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
|
+
if (core.round)
|
|
32
|
+
element.round = core.round;
|
|
33
|
+
|
|
34
|
+
this.fittingRectangle(element, core);
|
|
35
|
+
this.fittingPosition(element, core);
|
|
36
|
+
this.fittingBackground(element, core);
|
|
37
|
+
|
|
38
|
+
if (core.stroke===null)
|
|
39
|
+
element.stroke = null;
|
|
40
|
+
else
|
|
41
|
+
this.fittingStroke(element, core);
|
|
42
|
+
|
|
43
|
+
element.labels = this.label.makeElements (core.labels);
|
|
44
|
+
element.icons = this.icon.makeElements(core.icons, element);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
return element;
|
|
48
|
+
}
|
|
49
|
+
mergeCore (core, element) {
|
|
50
|
+
element._core = core;
|
|
51
|
+
core._element = element;
|
|
52
|
+
}
|
|
53
|
+
/* **************************************************************** *
|
|
54
|
+
* Draw
|
|
55
|
+
* **************************************************************** */
|
|
56
|
+
drawAdd (place, data, projector) {
|
|
57
|
+
const g = place.selectAll(`g.${this.name}`)
|
|
58
|
+
.data([data], (d) => { return d._id; })
|
|
59
|
+
.enter()
|
|
60
|
+
.append('g')
|
|
61
|
+
.attr('class', this.name)
|
|
62
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
63
|
+
|
|
64
|
+
this.drawBase(g, projector);
|
|
65
|
+
|
|
66
|
+
this.icon.draw(g, data, projector);
|
|
67
|
+
this.label.draw(g, data, projector);
|
|
68
|
+
}
|
|
69
|
+
drawUpdate (place, data) {
|
|
70
|
+
place.selectAll(`g.${this.name}`)
|
|
71
|
+
.data([data], (d) => { return d._id; });
|
|
72
|
+
}
|
|
73
|
+
drawDelete (place, data) {
|
|
74
|
+
place.selectAll(`g.${this.name}`)
|
|
75
|
+
.data([data], (d) => { return d._id; })
|
|
76
|
+
.exit()
|
|
77
|
+
.remove();
|
|
78
|
+
}
|
|
79
|
+
draw (place, data, projector) {
|
|
80
|
+
// this.drawDelete(place, data);
|
|
81
|
+
this.drawUpdate(place, data);
|
|
82
|
+
this.drawAdd(place, data, projector);
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/ElementDialog.js
CHANGED
|
@@ -1,77 +1,67 @@
|
|
|
1
|
-
import ElementFounder from './ElementFounder';
|
|
2
|
-
import ElementLabel from './ElementLabel';
|
|
3
|
-
|
|
4
|
-
export default class ElementDialog extends ElementFounder {
|
|
5
|
-
constructor (params) {
|
|
6
|
-
super('dialog', 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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 ElementDialog extends ElementFounder {
|
|
5
|
+
constructor (params) {
|
|
6
|
+
super('dialog', 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
|
+
}
|
package/src/ElementFounder.js
CHANGED
|
@@ -1,85 +1,124 @@
|
|
|
1
|
-
import POSITION from './DataPosition';
|
|
2
|
-
import RECTANGLE from './DataRectangle';
|
|
3
|
-
import BACKGROUND from './DataBackground';
|
|
4
|
-
import STROKE from './DataStroke';
|
|
5
|
-
import FONT from './DataFont';
|
|
6
|
-
|
|
7
|
-
export default class ElementFounder {
|
|
8
|
-
constructor (name, params) {
|
|
9
|
-
this.name = name;
|
|
10
|
-
|
|
11
|
-
this.idm = params.idm;
|
|
12
|
-
}
|
|
13
|
-
/* **************************************************************** *
|
|
14
|
-
* Data
|
|
15
|
-
* **************************************************************** */
|
|
16
|
-
makeTemplateElement (attributes) {
|
|
17
|
-
return {
|
|
18
|
-
...{
|
|
19
|
-
element_type: this.name,
|
|
20
|
-
visible: true,
|
|
21
|
-
_id: null,
|
|
22
|
-
_core: null,
|
|
23
|
-
},
|
|
24
|
-
...attributes
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
makeCrossReference (element, core) {
|
|
28
|
-
element._core = core;
|
|
29
|
-
core._element = element;
|
|
30
|
-
}
|
|
31
|
-
initElementID (element, core) {
|
|
32
|
-
element._id = core.id || this.idm.nextID();
|
|
33
|
-
}
|
|
34
|
-
initElementVisible (element, core) {
|
|
35
|
-
if (core.visible===true || core.visible===false)
|
|
36
|
-
element.visible = core.visible;
|
|
37
|
-
}
|
|
38
|
-
initElementParent (element, parent) {
|
|
39
|
-
if (parent)
|
|
40
|
-
element._parent = parent;
|
|
41
|
-
}
|
|
42
|
-
initElement (element, core, parent) {
|
|
43
|
-
this.makeCrossReference(element, core);
|
|
44
|
-
this.initElementID(element, core);
|
|
45
|
-
this.initElementVisible(element, core);
|
|
46
|
-
this.initElementParent(element, parent);
|
|
47
|
-
}
|
|
48
|
-
fittingRectangle (element, core) {
|
|
49
|
-
element.rectangle = RECTANGLE.build(core.rectangle);
|
|
50
|
-
}
|
|
51
|
-
fittingPosition (element, core) {
|
|
52
|
-
element.position = POSITION.build(core.position);
|
|
53
|
-
}
|
|
54
|
-
fittingBackground (element, core) {
|
|
55
|
-
element.background = BACKGROUND.build(core.background);
|
|
56
|
-
}
|
|
57
|
-
fittingStroke (element, core) {
|
|
58
|
-
element.stroke = STROKE.build(core.stroke || element.stroke);
|
|
59
|
-
}
|
|
60
|
-
fittingFont (element, core) {
|
|
61
|
-
element.font = FONT.build(core.font);
|
|
62
|
-
}
|
|
63
|
-
merge (core, element) {}
|
|
64
|
-
/* **************************************************************** *
|
|
65
|
-
* Draw
|
|
66
|
-
* **************************************************************** */
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
import POSITION from './DataPosition';
|
|
2
|
+
import RECTANGLE from './DataRectangle';
|
|
3
|
+
import BACKGROUND from './DataBackground';
|
|
4
|
+
import STROKE from './DataStroke';
|
|
5
|
+
import FONT from './DataFont';
|
|
6
|
+
|
|
7
|
+
export default class ElementFounder {
|
|
8
|
+
constructor (name, params) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
|
|
11
|
+
this.idm = params.idm;
|
|
12
|
+
}
|
|
13
|
+
/* **************************************************************** *
|
|
14
|
+
* Data
|
|
15
|
+
* **************************************************************** */
|
|
16
|
+
makeTemplateElement (attributes) {
|
|
17
|
+
return {
|
|
18
|
+
...{
|
|
19
|
+
element_type: this.name,
|
|
20
|
+
visible: true,
|
|
21
|
+
_id: null,
|
|
22
|
+
_core: null,
|
|
23
|
+
},
|
|
24
|
+
...attributes
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
makeCrossReference (element, core) {
|
|
28
|
+
element._core = core;
|
|
29
|
+
core._element = element;
|
|
30
|
+
}
|
|
31
|
+
initElementID (element, core) {
|
|
32
|
+
element._id = core.id || this.idm.nextID();
|
|
33
|
+
}
|
|
34
|
+
initElementVisible (element, core) {
|
|
35
|
+
if (core.visible===true || core.visible===false)
|
|
36
|
+
element.visible = core.visible;
|
|
37
|
+
}
|
|
38
|
+
initElementParent (element, parent) {
|
|
39
|
+
if (parent)
|
|
40
|
+
element._parent = parent;
|
|
41
|
+
}
|
|
42
|
+
initElement (element, core, parent) {
|
|
43
|
+
this.makeCrossReference(element, core);
|
|
44
|
+
this.initElementID(element, core);
|
|
45
|
+
this.initElementVisible(element, core);
|
|
46
|
+
this.initElementParent(element, parent);
|
|
47
|
+
}
|
|
48
|
+
fittingRectangle (element, core) {
|
|
49
|
+
element.rectangle = RECTANGLE.build(core.rectangle);
|
|
50
|
+
}
|
|
51
|
+
fittingPosition (element, core) {
|
|
52
|
+
element.position = POSITION.build(core.position);
|
|
53
|
+
}
|
|
54
|
+
fittingBackground (element, core) {
|
|
55
|
+
element.background = BACKGROUND.build(core.background);
|
|
56
|
+
}
|
|
57
|
+
fittingStroke (element, core) {
|
|
58
|
+
element.stroke = STROKE.build(core.stroke || element.stroke);
|
|
59
|
+
}
|
|
60
|
+
fittingFont (element, core) {
|
|
61
|
+
element.font = FONT.build(core.font);
|
|
62
|
+
}
|
|
63
|
+
merge (core, element) {}
|
|
64
|
+
/* **************************************************************** *
|
|
65
|
+
* Draw
|
|
66
|
+
* **************************************************************** */
|
|
67
|
+
/**
|
|
68
|
+
* グループの transform。回転ビュー(projector あり)では絶対座標を
|
|
69
|
+
* 射影して描くため translate は使わない。
|
|
70
|
+
*/
|
|
71
|
+
groupTransform (d, projector) {
|
|
72
|
+
if (projector)
|
|
73
|
+
return null;
|
|
74
|
+
|
|
75
|
+
return `translate(${d.position.x}, ${d.position.y})`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 要素の下地(base)を描く。通常はグループ局所座標の rect、
|
|
79
|
+
* 回転ビューでは絶対座標の4頂点を射影した polygon(角丸 round は
|
|
80
|
+
* 回転ビューでは省略される)。fill/stroke は共通で適用し、
|
|
81
|
+
* 追加の属性は返り値の selection に呼び出し側で付ける。
|
|
82
|
+
*/
|
|
83
|
+
drawBase (g, projector) {
|
|
84
|
+
let base = null;
|
|
85
|
+
|
|
86
|
+
if (projector) {
|
|
87
|
+
base = g.append('polygon')
|
|
88
|
+
.attr('class', 'base')
|
|
89
|
+
.attr('points', d => projector.rectPoints(
|
|
90
|
+
d.position.x, d.position.y, d.rectangle.w, d.rectangle.h,
|
|
91
|
+
projector.depthZ(d._depth)));
|
|
92
|
+
} else {
|
|
93
|
+
base = g.append('rect')
|
|
94
|
+
.attr('class', 'base')
|
|
95
|
+
.attr('width', d => d.rectangle.w)
|
|
96
|
+
.attr('height', d => d.rectangle.h)
|
|
97
|
+
.attr('rx', d => d.round || 0)
|
|
98
|
+
.attr('ry', d => d.round || 0);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return base
|
|
102
|
+
.attr('fill', d => d.background.color)
|
|
103
|
+
.attr('stroke', d => this.stroke(d))
|
|
104
|
+
.attr('stroke-width', d => this.strokeWidth(d));
|
|
105
|
+
}
|
|
106
|
+
stroke (d) {
|
|
107
|
+
if (!d.stroke)
|
|
108
|
+
return null;
|
|
109
|
+
|
|
110
|
+
if (!d.stroke)
|
|
111
|
+
return '#333';
|
|
112
|
+
|
|
113
|
+
return d.stroke.color || '#333';
|
|
114
|
+
}
|
|
115
|
+
strokeWidth (d) {
|
|
116
|
+
if (!d.stroke)
|
|
117
|
+
return null;
|
|
118
|
+
|
|
119
|
+
if (!d.stroke)
|
|
120
|
+
return 1;
|
|
121
|
+
|
|
122
|
+
return d.stroke.width || 1;
|
|
123
|
+
}
|
|
124
|
+
}
|