@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/dist/ElementImage.js
CHANGED
|
@@ -30,8 +30,8 @@ var ElementImage = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
30
30
|
});
|
|
31
31
|
return _this;
|
|
32
32
|
}
|
|
33
|
-
/* **************************************************************** *
|
|
34
|
-
* Data
|
|
33
|
+
/* **************************************************************** *
|
|
34
|
+
* Data
|
|
35
35
|
* **************************************************************** */
|
|
36
36
|
_inherits(ElementImage, _ElementFounder);
|
|
37
37
|
return _createClass(ElementImage, [{
|
|
@@ -58,34 +58,20 @@ var ElementImage = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
58
58
|
element.labels = this.label.makeElements(core.labels);
|
|
59
59
|
return element;
|
|
60
60
|
}
|
|
61
|
-
/* **************************************************************** *
|
|
62
|
-
* Draw
|
|
61
|
+
/* **************************************************************** *
|
|
62
|
+
* Draw
|
|
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
|
@@ -24,8 +24,8 @@ var ElementLabel = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
24
24
|
_classCallCheck(this, ElementLabel);
|
|
25
25
|
return _callSuper(this, ElementLabel, ['label', params]);
|
|
26
26
|
}
|
|
27
|
-
/* **************************************************************** *
|
|
28
|
-
* Data
|
|
27
|
+
/* **************************************************************** *
|
|
28
|
+
* Data
|
|
29
29
|
* **************************************************************** */
|
|
30
30
|
_inherits(ElementLabel, _ElementFounder);
|
|
31
31
|
return _createClass(ElementLabel, [{
|
|
@@ -56,20 +56,29 @@ var ElementLabel = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
56
56
|
return _this.makeElement(d);
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
/* **************************************************************** *
|
|
60
|
-
* Draw
|
|
59
|
+
/* **************************************************************** *
|
|
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
|
@@ -24,8 +24,8 @@ var ElementModal = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
24
24
|
_classCallCheck(this, ElementModal);
|
|
25
25
|
return _callSuper(this, ElementModal, ['modal', params]);
|
|
26
26
|
}
|
|
27
|
-
/* **************************************************************** *
|
|
28
|
-
* Data
|
|
27
|
+
/* **************************************************************** *
|
|
28
|
+
* Data
|
|
29
29
|
* **************************************************************** */
|
|
30
30
|
_inherits(ElementModal, _ElementFounder);
|
|
31
31
|
return _createClass(ElementModal, [{
|
|
@@ -47,24 +47,22 @@ var ElementModal = exports["default"] = /*#__PURE__*/function (_ElementFounder)
|
|
|
47
47
|
this.fittingBackground(element, core);
|
|
48
48
|
return element;
|
|
49
49
|
}
|
|
50
|
-
/* **************************************************************** *
|
|
51
|
-
* Draw
|
|
50
|
+
/* **************************************************************** *
|
|
51
|
+
* Draw
|
|
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
|
+
}();
|
package/dist/Rectum.js
CHANGED
|
@@ -7,11 +7,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _assh0le = require("@yanqirenshi/assh0le");
|
|
9
9
|
var _Element = _interopRequireDefault(require("./Element"));
|
|
10
|
+
var _Projector = _interopRequireDefault(require("./Projector"));
|
|
10
11
|
var _Drawer = require("./Drawer.js");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
13
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
13
14
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
15
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
15
19
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
16
20
|
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); } }
|
|
17
21
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -44,13 +48,137 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
44
48
|
ht: {},
|
|
45
49
|
list: []
|
|
46
50
|
};
|
|
51
|
+
|
|
52
|
+
// 回転ビュー(任意)。{ y, x, perspective, origin } を渡すと
|
|
53
|
+
// レイアウト平面を透視投影して描く(Projector 参照)。
|
|
54
|
+
_this._rotation = params && params.rotation || null;
|
|
47
55
|
return _this;
|
|
48
56
|
}
|
|
49
57
|
/* **************************************************************** *
|
|
50
|
-
*
|
|
58
|
+
* Rotation (回転ビュー)
|
|
51
59
|
* **************************************************************** */
|
|
52
60
|
_inherits(Rectum, _Colon);
|
|
53
61
|
return _createClass(Rectum, [{
|
|
62
|
+
key: "selector_setAfter",
|
|
63
|
+
value: function selector_setAfter() {
|
|
64
|
+
this.attachRotateDrag();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Ctrl + グラブ(ドラッグ)でレイアウトを回転させる対話操作。
|
|
68
|
+
* パン/ズーム(d3.zoom)は Ctrl 押下の mousedown を既定 filter で
|
|
69
|
+
* 無視するため、通常のグラブ移動とは競合しない。
|
|
70
|
+
* 横移動 → y(縦軸回り)、縦移動 → x(横軸回り)を 0.25度/px で加減し、
|
|
71
|
+
* ±80度でクランプする(平面が裏返って表示が壊れないように)。
|
|
72
|
+
* 平面表示(rotation 未指定)から始めた場合は、回転中心に要素全体の
|
|
73
|
+
* バウンディング中心を使う。
|
|
74
|
+
*/
|
|
75
|
+
}, {
|
|
76
|
+
key: "attachRotateDrag",
|
|
77
|
+
value: function attachRotateDrag() {
|
|
78
|
+
var _this2 = this;
|
|
79
|
+
var svg = this.d3Element();
|
|
80
|
+
if (!svg) return;
|
|
81
|
+
var DEG_PER_PX = 0.25;
|
|
82
|
+
svg.on('mousedown.wf-rotate', function (event) {
|
|
83
|
+
if (!event.ctrlKey || event.button !== 0) return;
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
var base = _this2._rotation || {};
|
|
86
|
+
var start = {
|
|
87
|
+
mx: event.clientX,
|
|
88
|
+
my: event.clientY,
|
|
89
|
+
y: base.y || 0,
|
|
90
|
+
x: base.x || 0
|
|
91
|
+
};
|
|
92
|
+
var rest = {
|
|
93
|
+
perspective: base.perspective,
|
|
94
|
+
origin: base.origin || _this2.defaultOrigin(),
|
|
95
|
+
lift: base.lift
|
|
96
|
+
};
|
|
97
|
+
var move = function move(e) {
|
|
98
|
+
_this2.rotation(_objectSpread(_objectSpread({}, rest), {}, {
|
|
99
|
+
y: _this2.clampAngle(start.y + (e.clientX - start.mx) * DEG_PER_PX),
|
|
100
|
+
x: _this2.clampAngle(start.x + (e.clientY - start.my) * DEG_PER_PX)
|
|
101
|
+
}));
|
|
102
|
+
};
|
|
103
|
+
var _up = function up() {
|
|
104
|
+
window.removeEventListener('mousemove', move);
|
|
105
|
+
window.removeEventListener('mouseup', _up);
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener('mousemove', move);
|
|
108
|
+
window.addEventListener('mouseup', _up);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** 回転角のクランプ(±80度。±90度で平面が真横になり、越えると裏返る) */
|
|
112
|
+
}, {
|
|
113
|
+
key: "clampAngle",
|
|
114
|
+
value: function clampAngle(v) {
|
|
115
|
+
var LIMIT = 80;
|
|
116
|
+
return Math.max(-LIMIT, Math.min(LIMIT, v));
|
|
117
|
+
}
|
|
118
|
+
/** 回転中心の既定値: ルート要素群のバウンディング中心 */
|
|
119
|
+
}, {
|
|
120
|
+
key: "defaultOrigin",
|
|
121
|
+
value: function defaultOrigin() {
|
|
122
|
+
var list = this._elements.list;
|
|
123
|
+
if (!list || list.length === 0) return {
|
|
124
|
+
x: 0,
|
|
125
|
+
y: 0
|
|
126
|
+
};
|
|
127
|
+
var min = {
|
|
128
|
+
x: Infinity,
|
|
129
|
+
y: Infinity
|
|
130
|
+
};
|
|
131
|
+
var max = {
|
|
132
|
+
x: -Infinity,
|
|
133
|
+
y: -Infinity
|
|
134
|
+
};
|
|
135
|
+
var _iterator = _createForOfIteratorHelper(list),
|
|
136
|
+
_step;
|
|
137
|
+
try {
|
|
138
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
139
|
+
var d = _step.value;
|
|
140
|
+
min.x = Math.min(min.x, d.position.x);
|
|
141
|
+
min.y = Math.min(min.y, d.position.y);
|
|
142
|
+
max.x = Math.max(max.x, d.position.x + d.rectangle.w);
|
|
143
|
+
max.y = Math.max(max.y, d.position.y + d.rectangle.h);
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
_iterator.e(err);
|
|
147
|
+
} finally {
|
|
148
|
+
_iterator.f();
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
x: (min.x + max.x) / 2,
|
|
152
|
+
y: (min.y + max.y) / 2
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "projector",
|
|
157
|
+
value: function projector() {
|
|
158
|
+
if (!this._rotation) return null;
|
|
159
|
+
return new _Projector["default"](this._rotation);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 回転設定の取得/変更。変更時は描画済みのレイヤを空にして描き直す
|
|
163
|
+
* (要素ペインタは enter join のため、その場更新ではなく再描画する)。
|
|
164
|
+
* null を渡すと通常の平面表示に戻る。
|
|
165
|
+
*/
|
|
166
|
+
}, {
|
|
167
|
+
key: "rotation",
|
|
168
|
+
value: function rotation(v) {
|
|
169
|
+
if (arguments.length === 0) return this._rotation;
|
|
170
|
+
this._rotation = v;
|
|
171
|
+
var place = this.layer('foreground');
|
|
172
|
+
if (place) {
|
|
173
|
+
place.selectAll('*').remove();
|
|
174
|
+
this.draw();
|
|
175
|
+
}
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
/* **************************************************************** *
|
|
179
|
+
* Make Elements
|
|
180
|
+
* **************************************************************** */
|
|
181
|
+
}, {
|
|
54
182
|
key: "firstObject",
|
|
55
183
|
value: function firstObject(list) {
|
|
56
184
|
if (list.length === 0) return null;
|
|
@@ -100,19 +228,19 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
100
228
|
list: []
|
|
101
229
|
};
|
|
102
230
|
var dh = new _Drawer.DrawerHierarchy();
|
|
103
|
-
var
|
|
104
|
-
|
|
231
|
+
var _iterator2 = _createForOfIteratorHelper(new_list),
|
|
232
|
+
_step2;
|
|
105
233
|
try {
|
|
106
|
-
for (
|
|
107
|
-
var d =
|
|
234
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
235
|
+
var d = _step2.value;
|
|
108
236
|
dh.fitting(d);
|
|
109
237
|
pool.ht[d._id] = d;
|
|
110
238
|
pool.list.push(d);
|
|
111
239
|
}
|
|
112
240
|
} catch (err) {
|
|
113
|
-
|
|
241
|
+
_iterator2.e(err);
|
|
114
242
|
} finally {
|
|
115
|
-
|
|
243
|
+
_iterator2.f();
|
|
116
244
|
}
|
|
117
245
|
return pool;
|
|
118
246
|
}
|
|
@@ -121,21 +249,26 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
121
249
|
* **************************************************************** */
|
|
122
250
|
}, {
|
|
123
251
|
key: "flatten",
|
|
124
|
-
value: function flatten(data) {
|
|
252
|
+
value: function flatten(data, level) {
|
|
125
253
|
var out = [];
|
|
126
|
-
var
|
|
127
|
-
|
|
254
|
+
var depth = level || 0;
|
|
255
|
+
var _iterator3 = _createForOfIteratorHelper(data),
|
|
256
|
+
_step3;
|
|
128
257
|
try {
|
|
129
|
-
for (
|
|
130
|
-
var d =
|
|
258
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
259
|
+
var d = _step3.value;
|
|
260
|
+
// 入れ子の深さ(ルート=0)。回転ビューの lift(階層ごとに手前へ
|
|
261
|
+
// 浮かせる)が参照する。描画順は親→子なので、浮いた子は常に
|
|
262
|
+
// 親の上に描かれる。
|
|
263
|
+
d._depth = depth;
|
|
131
264
|
out.push(d);
|
|
132
265
|
if (d.children.length === 0) continue;
|
|
133
|
-
out = out.concat(this.flatten(d.children));
|
|
266
|
+
out = out.concat(this.flatten(d.children, depth + 1));
|
|
134
267
|
}
|
|
135
268
|
} catch (err) {
|
|
136
|
-
|
|
269
|
+
_iterator3.e(err);
|
|
137
270
|
} finally {
|
|
138
|
-
|
|
271
|
+
_iterator3.f();
|
|
139
272
|
}
|
|
140
273
|
return out;
|
|
141
274
|
}
|
|
@@ -145,7 +278,7 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
145
278
|
var data = this.flatten(this._elements.list);
|
|
146
279
|
var place = this.layer('foreground');
|
|
147
280
|
if (!place) return;
|
|
148
|
-
this.element.draw(place, data);
|
|
281
|
+
this.element.draw(place, data, this.projector());
|
|
149
282
|
}
|
|
150
283
|
/* **************************************************************** *
|
|
151
284
|
* Data
|
|
@@ -9,8 +9,12 @@ var _assh0le = _interopRequireDefault(require("@yanqirenshi/assh0le"));
|
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
10
|
function D3Wireframe(props) {
|
|
11
11
|
var rectum = props.rectum;
|
|
12
|
+
|
|
13
|
+
// 同一ページに複数インスタンスを置く場合は id を指定して
|
|
14
|
+
// DOM id の衝突を避ける(既定 "d3-wireframe-graph")。
|
|
15
|
+
var id = props.id || 'd3-wireframe-graph';
|
|
12
16
|
return /*#__PURE__*/_react["default"].createElement(_assh0le["default"], {
|
|
13
|
-
id:
|
|
17
|
+
id: id,
|
|
14
18
|
rectum: rectum
|
|
15
19
|
});
|
|
16
20
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "Projector", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _Projector["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "Rectum", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function get() {
|
|
@@ -12,5 +18,6 @@ Object.defineProperty(exports, "Rectum", {
|
|
|
12
18
|
exports["default"] = void 0;
|
|
13
19
|
var _D3Wireframe = _interopRequireDefault(require("./components/D3Wireframe.js"));
|
|
14
20
|
var _Rectum = _interopRequireDefault(require("./Rectum.js"));
|
|
21
|
+
var _Projector = _interopRequireDefault(require("./Projector.js"));
|
|
15
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
16
23
|
var _default = exports["default"] = _D3Wireframe["default"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanqirenshi/d3.wireframe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Wireframe diagram renderer (frame / image / button / modal / dialog elements)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"src"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"transpile": "babel src -d dist --copy-files",
|
|
11
|
+
"transpile": "babel src -d dist --copy-files --delete-dir-on-start",
|
|
12
12
|
"prepublishOnly": "npm run transpile",
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"test:w": "jest --watch",
|
|
@@ -16,14 +16,15 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/Foolsgolds/Assholes.git",
|
|
20
|
+
"directory": "packages/d3.wireframe"
|
|
20
21
|
},
|
|
21
22
|
"author": "yanqirenshi <yanqirenshi@gmail.com> (https://github.com/yanqirenshi)",
|
|
22
|
-
"license": "
|
|
23
|
+
"license": "MIT",
|
|
23
24
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/
|
|
25
|
+
"url": "https://github.com/Foolsgolds/Assholes/issues"
|
|
25
26
|
},
|
|
26
|
-
"homepage": "https://
|
|
27
|
+
"homepage": "https://github.com/Foolsgolds/Assholes/tree/main/packages/d3.wireframe#readme",
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"react": "^18.0.0 || ^19.0.0",
|
|
29
30
|
"react-dom": "^18.0.0 || ^19.0.0"
|
package/src/DataBackground.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
class DataBackground {
|
|
2
|
-
template () {
|
|
3
|
-
return {
|
|
4
|
-
color: '#fff',
|
|
5
|
-
opacity: 1.0,
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
build (data) {
|
|
9
|
-
let out = this.template();
|
|
10
|
-
|
|
11
|
-
if (!data)
|
|
12
|
-
return out;
|
|
13
|
-
|
|
14
|
-
if (data.color) out.color = data.color;
|
|
15
|
-
if (data.opacity) out.opacity = data.opacity;
|
|
16
|
-
|
|
17
|
-
return out;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const BACKGROUND = new DataBackground();
|
|
22
|
-
|
|
23
|
-
export default BACKGROUND;
|
|
1
|
+
class DataBackground {
|
|
2
|
+
template () {
|
|
3
|
+
return {
|
|
4
|
+
color: '#fff',
|
|
5
|
+
opacity: 1.0,
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
build (data) {
|
|
9
|
+
let out = this.template();
|
|
10
|
+
|
|
11
|
+
if (!data)
|
|
12
|
+
return out;
|
|
13
|
+
|
|
14
|
+
if (data.color) out.color = data.color;
|
|
15
|
+
if (data.opacity) out.opacity = data.opacity;
|
|
16
|
+
|
|
17
|
+
return out;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const BACKGROUND = new DataBackground();
|
|
22
|
+
|
|
23
|
+
export default BACKGROUND;
|