@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/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,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanqirenshi/d3.wireframe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Wireframe diagram renderer (frame / image / button / modal / dialog elements)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
11
|
"transpile": "babel src -d dist --copy-files",
|
|
8
12
|
"prepublishOnly": "npm run transpile",
|
|
@@ -21,8 +25,8 @@
|
|
|
21
25
|
},
|
|
22
26
|
"homepage": "https://yanqirenshi.github.io/D3.Wireframe/#home",
|
|
23
27
|
"peerDependencies": {
|
|
24
|
-
"react": "^18.
|
|
25
|
-
"react-dom": "^18.
|
|
28
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
29
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"@yanqirenshi/assh0le": "^0.5.2"
|
package/src/Element.js
CHANGED
|
@@ -57,11 +57,11 @@ export default class Element {
|
|
|
57
57
|
/* **************************************************************** *
|
|
58
58
|
* Draw
|
|
59
59
|
* **************************************************************** */
|
|
60
|
-
draw (place, list) {
|
|
60
|
+
draw (place, list, projector) {
|
|
61
61
|
for (let data of list) {
|
|
62
62
|
const ec = this.elementClass(data);
|
|
63
63
|
|
|
64
|
-
ec.draw(place, data);
|
|
64
|
+
ec.draw(place, data, projector);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/ElementButton.js
CHANGED
|
@@ -53,28 +53,18 @@ export default class ElementButton extends ElementFounder {
|
|
|
53
53
|
/* **************************************************************** *
|
|
54
54
|
* Draw
|
|
55
55
|
* **************************************************************** */
|
|
56
|
-
drawAdd (place, data) {
|
|
56
|
+
drawAdd (place, data, projector) {
|
|
57
57
|
const g = place.selectAll(`g.${this.name}`)
|
|
58
58
|
.data([data], (d) => { return d._id; })
|
|
59
59
|
.enter()
|
|
60
60
|
.append('g')
|
|
61
61
|
.attr('class', this.name)
|
|
62
|
-
.attr("transform", d =>
|
|
63
|
-
return `translate(${d.position.x}, ${d.position.y})`;
|
|
64
|
-
});
|
|
62
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
.attr('class', 'base')
|
|
68
|
-
.attr('width', d => d.rectangle.w)
|
|
69
|
-
.attr('height', d => d.rectangle.h)
|
|
70
|
-
.attr('rx', d => d.round || 0)
|
|
71
|
-
.attr('ry', d => d.round || 0)
|
|
72
|
-
.attr('fill', d => d.background.color)
|
|
73
|
-
.attr('stroke', d => this.stroke(d))
|
|
74
|
-
.attr('stroke-width', d => this.strokeWidth(d));
|
|
64
|
+
this.drawBase(g, projector);
|
|
75
65
|
|
|
76
|
-
this.icon.draw(g, data);
|
|
77
|
-
this.label.draw(g, data);
|
|
66
|
+
this.icon.draw(g, data, projector);
|
|
67
|
+
this.label.draw(g, data, projector);
|
|
78
68
|
}
|
|
79
69
|
drawUpdate (place, data) {
|
|
80
70
|
place.selectAll(`g.${this.name}`)
|
|
@@ -86,9 +76,9 @@ export default class ElementButton extends ElementFounder {
|
|
|
86
76
|
.exit()
|
|
87
77
|
.remove();
|
|
88
78
|
}
|
|
89
|
-
draw (place, data) {
|
|
79
|
+
draw (place, data, projector) {
|
|
90
80
|
// this.drawDelete(place, data);
|
|
91
81
|
this.drawUpdate(place, data);
|
|
92
|
-
this.drawAdd(place, data);
|
|
82
|
+
this.drawAdd(place, data, projector);
|
|
93
83
|
}
|
|
94
84
|
}
|
package/src/ElementDialog.js
CHANGED
|
@@ -37,27 +37,17 @@ export default class ElementDialog extends ElementFounder {
|
|
|
37
37
|
/* **************************************************************** *
|
|
38
38
|
* Draw
|
|
39
39
|
* **************************************************************** */
|
|
40
|
-
drawAdd (place, data) {
|
|
40
|
+
drawAdd (place, data, projector) {
|
|
41
41
|
const g = place.selectAll(`g.${this.name}`)
|
|
42
42
|
.data([data], (d) => { return d._id; })
|
|
43
43
|
.enter()
|
|
44
44
|
.append('g')
|
|
45
45
|
.attr('class', this.name)
|
|
46
|
-
.attr("transform", d =>
|
|
47
|
-
return `translate(${d.position.x}, ${d.position.y})`;
|
|
48
|
-
});
|
|
46
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
.attr('class', 'base')
|
|
52
|
-
.attr('width', d => d.rectangle.w)
|
|
53
|
-
.attr('height', d => d.rectangle.h)
|
|
54
|
-
.attr('rx', d => d.round || 0)
|
|
55
|
-
.attr('ry', d => d.round || 0)
|
|
56
|
-
.attr('fill', d => d.background.color)
|
|
57
|
-
.attr('stroke', d => this.stroke(d))
|
|
58
|
-
.attr('stroke-width', d => this.strokeWidth(d));
|
|
48
|
+
this.drawBase(g, projector);
|
|
59
49
|
|
|
60
|
-
this.label.draw(g, data);
|
|
50
|
+
this.label.draw(g, data, projector);
|
|
61
51
|
}
|
|
62
52
|
drawUpdate (place, data) {
|
|
63
53
|
place.selectAll(`g.${this.name}`)
|
|
@@ -69,9 +59,9 @@ export default class ElementDialog extends ElementFounder {
|
|
|
69
59
|
.exit()
|
|
70
60
|
.remove();
|
|
71
61
|
}
|
|
72
|
-
draw (place, data) {
|
|
62
|
+
draw (place, data, projector) {
|
|
73
63
|
// this.drawDelete(place, data);
|
|
74
64
|
this.drawUpdate(place, data);
|
|
75
|
-
this.drawAdd(place, data);
|
|
65
|
+
this.drawAdd(place, data, projector);
|
|
76
66
|
}
|
|
77
67
|
}
|
package/src/ElementFounder.js
CHANGED
|
@@ -64,6 +64,45 @@ export default class ElementFounder {
|
|
|
64
64
|
/* **************************************************************** *
|
|
65
65
|
* Draw
|
|
66
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
|
+
}
|
|
67
106
|
stroke (d) {
|
|
68
107
|
if (!d.stroke)
|
|
69
108
|
return null;
|
package/src/ElementFrame.js
CHANGED
|
@@ -37,27 +37,17 @@ export default class ElementFrame extends ElementFounder {
|
|
|
37
37
|
/* **************************************************************** *
|
|
38
38
|
* Draw
|
|
39
39
|
* **************************************************************** */
|
|
40
|
-
drawAdd (place, data) {
|
|
40
|
+
drawAdd (place, data, projector) {
|
|
41
41
|
const g = place.selectAll(`g.${this.name}`)
|
|
42
42
|
.data([data], (d) => { return d._id; })
|
|
43
43
|
.enter()
|
|
44
44
|
.append('g')
|
|
45
45
|
.attr('class', this.name)
|
|
46
|
-
.attr("transform", d =>
|
|
47
|
-
return `translate(${d.position.x}, ${d.position.y})`;
|
|
48
|
-
});
|
|
46
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
.attr('class', 'base')
|
|
52
|
-
.attr('width', d => d.rectangle.w)
|
|
53
|
-
.attr('height', d => d.rectangle.h)
|
|
54
|
-
.attr('rx', d => d.round || 0)
|
|
55
|
-
.attr('ry', d => d.round || 0)
|
|
56
|
-
.attr('fill', d => d.background.color)
|
|
57
|
-
.attr('stroke', d => this.stroke(d))
|
|
58
|
-
.attr('stroke-width', d => this.strokeWidth(d));
|
|
48
|
+
this.drawBase(g, projector);
|
|
59
49
|
|
|
60
|
-
this.label.draw(g, data);
|
|
50
|
+
this.label.draw(g, data, projector);
|
|
61
51
|
}
|
|
62
52
|
drawUpdate (place, data) {
|
|
63
53
|
place.selectAll(`g.${this.name}`)
|
|
@@ -69,9 +59,9 @@ export default class ElementFrame extends ElementFounder {
|
|
|
69
59
|
.exit()
|
|
70
60
|
.remove();
|
|
71
61
|
}
|
|
72
|
-
draw (place, data) {
|
|
62
|
+
draw (place, data, projector) {
|
|
73
63
|
// this.drawDelete(place, data);
|
|
74
64
|
this.drawUpdate(place, data);
|
|
75
|
-
this.drawAdd(place, data);
|
|
65
|
+
this.drawAdd(place, data, projector);
|
|
76
66
|
}
|
|
77
67
|
}
|
package/src/ElementIcon.js
CHANGED
|
@@ -42,14 +42,30 @@ export default class ElementIcon extends ElementFounder {
|
|
|
42
42
|
/* **************************************************************** *
|
|
43
43
|
* Draw
|
|
44
44
|
* **************************************************************** */
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* アイコン(画像)を描く。SVG の <image> は polygon 化できないため、
|
|
47
|
+
* 回転ビュー(projector あり)では要素の3隅を正確に写す近似 affine
|
|
48
|
+
* 行列で変形する(アイコンは小さいので誤差は実用上見えない)。
|
|
49
|
+
*/
|
|
50
|
+
draw (place, data, projector) {
|
|
46
51
|
place.selectAll('image')
|
|
47
52
|
.data(data.icons || [], d => d._id)
|
|
48
53
|
.enter()
|
|
49
54
|
.append('image')
|
|
50
55
|
.attr('xlink:href', d => d.url)
|
|
51
|
-
.attr('
|
|
52
|
-
|
|
56
|
+
.attr('transform', d => {
|
|
57
|
+
if (!projector)
|
|
58
|
+
return null;
|
|
59
|
+
|
|
60
|
+
const x = data.position.x + ((d.position && d.position.x) || 0);
|
|
61
|
+
const y = data.position.y + ((d.position && d.position.y) || 0);
|
|
62
|
+
const w = (d.size && d.size.w) || d.rectangle.w;
|
|
63
|
+
const h = (d.size && d.size.h) || d.rectangle.h;
|
|
64
|
+
|
|
65
|
+
return projector.affine(x, y, w, h, projector.depthZ(data._depth));
|
|
66
|
+
})
|
|
67
|
+
.attr('x', d => projector ? 0 : ((d.position && d.position.x) || 0))
|
|
68
|
+
.attr('y', d => projector ? 0 : ((d.position && d.position.y) || 0))
|
|
53
69
|
.attr('width', d => (d.size && d.size.w) || d.rectangle.w)
|
|
54
70
|
.attr('height', d => (d.size && d.size.h) || d.rectangle.h);
|
|
55
71
|
}
|
package/src/ElementImage.js
CHANGED
|
@@ -37,27 +37,17 @@ export default class ElementImage extends ElementFounder {
|
|
|
37
37
|
/* **************************************************************** *
|
|
38
38
|
* Draw
|
|
39
39
|
* **************************************************************** */
|
|
40
|
-
drawAdd (place, data) {
|
|
40
|
+
drawAdd (place, data, projector) {
|
|
41
41
|
const g = place.selectAll(`g.${this.name}`)
|
|
42
42
|
.data([data], (d) => { return d._id; })
|
|
43
43
|
.enter()
|
|
44
44
|
.append('g')
|
|
45
45
|
.attr('class', this.name)
|
|
46
|
-
.attr("transform", d =>
|
|
47
|
-
return `translate(${d.position.x}, ${d.position.y})`;
|
|
48
|
-
});
|
|
46
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
.attr('class', 'base')
|
|
52
|
-
.attr('width', d => d.rectangle.w)
|
|
53
|
-
.attr('height', d => d.rectangle.h)
|
|
54
|
-
.attr('rx', d => d.round || 0)
|
|
55
|
-
.attr('ry', d => d.round || 0)
|
|
56
|
-
.attr('fill', d => d.background.color)
|
|
57
|
-
.attr('stroke', d => this.stroke(d))
|
|
58
|
-
.attr('stroke-width', d => this.strokeWidth(d));
|
|
48
|
+
this.drawBase(g, projector);
|
|
59
49
|
|
|
60
|
-
this.label.draw(g, data);
|
|
50
|
+
this.label.draw(g, data, projector);
|
|
61
51
|
}
|
|
62
52
|
drawUpdate (place, data) {
|
|
63
53
|
place.selectAll(`g.${this.name}`)
|
|
@@ -69,9 +59,9 @@ export default class ElementImage extends ElementFounder {
|
|
|
69
59
|
.exit()
|
|
70
60
|
.remove();
|
|
71
61
|
}
|
|
72
|
-
draw (place, data) {
|
|
62
|
+
draw (place, data, projector) {
|
|
73
63
|
// this.drawDelete(place, data);
|
|
74
64
|
this.drawUpdate(place, data);
|
|
75
|
-
this.drawAdd(place, data);
|
|
65
|
+
this.drawAdd(place, data, projector);
|
|
76
66
|
}
|
|
77
67
|
}
|
package/src/ElementLabel.js
CHANGED
|
@@ -36,14 +36,29 @@ export default class ElementLabel extends ElementFounder {
|
|
|
36
36
|
/* **************************************************************** *
|
|
37
37
|
* Draw
|
|
38
38
|
* **************************************************************** */
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
|
|
41
|
+
* ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
|
|
42
|
+
* 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
|
|
43
|
+
*/
|
|
44
|
+
draw (place, data, projector) {
|
|
45
|
+
const project = (d) => projector.point(
|
|
46
|
+
data.position.x + d.position.x,
|
|
47
|
+
data.position.y + d.position.y,
|
|
48
|
+
projector.depthZ(data._depth));
|
|
49
|
+
|
|
40
50
|
place.selectAll('label')
|
|
41
51
|
.data(data.labels, d => d._id)
|
|
42
52
|
.enter()
|
|
43
53
|
.append("text")
|
|
44
|
-
.attr("x", d => d.position.x)
|
|
45
|
-
.attr("y", d => d.position.y)
|
|
46
|
-
.style("font-size", d =>
|
|
54
|
+
.attr("x", d => projector ? project(d).x : d.position.x)
|
|
55
|
+
.attr("y", d => projector ? project(d).y : d.position.y)
|
|
56
|
+
.style("font-size", d => {
|
|
57
|
+
if (!projector)
|
|
58
|
+
return `${d.font.size}px`;
|
|
59
|
+
|
|
60
|
+
return `${d.font.size * project(d).k}px`;
|
|
61
|
+
})
|
|
47
62
|
.style("fill", d => d.font.color)
|
|
48
63
|
.style("font-weight", d => d.font.weight)
|
|
49
64
|
.text(d => d.text);
|
package/src/ElementModal.js
CHANGED
|
@@ -28,23 +28,19 @@ export default class ElementModal extends ElementFounder {
|
|
|
28
28
|
/* **************************************************************** *
|
|
29
29
|
* Draw
|
|
30
30
|
* **************************************************************** */
|
|
31
|
-
drawAdd (place, data) {
|
|
31
|
+
drawAdd (place, data, projector) {
|
|
32
32
|
const g = place.selectAll(`g.${this.name}`)
|
|
33
33
|
.data([data], (d) => { return d._id; })
|
|
34
34
|
.enter()
|
|
35
35
|
.append('g')
|
|
36
36
|
.attr('class', this.name)
|
|
37
|
-
.attr("transform", d =>
|
|
38
|
-
return `translate(${d.position.x}, ${d.position.y})`;
|
|
39
|
-
});
|
|
37
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.attr('
|
|
45
|
-
.attr('
|
|
46
|
-
.attr('ry', 0)
|
|
47
|
-
.attr('fill', d => d.background.color)
|
|
39
|
+
// modal は stroke 無し + 半透明の面。共通の drawBase(rect/polygon の
|
|
40
|
+
// 切替)を使い、追加の属性だけここで上書きする。
|
|
41
|
+
this.drawBase(g, projector)
|
|
42
|
+
.attr('stroke', null)
|
|
43
|
+
.attr('stroke-width', null)
|
|
48
44
|
.attr('fill-opacity', d => d.background.opacity);
|
|
49
45
|
}
|
|
50
46
|
drawUpdate (place, data) {
|
|
@@ -57,9 +53,9 @@ export default class ElementModal extends ElementFounder {
|
|
|
57
53
|
.exit()
|
|
58
54
|
.remove();
|
|
59
55
|
}
|
|
60
|
-
draw (place, data) {
|
|
56
|
+
draw (place, data, projector) {
|
|
61
57
|
// this.drawDelete(place, data);
|
|
62
58
|
this.drawUpdate(place, data);
|
|
63
|
-
this.drawAdd(place, data);
|
|
59
|
+
this.drawAdd(place, data, projector);
|
|
64
60
|
}
|
|
65
61
|
}
|