@yanqirenshi/d3.wireframe 0.1.0 → 0.2.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/dist/Element.js +2 -2
- package/dist/ElementButton.js +7 -21
- package/dist/ElementDialog.js +6 -20
- package/dist/ElementFounder.js +44 -0
- package/dist/ElementFrame.js +6 -20
- package/dist/ElementIcon.js +15 -3
- package/dist/ElementImage.js +6 -20
- package/dist/ElementLabel.js +13 -4
- package/dist/ElementModal.js +9 -11
- 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 -3
- package/src/Element.js +2 -2
- package/src/ElementButton.js +7 -17
- package/src/ElementDialog.js +6 -16
- package/src/ElementFounder.js +39 -0
- package/src/ElementFrame.js +6 -16
- package/src/ElementIcon.js +19 -3
- package/src/ElementImage.js +6 -16
- package/src/ElementLabel.js +19 -4
- package/src/ElementModal.js +9 -13
- 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/babel.config.js +0 -10
- package/jest.config.js +0 -23
- package/tests/D3Wireframe.test.js +0 -54
- package/tests/d3-stub.js +0 -4
package/dist/Element.js
CHANGED
|
@@ -79,14 +79,14 @@ var Element = exports["default"] = /*#__PURE__*/function () {
|
|
|
79
79
|
* **************************************************************** */
|
|
80
80
|
}, {
|
|
81
81
|
key: "draw",
|
|
82
|
-
value: function draw(place, list) {
|
|
82
|
+
value: function draw(place, list, projector) {
|
|
83
83
|
var _iterator = _createForOfIteratorHelper(list),
|
|
84
84
|
_step;
|
|
85
85
|
try {
|
|
86
86
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
87
87
|
var data = _step.value;
|
|
88
88
|
var ec = this.elementClass(data);
|
|
89
|
-
ec.draw(place, data);
|
|
89
|
+
ec.draw(place, data, projector);
|
|
90
90
|
}
|
|
91
91
|
} catch (err) {
|
|
92
92
|
_iterator.e(err);
|
package/dist/ElementButton.js
CHANGED
|
@@ -78,30 +78,16 @@ var ElementButton = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
78
78
|
* **************************************************************** */
|
|
79
79
|
}, {
|
|
80
80
|
key: "drawAdd",
|
|
81
|
-
value: function drawAdd(place, data) {
|
|
81
|
+
value: function drawAdd(place, data, projector) {
|
|
82
82
|
var _this2 = this;
|
|
83
83
|
var g = place.selectAll("g.".concat(this.name)).data([data], function (d) {
|
|
84
84
|
return d._id;
|
|
85
85
|
}).enter().append('g').attr('class', this.name).attr("transform", function (d) {
|
|
86
|
-
return
|
|
86
|
+
return _this2.groupTransform(d, projector);
|
|
87
87
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return d.rectangle.h;
|
|
92
|
-
}).attr('rx', function (d) {
|
|
93
|
-
return d.round || 0;
|
|
94
|
-
}).attr('ry', function (d) {
|
|
95
|
-
return d.round || 0;
|
|
96
|
-
}).attr('fill', function (d) {
|
|
97
|
-
return d.background.color;
|
|
98
|
-
}).attr('stroke', function (d) {
|
|
99
|
-
return _this2.stroke(d);
|
|
100
|
-
}).attr('stroke-width', function (d) {
|
|
101
|
-
return _this2.strokeWidth(d);
|
|
102
|
-
});
|
|
103
|
-
this.icon.draw(g, data);
|
|
104
|
-
this.label.draw(g, data);
|
|
88
|
+
this.drawBase(g, projector);
|
|
89
|
+
this.icon.draw(g, data, projector);
|
|
90
|
+
this.label.draw(g, data, projector);
|
|
105
91
|
}
|
|
106
92
|
}, {
|
|
107
93
|
key: "drawUpdate",
|
|
@@ -119,10 +105,10 @@ var ElementButton = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
119
105
|
}
|
|
120
106
|
}, {
|
|
121
107
|
key: "draw",
|
|
122
|
-
value: function draw(place, data) {
|
|
108
|
+
value: function draw(place, data, projector) {
|
|
123
109
|
// this.drawDelete(place, data);
|
|
124
110
|
this.drawUpdate(place, data);
|
|
125
|
-
this.drawAdd(place, data);
|
|
111
|
+
this.drawAdd(place, data, projector);
|
|
126
112
|
}
|
|
127
113
|
}]);
|
|
128
114
|
}(_ElementFounder2["default"]);
|
package/dist/ElementDialog.js
CHANGED
|
@@ -63,29 +63,15 @@ var ElementDialog = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
63
63
|
* **************************************************************** */
|
|
64
64
|
}, {
|
|
65
65
|
key: "drawAdd",
|
|
66
|
-
value: function drawAdd(place, data) {
|
|
66
|
+
value: function drawAdd(place, data, projector) {
|
|
67
67
|
var _this2 = this;
|
|
68
68
|
var g = place.selectAll("g.".concat(this.name)).data([data], function (d) {
|
|
69
69
|
return d._id;
|
|
70
70
|
}).enter().append('g').attr('class', this.name).attr("transform", function (d) {
|
|
71
|
-
return
|
|
71
|
+
return _this2.groupTransform(d, projector);
|
|
72
72
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}).attr('height', function (d) {
|
|
76
|
-
return d.rectangle.h;
|
|
77
|
-
}).attr('rx', function (d) {
|
|
78
|
-
return d.round || 0;
|
|
79
|
-
}).attr('ry', function (d) {
|
|
80
|
-
return d.round || 0;
|
|
81
|
-
}).attr('fill', function (d) {
|
|
82
|
-
return d.background.color;
|
|
83
|
-
}).attr('stroke', function (d) {
|
|
84
|
-
return _this2.stroke(d);
|
|
85
|
-
}).attr('stroke-width', function (d) {
|
|
86
|
-
return _this2.strokeWidth(d);
|
|
87
|
-
});
|
|
88
|
-
this.label.draw(g, data);
|
|
73
|
+
this.drawBase(g, projector);
|
|
74
|
+
this.label.draw(g, data, projector);
|
|
89
75
|
}
|
|
90
76
|
}, {
|
|
91
77
|
key: "drawUpdate",
|
|
@@ -103,10 +89,10 @@ var ElementDialog = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
103
89
|
}
|
|
104
90
|
}, {
|
|
105
91
|
key: "draw",
|
|
106
|
-
value: function draw(place, data) {
|
|
92
|
+
value: function draw(place, data, projector) {
|
|
107
93
|
// this.drawDelete(place, data);
|
|
108
94
|
this.drawUpdate(place, data);
|
|
109
|
-
this.drawAdd(place, data);
|
|
95
|
+
this.drawAdd(place, data, projector);
|
|
110
96
|
}
|
|
111
97
|
}]);
|
|
112
98
|
}(_ElementFounder2["default"]);
|
package/dist/ElementFounder.js
CHANGED
|
@@ -98,6 +98,50 @@ var ElementFounder = exports["default"] = /*#__PURE__*/function () {
|
|
|
98
98
|
/* **************************************************************** *
|
|
99
99
|
* Draw
|
|
100
100
|
* **************************************************************** */
|
|
101
|
+
/**
|
|
102
|
+
* グループの transform。回転ビュー(projector あり)では絶対座標を
|
|
103
|
+
* 射影して描くため translate は使わない。
|
|
104
|
+
*/
|
|
105
|
+
}, {
|
|
106
|
+
key: "groupTransform",
|
|
107
|
+
value: function groupTransform(d, projector) {
|
|
108
|
+
if (projector) return null;
|
|
109
|
+
return "translate(".concat(d.position.x, ", ").concat(d.position.y, ")");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 要素の下地(base)を描く。通常はグループ局所座標の rect、
|
|
113
|
+
* 回転ビューでは絶対座標の4頂点を射影した polygon(角丸 round は
|
|
114
|
+
* 回転ビューでは省略される)。fill/stroke は共通で適用し、
|
|
115
|
+
* 追加の属性は返り値の selection に呼び出し側で付ける。
|
|
116
|
+
*/
|
|
117
|
+
}, {
|
|
118
|
+
key: "drawBase",
|
|
119
|
+
value: function drawBase(g, projector) {
|
|
120
|
+
var _this = this;
|
|
121
|
+
var base = null;
|
|
122
|
+
if (projector) {
|
|
123
|
+
base = g.append('polygon').attr('class', 'base').attr('points', function (d) {
|
|
124
|
+
return projector.rectPoints(d.position.x, d.position.y, d.rectangle.w, d.rectangle.h, projector.depthZ(d._depth));
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
base = g.append('rect').attr('class', 'base').attr('width', function (d) {
|
|
128
|
+
return d.rectangle.w;
|
|
129
|
+
}).attr('height', function (d) {
|
|
130
|
+
return d.rectangle.h;
|
|
131
|
+
}).attr('rx', function (d) {
|
|
132
|
+
return d.round || 0;
|
|
133
|
+
}).attr('ry', function (d) {
|
|
134
|
+
return d.round || 0;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return base.attr('fill', function (d) {
|
|
138
|
+
return d.background.color;
|
|
139
|
+
}).attr('stroke', function (d) {
|
|
140
|
+
return _this.stroke(d);
|
|
141
|
+
}).attr('stroke-width', function (d) {
|
|
142
|
+
return _this.strokeWidth(d);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
101
145
|
}, {
|
|
102
146
|
key: "stroke",
|
|
103
147
|
value: function stroke(d) {
|
package/dist/ElementFrame.js
CHANGED
|
@@ -63,29 +63,15 @@ var ElementFrame = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
63
63
|
* **************************************************************** */
|
|
64
64
|
}, {
|
|
65
65
|
key: "drawAdd",
|
|
66
|
-
value: function drawAdd(place, data) {
|
|
66
|
+
value: function drawAdd(place, data, projector) {
|
|
67
67
|
var _this2 = this;
|
|
68
68
|
var g = place.selectAll("g.".concat(this.name)).data([data], function (d) {
|
|
69
69
|
return d._id;
|
|
70
70
|
}).enter().append('g').attr('class', this.name).attr("transform", function (d) {
|
|
71
|
-
return
|
|
71
|
+
return _this2.groupTransform(d, projector);
|
|
72
72
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}).attr('height', function (d) {
|
|
76
|
-
return d.rectangle.h;
|
|
77
|
-
}).attr('rx', function (d) {
|
|
78
|
-
return d.round || 0;
|
|
79
|
-
}).attr('ry', function (d) {
|
|
80
|
-
return d.round || 0;
|
|
81
|
-
}).attr('fill', function (d) {
|
|
82
|
-
return d.background.color;
|
|
83
|
-
}).attr('stroke', function (d) {
|
|
84
|
-
return _this2.stroke(d);
|
|
85
|
-
}).attr('stroke-width', function (d) {
|
|
86
|
-
return _this2.strokeWidth(d);
|
|
87
|
-
});
|
|
88
|
-
this.label.draw(g, data);
|
|
73
|
+
this.drawBase(g, projector);
|
|
74
|
+
this.label.draw(g, data, projector);
|
|
89
75
|
}
|
|
90
76
|
}, {
|
|
91
77
|
key: "drawUpdate",
|
|
@@ -103,10 +89,10 @@ var ElementFrame = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
103
89
|
}
|
|
104
90
|
}, {
|
|
105
91
|
key: "draw",
|
|
106
|
-
value: function draw(place, data) {
|
|
92
|
+
value: function draw(place, data, projector) {
|
|
107
93
|
// this.drawDelete(place, data);
|
|
108
94
|
this.drawUpdate(place, data);
|
|
109
|
-
this.drawAdd(place, data);
|
|
95
|
+
this.drawAdd(place, data, projector);
|
|
110
96
|
}
|
|
111
97
|
}]);
|
|
112
98
|
}(_ElementFounder2["default"]);
|
package/dist/ElementIcon.js
CHANGED
|
@@ -62,17 +62,29 @@ var ElementIcon = exports["default"] = /*#__PURE__*/function (_ElementFounder) {
|
|
|
62
62
|
/* **************************************************************** *
|
|
63
63
|
* Draw
|
|
64
64
|
* **************************************************************** */
|
|
65
|
+
/**
|
|
66
|
+
* アイコン(画像)を描く。SVG の <image> は polygon 化できないため、
|
|
67
|
+
* 回転ビュー(projector あり)では要素の3隅を正確に写す近似 affine
|
|
68
|
+
* 行列で変形する(アイコンは小さいので誤差は実用上見えない)。
|
|
69
|
+
*/
|
|
65
70
|
}, {
|
|
66
71
|
key: "draw",
|
|
67
|
-
value: function draw(place, data) {
|
|
72
|
+
value: function draw(place, data, projector) {
|
|
68
73
|
place.selectAll('image').data(data.icons || [], function (d) {
|
|
69
74
|
return d._id;
|
|
70
75
|
}).enter().append('image').attr('xlink:href', function (d) {
|
|
71
76
|
return d.url;
|
|
77
|
+
}).attr('transform', function (d) {
|
|
78
|
+
if (!projector) return null;
|
|
79
|
+
var x = data.position.x + (d.position && d.position.x || 0);
|
|
80
|
+
var y = data.position.y + (d.position && d.position.y || 0);
|
|
81
|
+
var w = d.size && d.size.w || d.rectangle.w;
|
|
82
|
+
var h = d.size && d.size.h || d.rectangle.h;
|
|
83
|
+
return projector.affine(x, y, w, h, projector.depthZ(data._depth));
|
|
72
84
|
}).attr('x', function (d) {
|
|
73
|
-
return d.position && d.position.x || 0;
|
|
85
|
+
return projector ? 0 : d.position && d.position.x || 0;
|
|
74
86
|
}).attr('y', function (d) {
|
|
75
|
-
return d.position && d.position.y || 0;
|
|
87
|
+
return projector ? 0 : d.position && d.position.y || 0;
|
|
76
88
|
}).attr('width', function (d) {
|
|
77
89
|
return d.size && d.size.w || d.rectangle.w;
|
|
78
90
|
}).attr('height', function (d) {
|
package/dist/ElementImage.js
CHANGED
|
@@ -63,29 +63,15 @@ var ElementImage = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
63
63
|
* **************************************************************** */
|
|
64
64
|
}, {
|
|
65
65
|
key: "drawAdd",
|
|
66
|
-
value: function drawAdd(place, data) {
|
|
66
|
+
value: function drawAdd(place, data, projector) {
|
|
67
67
|
var _this2 = this;
|
|
68
68
|
var g = place.selectAll("g.".concat(this.name)).data([data], function (d) {
|
|
69
69
|
return d._id;
|
|
70
70
|
}).enter().append('g').attr('class', this.name).attr("transform", function (d) {
|
|
71
|
-
return
|
|
71
|
+
return _this2.groupTransform(d, projector);
|
|
72
72
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}).attr('height', function (d) {
|
|
76
|
-
return d.rectangle.h;
|
|
77
|
-
}).attr('rx', function (d) {
|
|
78
|
-
return d.round || 0;
|
|
79
|
-
}).attr('ry', function (d) {
|
|
80
|
-
return d.round || 0;
|
|
81
|
-
}).attr('fill', function (d) {
|
|
82
|
-
return d.background.color;
|
|
83
|
-
}).attr('stroke', function (d) {
|
|
84
|
-
return _this2.stroke(d);
|
|
85
|
-
}).attr('stroke-width', function (d) {
|
|
86
|
-
return _this2.strokeWidth(d);
|
|
87
|
-
});
|
|
88
|
-
this.label.draw(g, data);
|
|
73
|
+
this.drawBase(g, projector);
|
|
74
|
+
this.label.draw(g, data, projector);
|
|
89
75
|
}
|
|
90
76
|
}, {
|
|
91
77
|
key: "drawUpdate",
|
|
@@ -103,10 +89,10 @@ var ElementImage = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
103
89
|
}
|
|
104
90
|
}, {
|
|
105
91
|
key: "draw",
|
|
106
|
-
value: function draw(place, data) {
|
|
92
|
+
value: function draw(place, data, projector) {
|
|
107
93
|
// this.drawDelete(place, data);
|
|
108
94
|
this.drawUpdate(place, data);
|
|
109
|
-
this.drawAdd(place, data);
|
|
95
|
+
this.drawAdd(place, data, projector);
|
|
110
96
|
}
|
|
111
97
|
}]);
|
|
112
98
|
}(_ElementFounder2["default"]);
|
package/dist/ElementLabel.js
CHANGED
|
@@ -59,17 +59,26 @@ var ElementLabel = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
59
59
|
/* **************************************************************** *
|
|
60
60
|
* Draw
|
|
61
61
|
* **************************************************************** */
|
|
62
|
+
/**
|
|
63
|
+
* ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
|
|
64
|
+
* ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
|
|
65
|
+
* 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
|
|
66
|
+
*/
|
|
62
67
|
}, {
|
|
63
68
|
key: "draw",
|
|
64
|
-
value: function draw(place, data) {
|
|
69
|
+
value: function draw(place, data, projector) {
|
|
70
|
+
var project = function project(d) {
|
|
71
|
+
return projector.point(data.position.x + d.position.x, data.position.y + d.position.y, projector.depthZ(data._depth));
|
|
72
|
+
};
|
|
65
73
|
place.selectAll('label').data(data.labels, function (d) {
|
|
66
74
|
return d._id;
|
|
67
75
|
}).enter().append("text").attr("x", function (d) {
|
|
68
|
-
return d.position.x;
|
|
76
|
+
return projector ? project(d).x : d.position.x;
|
|
69
77
|
}).attr("y", function (d) {
|
|
70
|
-
return d.position.y;
|
|
78
|
+
return projector ? project(d).y : d.position.y;
|
|
71
79
|
}).style("font-size", function (d) {
|
|
72
|
-
return "".concat(d.font.size, "px");
|
|
80
|
+
if (!projector) return "".concat(d.font.size, "px");
|
|
81
|
+
return "".concat(d.font.size * project(d).k, "px");
|
|
73
82
|
}).style("fill", function (d) {
|
|
74
83
|
return d.font.color;
|
|
75
84
|
}).style("font-weight", function (d) {
|
package/dist/ElementModal.js
CHANGED
|
@@ -52,19 +52,17 @@ var ElementModal = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
52
52
|
* **************************************************************** */
|
|
53
53
|
}, {
|
|
54
54
|
key: "drawAdd",
|
|
55
|
-
value: function drawAdd(place, data) {
|
|
55
|
+
value: function drawAdd(place, data, projector) {
|
|
56
|
+
var _this = this;
|
|
56
57
|
var g = place.selectAll("g.".concat(this.name)).data([data], function (d) {
|
|
57
58
|
return d._id;
|
|
58
59
|
}).enter().append('g').attr('class', this.name).attr("transform", function (d) {
|
|
59
|
-
return
|
|
60
|
+
return _this.groupTransform(d, projector);
|
|
60
61
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}).attr('rx', 0).attr('ry', 0).attr('fill', function (d) {
|
|
66
|
-
return d.background.color;
|
|
67
|
-
}).attr('fill-opacity', function (d) {
|
|
62
|
+
|
|
63
|
+
// modal は stroke 無し + 半透明の面。共通の drawBase(rect/polygon の
|
|
64
|
+
// 切替)を使い、追加の属性だけここで上書きする。
|
|
65
|
+
this.drawBase(g, projector).attr('stroke', null).attr('stroke-width', null).attr('fill-opacity', function (d) {
|
|
68
66
|
return d.background.opacity;
|
|
69
67
|
});
|
|
70
68
|
}
|
|
@@ -84,10 +82,10 @@ var ElementModal = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
84
82
|
}
|
|
85
83
|
}, {
|
|
86
84
|
key: "draw",
|
|
87
|
-
value: function draw(place, data) {
|
|
85
|
+
value: function draw(place, data, projector) {
|
|
88
86
|
// this.drawDelete(place, data);
|
|
89
87
|
this.drawUpdate(place, data);
|
|
90
|
-
this.drawAdd(place, data);
|
|
88
|
+
this.drawAdd(place, data, projector);
|
|
91
89
|
}
|
|
92
90
|
}]);
|
|
93
91
|
}(_ElementFounder2["default"]);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
9
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
10
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
/**
|
|
14
|
+
* 回転ビュー用の透視投影(データクラス — DOM/d3 非依存)。
|
|
15
|
+
*
|
|
16
|
+
* レイアウト平面(z=0)上の点を、origin を中心に Y軸 → X軸の順で回転し、
|
|
17
|
+
* 視点距離 perspective から透視投影して 2D 座標に落とす。
|
|
18
|
+
* SVG の transform は affine のみで透視変換を持たないため、矩形は
|
|
19
|
+
* 4頂点をこのクラスで射影して polygon として描く(ペインタ側)。
|
|
20
|
+
* 文字は SVG では遠近で歪ませられないので、射影後の位置 + 距離に応じた
|
|
21
|
+
* スケール(k)で近似する。
|
|
22
|
+
*
|
|
23
|
+
* config:
|
|
24
|
+
* y: Y軸(縦軸)回りの回転角(度)。正で右側が奥に倒れる
|
|
25
|
+
* x: X軸(横軸)回りの回転角(度)。正で下側が奥に倒れる
|
|
26
|
+
* perspective: 視点距離(px、既定 1600)。小さいほどパースが強い
|
|
27
|
+
* origin: 回転の中心 { x, y }(レイアウト座標。既定 {0,0})
|
|
28
|
+
* lift: 入れ子1階層ごとに子を手前(視点側)へ浮かせる距離(px、
|
|
29
|
+
* 既定 0)。親平面と子パネルの間に奥行きの隙間ができる
|
|
30
|
+
*/
|
|
31
|
+
var Projector = exports["default"] = /*#__PURE__*/function () {
|
|
32
|
+
function Projector(config) {
|
|
33
|
+
_classCallCheck(this, Projector);
|
|
34
|
+
var cfg = config || {};
|
|
35
|
+
this._ry = this.deg2rad(cfg.y || 0);
|
|
36
|
+
this._rx = this.deg2rad(cfg.x || 0);
|
|
37
|
+
this._f = cfg.perspective || 1600;
|
|
38
|
+
this._lift = cfg.lift || 0;
|
|
39
|
+
this._origin = {
|
|
40
|
+
x: cfg.origin && (cfg.origin.x || cfg.origin.x === 0) ? cfg.origin.x : 0,
|
|
41
|
+
y: cfg.origin && (cfg.origin.y || cfg.origin.y === 0) ? cfg.origin.y : 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return _createClass(Projector, [{
|
|
45
|
+
key: "deg2rad",
|
|
46
|
+
value: function deg2rad(degree) {
|
|
47
|
+
return degree * (Math.PI / 180);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 入れ子の深さ(ルート=0)を z 座標に変換する。
|
|
51
|
+
* 負の z = 視点側(手前)。lift × 深さ だけ浮く。
|
|
52
|
+
*/
|
|
53
|
+
}, {
|
|
54
|
+
key: "depthZ",
|
|
55
|
+
value: function depthZ(depth) {
|
|
56
|
+
return -((depth || 0) * this._lift);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* レイアウト座標 (x, y)(+任意の z。負=手前)を射影する。
|
|
60
|
+
* @returns { x, y, k } k は距離に応じたスケール(手前 >1 / 奥 <1)。
|
|
61
|
+
* 文字サイズの近似スケールに使う。
|
|
62
|
+
*/
|
|
63
|
+
}, {
|
|
64
|
+
key: "point",
|
|
65
|
+
value: function point(x, y, z) {
|
|
66
|
+
var px = x - this._origin.x;
|
|
67
|
+
var py = y - this._origin.y;
|
|
68
|
+
var pz = z || 0;
|
|
69
|
+
|
|
70
|
+
// Y軸回転: x1 = px cosθ - pz sinθ, z1 = px sinθ + pz cosθ
|
|
71
|
+
var x1 = px * Math.cos(this._ry) - pz * Math.sin(this._ry);
|
|
72
|
+
var z1 = px * Math.sin(this._ry) + pz * Math.cos(this._ry);
|
|
73
|
+
|
|
74
|
+
// X軸回転: y2 = py cosφ - z1 sinφ, z2 = py sinφ + z1 cosφ
|
|
75
|
+
var y2 = py * Math.cos(this._rx) - z1 * Math.sin(this._rx);
|
|
76
|
+
var z2 = py * Math.sin(this._rx) + z1 * Math.cos(this._rx);
|
|
77
|
+
|
|
78
|
+
// 透視投影(奥 = z が大きいほど縮む)
|
|
79
|
+
var k = this._f / (this._f + z2);
|
|
80
|
+
return {
|
|
81
|
+
x: this._origin.x + x1 * k,
|
|
82
|
+
y: this._origin.y + y2 * k,
|
|
83
|
+
k: k
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 矩形(x, y, w, h)の4頂点を射影し、SVG polygon の points 文字列にする。
|
|
88
|
+
*/
|
|
89
|
+
}, {
|
|
90
|
+
key: "rectPoints",
|
|
91
|
+
value: function rectPoints(x, y, w, h, z) {
|
|
92
|
+
var corners = [this.point(x, y, z), this.point(x + w, y, z), this.point(x + w, y + h, z), this.point(x, y + h, z)];
|
|
93
|
+
return corners.map(function (p) {
|
|
94
|
+
return p.x + ',' + p.y;
|
|
95
|
+
}).join(' ');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* polygon 化できない要素(画像アイコンなど)向けの近似 affine 行列。
|
|
99
|
+
* 要素の局所座標 (0,0), (w,0), (0,h) を射影先へ正確に写す
|
|
100
|
+
* matrix(a,b,c,d,e,f) を返す(4隅のうち残り1隅は近似 — 小さい要素用)。
|
|
101
|
+
*/
|
|
102
|
+
}, {
|
|
103
|
+
key: "affine",
|
|
104
|
+
value: function affine(x, y, w, h, z) {
|
|
105
|
+
var p0 = this.point(x, y, z);
|
|
106
|
+
var p1 = this.point(x + w, y, z);
|
|
107
|
+
var p3 = this.point(x, y + h, z);
|
|
108
|
+
var a = (p1.x - p0.x) / w;
|
|
109
|
+
var b = (p1.y - p0.y) / w;
|
|
110
|
+
var c = (p3.x - p0.x) / h;
|
|
111
|
+
var d = (p3.y - p0.y) / h;
|
|
112
|
+
return "matrix(".concat(a, ",").concat(b, ",").concat(c, ",").concat(d, ",").concat(p0.x, ",").concat(p0.y, ")");
|
|
113
|
+
}
|
|
114
|
+
}]);
|
|
115
|
+
}();
|