@yanqirenshi/d3.wireframe 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports["default"] = void 0;
8
8
  var _ElementFounder2 = _interopRequireDefault(require("./ElementFounder"));
9
+ var _model = require("@yanqirenshi/model.wireframe");
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
11
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
12
  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); } }
@@ -24,15 +25,16 @@ var ElementLabel = exports["default"] = /*#__PURE__*/function (_ElementFounder)
24
25
  _classCallCheck(this, ElementLabel);
25
26
  return _callSuper(this, ElementLabel, ['label', params]);
26
27
  }
27
- /* **************************************************************** *
28
- * Data
28
+ /* **************************************************************** *
29
+ * Data
29
30
  * **************************************************************** */
30
31
  _inherits(ElementLabel, _ElementFounder);
31
32
  return _createClass(ElementLabel, [{
32
33
  key: "templateElement",
33
34
  value: function templateElement() {
34
35
  return this.makeTemplateElement({
35
- text: '????????',
36
+ text: _model.LABEL_DEFAULTS.text,
37
+ // model.wireframe(#195)
36
38
  position: null,
37
39
  font: null
38
40
  });
@@ -56,13 +58,13 @@ var ElementLabel = exports["default"] = /*#__PURE__*/function (_ElementFounder)
56
58
  return _this.makeElement(d);
57
59
  });
58
60
  }
59
- /* **************************************************************** *
60
- * Draw
61
+ /* **************************************************************** *
62
+ * Draw
61
63
  * **************************************************************** */
62
- /**
63
- * ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
64
- * ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
65
- * 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
64
+ /**
65
+ * ラベルを描く。回転ビュー(projector あり)では、親要素の絶対位置 +
66
+ * ラベル相対位置を射影した点に置き、フォントサイズは距離スケール(k)で
67
+ * 近似する(SVG の文字は遠近で歪ませられないため、位置と大きさのみ)。
66
68
  */
67
69
  }, {
68
70
  key: "draw",
package/dist/Rectum.js CHANGED
@@ -10,6 +10,10 @@ var _Element = _interopRequireDefault(require("./Element"));
10
10
  var _Projector = _interopRequireDefault(require("./Projector"));
11
11
  var _Drawer = require("./Drawer.js");
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
14
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
16
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
13
17
  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; } } }; }
14
18
  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; } }
15
19
  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; }
@@ -31,8 +35,33 @@ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !==
31
35
  function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
32
36
  function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
33
37
  function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
38
+ /** 要素のグループ(foreground レイヤの直下に、親 → 子の順で平らに並ぶ) */
39
+ var ELEMENT_GROUPS = 'g.frame, g.image, g.button, g.modal, g.dialog';
40
+
41
+ /**
42
+ * click / contextmenu を、コールバックへ知らせる(#195)。
43
+ * d3.sitemap / d3.deployment / d3.unchi / d3.dfd の notify と同じ作法。
44
+ *
45
+ * - コールバックがあるときだけ呼ばれる(呼ぶ側が、無ければ on() を付けない)。
46
+ * 渡していなければ何もしないので、ブラウザ標準のメニューが出て、イベントは外側へ届く
47
+ * - contextmenu: 左ボタンを押したまま(ドラッグ中)の右クリックは知らせない。
48
+ * それ以外は、ブラウザ標準のメニューを止め、外側へ伝えない。最後の引数に event を渡す
49
+ * - click: 外側へ伝えず、(core, element) で呼ぶ
50
+ */
51
+ var notify = function notify(callback, event, core, datum) {
52
+ if (event.type === 'contextmenu') {
53
+ if (event.buttons & 1) return;
54
+ event.preventDefault();
55
+ event.stopPropagation();
56
+ callback(core, datum, event);
57
+ return;
58
+ }
59
+ event.stopPropagation();
60
+ callback(core, datum);
61
+ };
62
+
34
63
  /**
35
- * データクラス。ワイヤーフレーム要素の構築・マージ・保持を行い、
64
+ * データクラス。ワイヤーフレーム要素の構築・保持を行い、
36
65
  * 描画は Element(各 Element クラス)へ委譲する。
37
66
  *
38
67
  * 旧 D3Wireframe(assh0le 0.0.3 の Asshole クラス継承)を
@@ -52,13 +81,38 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
52
81
  // 回転ビュー(任意)。{ y, x, perspective, origin } を渡すと
53
82
  // レイアウト平面を透視投影して描く(Projector 参照)。
54
83
  _this._rotation = params && params.rotation || null;
84
+
85
+ // コールバック(任意。0.3.0 から)。描画は行わず通知のみ
86
+ _this._callbacks = _this.initCallbacks(params);
87
+
88
+ // Ctrl + ドラッグで回転させた直後のクリックを、要素のクリックとして知らせないための印
89
+ _this._rotate_moved = false;
55
90
  return _this;
56
91
  }
57
- /* **************************************************************** *
58
- * Rotation (回転ビュー)
59
- * **************************************************************** */
92
+ /**
93
+ * コールバック(すべて任意。0.3.0 から)。
94
+ * element.click(core, element) … 要素のクリック
95
+ * element.contextmenu(core, element, event) … 要素の右クリック
96
+ * core は入力のレコードそのもの、element は描画用に作った要素(位置は親の位置を足した絶対位置)。
97
+ * 入れ子の要素は、いちばん内側(上に描かれている)の要素だけが知らせる。
98
+ */
60
99
  _inherits(Rectum, _Colon);
61
100
  return _createClass(Rectum, [{
101
+ key: "initCallbacks",
102
+ value: function initCallbacks(params) {
103
+ var callbacks = params && params.callbacks || {};
104
+ var element = callbacks.element || {};
105
+ return {
106
+ element: {
107
+ click: element.click || null,
108
+ contextmenu: element.contextmenu || null
109
+ }
110
+ };
111
+ }
112
+ /* **************************************************************** *
113
+ * Rotation (回転ビュー)
114
+ * **************************************************************** */
115
+ }, {
62
116
  key: "selector_setAfter",
63
117
  value: function selector_setAfter() {
64
118
  this.attachRotateDrag();
@@ -94,7 +148,9 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
94
148
  origin: base.origin || _this2.defaultOrigin(),
95
149
  lift: base.lift
96
150
  };
151
+ _this2._rotate_moved = false;
97
152
  var move = function move(e) {
153
+ _this2._rotate_moved = true;
98
154
  _this2.rotation(_objectSpread(_objectSpread({}, rest), {}, {
99
155
  y: _this2.clampAngle(start.y + (e.clientX - start.mx) * DEG_PER_PX),
100
156
  x: _this2.clampAngle(start.x + (e.clientY - start.my) * DEG_PER_PX)
@@ -103,6 +159,13 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
103
159
  var _up = function up() {
104
160
  window.removeEventListener('mousemove', move);
105
161
  window.removeEventListener('mouseup', _up);
162
+
163
+ // 離したあとに届く click は、回転の操作の一部なので要素のクリックとして知らせない。
164
+ // click は mouseup の直後に届くので、タイマーで印を消す
165
+ // (mousedown で消す形にしないのは、d3.zoom が Ctrl なしの mousedown の伝播を止めるため)
166
+ setTimeout(function () {
167
+ _this2._rotate_moved = false;
168
+ }, 0);
106
169
  };
107
170
  window.addEventListener('mousemove', move);
108
171
  window.addEventListener('mouseup', _up);
@@ -168,61 +231,42 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
168
231
  value: function rotation(v) {
169
232
  if (arguments.length === 0) return this._rotation;
170
233
  this._rotation = v;
171
- var place = this.layer('foreground');
172
- if (place) {
173
- place.selectAll('*').remove();
174
- this.draw();
175
- }
234
+
235
+ // draw() が描いてあるものを消してから描き直す(0.3.0 から)
236
+ if (this.layer('foreground')) this.draw();
176
237
  return this;
177
238
  }
178
239
  /* **************************************************************** *
179
240
  * Make Elements
180
241
  * **************************************************************** */
242
+ /**
243
+ * 根の要素を作る。data() のたびに、入力から作り直す(0.3.0 から。#195)。
244
+ *
245
+ * 0.2.1 までは、前の要素と突き合わせて(merge)いたが、入力の配列を並べ替えたうえで空にし、
246
+ * 同じ id(か id の無い)要素を 2 回目に渡すと TypeError で落ちていた。
247
+ *
248
+ * - 入力の配列は書き換えない(並べ替えは複製に対して行う)
249
+ * - 描く順番は、0.2.1 の 1 回目と同じ id の昇順(入力の順ではない)。比べ方も同じ
250
+ * - visible: false の根の要素は作らない(子は Element.makeElement が除く)
251
+ * - 自動の番号(id の無い要素・ラベル・アイコン)は、毎回 1 から振り直す
252
+ */
181
253
  }, {
182
- key: "firstObject",
183
- value: function firstObject(list) {
184
- if (list.length === 0) return null;
185
- return list[0];
186
- }
187
- }, {
188
- key: "merge",
189
- value: function merge(source, target) {
190
- var source_sorted = source.sort(function (a, b) {
254
+ key: "sortRoots",
255
+ value: function sortRoots(list) {
256
+ return _toConsumableArray(list || []).sort(function (a, b) {
191
257
  return a.id < b.id ? -1 : 1;
192
258
  });
193
- var target_sorted = target.sort(function (a, b) {
194
- return a._core.id < b._core.id ? -1 : 1;
195
- });
196
- var out = [];
197
- while (source_sorted.length > 0 || target_sorted.length > 0) {
198
- var src = this.firstObject(source_sorted);
199
- var trg = this.firstObject(target_sorted);
200
- if (trg === null) {
201
- // source にしか無いケース
202
- if (src.visible !== false) out.push(this.element.makeElement(src));
203
- source_sorted.shift();
204
- } else if (src === null) {
205
- // target にしか無いやつは削除する。
206
- target_sorted.shift();
207
- } else if (src.id === trg._core.id) {
208
- out.push(this.element.mergeCore(src, trg));
209
- source_sorted.shift();
210
- target_sorted.shift();
211
- } else if (src.id < trg._core.id) {
212
- // source にしか無いケース
213
- out.push(this.element.makeElement(src));
214
- source_sorted.shift();
215
- } else {
216
- // target にしか無いやつは削除する。
217
- target_sorted.shift();
218
- }
219
- }
220
- return out;
221
259
  }
222
260
  }, {
223
261
  key: "makeElements",
224
262
  value: function makeElements(list) {
225
- var new_list = this.merge(list, this._elements.list);
263
+ var _this3 = this;
264
+ this.element = new _Element["default"]();
265
+ var new_list = this.sortRoots(list).filter(function (src) {
266
+ return src.visible !== false;
267
+ }).map(function (src) {
268
+ return _this3.element.makeElement(src);
269
+ });
226
270
  var pool = {
227
271
  ht: {},
228
272
  list: []
@@ -272,13 +316,43 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
272
316
  }
273
317
  return out;
274
318
  }
319
+ /**
320
+ * 描く。描いてあるものを消してから、要素を描き直す(0.3.0 から。#195)。
321
+ * 各要素の描画は enter だけで、消す・更新する処理を持たないので、
322
+ * data() で要素を作り直しても、描いてあるものを消さないと図が変わらない(rotation() と同じやり方)。
323
+ */
275
324
  }, {
276
325
  key: "draw",
277
326
  value: function draw() {
278
327
  var data = this.flatten(this._elements.list);
279
328
  var place = this.layer('foreground');
280
329
  if (!place) return;
330
+ place.selectAll('*').remove();
281
331
  this.element.draw(place, data, this.projector());
332
+ this.attachElementEvents(place);
333
+ }
334
+ /**
335
+ * 要素のクリック・右クリックを知らせる(callbacks.element。0.3.0 から)。受けるのは要素のグループ(g.frame など)で、
336
+ * ラベルとアイコンは、その中にある。入れ子の要素は DOM では入れ子にならず、子が親より後(上)に描かれるので、
337
+ * いちばん内側の要素が受ける。コールバックがあるときだけ、カーソルを pointer にする。
338
+ * Ctrl + ドラッグで回転させた直後のクリックは知らせない。
339
+ */
340
+ }, {
341
+ key: "attachElementEvents",
342
+ value: function attachElementEvents(place) {
343
+ var _this4 = this;
344
+ var _this$_callbacks$elem = this._callbacks.element,
345
+ click = _this$_callbacks$elem.click,
346
+ contextmenu = _this$_callbacks$elem.contextmenu;
347
+ if (!click && !contextmenu) return;
348
+ var groups = place.selectAll(ELEMENT_GROUPS).style('cursor', 'pointer');
349
+ if (click) groups.on('click', function (event, d) {
350
+ if (_this4._rotate_moved) return;
351
+ notify(click, event, d._core, d);
352
+ });
353
+ if (contextmenu) groups.on('contextmenu', function (event, d) {
354
+ return notify(contextmenu, event, d._core, d);
355
+ });
282
356
  }
283
357
  /* **************************************************************** *
284
358
  * Data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.wireframe",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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,20 +16,22 @@
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "git+https://github.com/yanqirenshi/D3.Wireframe.git"
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": "ISC",
23
+ "license": "MIT",
23
24
  "bugs": {
24
- "url": "https://github.com/yanqirenshi/D3.Wireframe/issues"
25
+ "url": "https://github.com/Foolsgolds/Assholes/issues"
25
26
  },
26
- "homepage": "https://yanqirenshi.github.io/D3.Wireframe/#home",
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"
30
31
  },
31
32
  "dependencies": {
32
- "@yanqirenshi/assh0le": "^0.5.2"
33
+ "@yanqirenshi/assh0le": "^0.5.2",
34
+ "@yanqirenshi/model.wireframe": "^0.1.0"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@babel/cli": "^7.8.4",
@@ -1,23 +1,15 @@
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
+ import { BACKGROUND_DEFAULTS, backgroundOf } from '@yanqirenshi/model.wireframe';
2
+
3
+ // 背景(color / opacity)。既定値と判定は model.wireframe が持つ(#195)
4
+ class DataBackground {
5
+ template () {
6
+ return { ...BACKGROUND_DEFAULTS };
7
+ }
8
+ build (data) {
9
+ return backgroundOf(data);
10
+ };
11
+ }
12
+
13
+ const BACKGROUND = new DataBackground();
14
+
15
+ export default BACKGROUND;
package/src/DataFont.js CHANGED
@@ -1,25 +1,15 @@
1
- class DataFont {
2
- template () {
3
- return {
4
- size: 16,
5
- color: '#fff',
6
- weight: 'normal',
7
- };
8
- }
9
- build (data) {
10
- let out = this.template();
11
-
12
- if (!data)
13
- return out;
14
-
15
- if (data.size) out.size = data.size;
16
- if (data.color) out.color = data.color;
17
- if (data.weight) out.weight = data.weight;
18
-
19
- return out;
20
- };
21
- }
22
-
23
- const FONT = new DataFont();
24
-
25
- export default FONT;
1
+ import { FONT_DEFAULTS, fontOf } from '@yanqirenshi/model.wireframe';
2
+
3
+ // 文字(size / color / weight)。既定値と判定は model.wireframe が持つ(#195)
4
+ class DataFont {
5
+ template () {
6
+ return { ...FONT_DEFAULTS };
7
+ }
8
+ build (data) {
9
+ return fontOf(data);
10
+ };
11
+ }
12
+
13
+ const FONT = new DataFont();
14
+
15
+ export default FONT;
@@ -1,21 +1,15 @@
1
- class DataPosition {
2
- template () {
3
- return { x:0, y:0, z:0 };
4
- }
5
- build (data) {
6
- let out = this.template();
7
-
8
- if (!data)
9
- return out;
10
-
11
- if (data.x) out.x = data.x;
12
- if (data.y) out.y = data.y;
13
- if (data.z) out.z = data.z;
14
-
15
- return out;
16
- };
17
- }
18
-
19
- const POSITION = new DataPosition();
20
-
21
- export default POSITION;
1
+ import { POSITION_DEFAULTS, positionOf } from '@yanqirenshi/model.wireframe';
2
+
3
+ // 位置(x / y / z)。既定値と判定は model.wireframe が持つ(#195)
4
+ class DataPosition {
5
+ template () {
6
+ return { ...POSITION_DEFAULTS };
7
+ }
8
+ build (data) {
9
+ return positionOf(data);
10
+ };
11
+ }
12
+
13
+ const POSITION = new DataPosition();
14
+
15
+ export default POSITION;
@@ -1,20 +1,15 @@
1
- class DataRectangle {
2
- template () {
3
- return { w: 0, h: 0 };
4
- }
5
- build (data) {
6
- let out = this.template();
7
-
8
- if (!data)
9
- return out;
10
-
11
- if (data.w) out.w = data.w;
12
- if (data.h) out.h = data.h;
13
-
14
- return out;
15
- };
16
- }
17
-
18
- const RECTANGLE = new DataRectangle();
19
-
20
- export default RECTANGLE;
1
+ import { RECTANGLE_DEFAULTS, rectangleOf } from '@yanqirenshi/model.wireframe';
2
+
3
+ // 大きさ(w / h)。既定値と判定は model.wireframe が持つ(#195)
4
+ class DataRectangle {
5
+ template () {
6
+ return { ...RECTANGLE_DEFAULTS };
7
+ }
8
+ build (data) {
9
+ return rectangleOf(data);
10
+ };
11
+ }
12
+
13
+ const RECTANGLE = new DataRectangle();
14
+
15
+ export default RECTANGLE;
package/src/DataStroke.js CHANGED
@@ -1,23 +1,15 @@
1
- class DataStroke {
2
- template () {
3
- return {
4
- color: '#afafb0',
5
- width: 1,
6
- };
7
- }
8
- build (data) {
9
- let out = this.template();
10
-
11
- if (!data)
12
- return null;
13
-
14
- if (data.color) out.color = data.color;
15
- if (data.width) out.width = data.width;
16
-
17
- return out;
18
- };
19
- }
20
-
21
- const STROKE = new DataStroke();
22
-
23
- export default STROKE;
1
+ import { STROKE_DEFAULTS, strokeOf } from '@yanqirenshi/model.wireframe';
2
+
3
+ // 線(color / width)。書いていなければ null(線なし)。既定値と判定は model.wireframe が持つ(#195)
4
+ class DataStroke {
5
+ template () {
6
+ return { ...STROKE_DEFAULTS };
7
+ }
8
+ build (data) {
9
+ return strokeOf(data);
10
+ };
11
+ }
12
+
13
+ const STROKE = new DataStroke();
14
+
15
+ export default STROKE;
package/src/Element.js CHANGED
@@ -1,67 +1,62 @@
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
- }
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
+ /* **************************************************************** *
53
+ * Draw
54
+ * **************************************************************** */
55
+ draw (place, list, projector) {
56
+ for (let data of list) {
57
+ const ec = this.elementClass(data);
58
+
59
+ ec.draw(place, data, projector);
60
+ }
61
+ }
62
+ }