@yanqirenshi/d3.wireframe 0.2.1 → 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.
- package/README.markdown +102 -44
- package/dist/DataBackground.js +7 -9
- package/dist/DataFont.js +7 -11
- package/dist/DataPosition.js +7 -11
- package/dist/DataRectangle.js +7 -9
- package/dist/DataStroke.js +7 -9
- package/dist/Digestion.js +20 -20
- package/dist/Drawer.js +20 -20
- package/dist/Element.js +0 -6
- package/dist/ElementButton.js +11 -14
- package/dist/ElementDialog.js +4 -4
- package/dist/ElementFounder.js +11 -7
- package/dist/ElementFrame.js +4 -4
- package/dist/ElementIcon.js +8 -8
- package/dist/ElementImage.js +4 -4
- package/dist/ElementLabel.js +3 -1
- package/dist/ElementModal.js +4 -4
- package/dist/Rectum.js +121 -47
- package/package.json +3 -2
- package/src/DataBackground.js +5 -13
- package/src/DataFont.js +5 -15
- package/src/DataPosition.js +5 -11
- package/src/DataRectangle.js +5 -10
- package/src/DataStroke.js +5 -13
- package/src/Digestion.js +273 -273
- package/src/Drawer.js +270 -270
- package/src/Element.js +0 -5
- package/src/ElementButton.js +6 -13
- package/src/ElementDialog.js +67 -67
- package/src/ElementFounder.js +12 -6
- package/src/ElementFrame.js +67 -67
- package/src/ElementIcon.js +72 -72
- package/src/ElementImage.js +67 -67
- package/src/ElementLabel.js +3 -1
- package/src/ElementModal.js +61 -61
- package/src/Rectum.js +115 -44
package/src/ElementModal.js
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import ElementFounder from './ElementFounder';
|
|
2
|
-
|
|
3
|
-
export default class ElementModal extends ElementFounder {
|
|
4
|
-
constructor (params) {
|
|
5
|
-
super('modal', params);
|
|
6
|
-
}
|
|
7
|
-
/* **************************************************************** *
|
|
8
|
-
* Data
|
|
9
|
-
* **************************************************************** */
|
|
10
|
-
templateElement () {
|
|
11
|
-
return this.makeTemplateElement({
|
|
12
|
-
position: null,
|
|
13
|
-
rectangle: null,
|
|
14
|
-
children: [],
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
makeElement (core, parent) {
|
|
18
|
-
let element = this.templateElement();
|
|
19
|
-
|
|
20
|
-
this.initElement(element, core, parent);
|
|
21
|
-
|
|
22
|
-
this.fittingRectangle(element, core);
|
|
23
|
-
this.fittingPosition(element, core);
|
|
24
|
-
this.fittingBackground(element, core);
|
|
25
|
-
|
|
26
|
-
return element;
|
|
27
|
-
}
|
|
28
|
-
/* **************************************************************** *
|
|
29
|
-
* Draw
|
|
30
|
-
* **************************************************************** */
|
|
31
|
-
drawAdd (place, data, projector) {
|
|
32
|
-
const g = place.selectAll(`g.${this.name}`)
|
|
33
|
-
.data([data], (d) => { return d._id; })
|
|
34
|
-
.enter()
|
|
35
|
-
.append('g')
|
|
36
|
-
.attr('class', this.name)
|
|
37
|
-
.attr("transform", d => this.groupTransform(d, projector));
|
|
38
|
-
|
|
39
|
-
// modal は stroke 無し + 半透明の面。共通の drawBase(rect/polygon の
|
|
40
|
-
// 切替)を使い、追加の属性だけここで上書きする。
|
|
41
|
-
this.drawBase(g, projector)
|
|
42
|
-
.attr('stroke', null)
|
|
43
|
-
.attr('stroke-width', null)
|
|
44
|
-
.attr('fill-opacity', d => d.background.opacity);
|
|
45
|
-
}
|
|
46
|
-
drawUpdate (place, data) {
|
|
47
|
-
place.selectAll(`g.${this.name}`)
|
|
48
|
-
.data([data], (d) => { return d._id; });
|
|
49
|
-
}
|
|
50
|
-
drawDelete (place, data) {
|
|
51
|
-
place.selectAll(`g.${this.name}`)
|
|
52
|
-
.data([data], (d) => { return d._id; })
|
|
53
|
-
.exit()
|
|
54
|
-
.remove();
|
|
55
|
-
}
|
|
56
|
-
draw (place, data, projector) {
|
|
57
|
-
// this.drawDelete(place, data);
|
|
58
|
-
this.drawUpdate(place, data);
|
|
59
|
-
this.drawAdd(place, data, projector);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
import ElementFounder from './ElementFounder';
|
|
2
|
+
|
|
3
|
+
export default class ElementModal extends ElementFounder {
|
|
4
|
+
constructor (params) {
|
|
5
|
+
super('modal', params);
|
|
6
|
+
}
|
|
7
|
+
/* **************************************************************** *
|
|
8
|
+
* Data
|
|
9
|
+
* **************************************************************** */
|
|
10
|
+
templateElement () {
|
|
11
|
+
return this.makeTemplateElement({
|
|
12
|
+
position: null,
|
|
13
|
+
rectangle: null,
|
|
14
|
+
children: [],
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
makeElement (core, parent) {
|
|
18
|
+
let element = this.templateElement();
|
|
19
|
+
|
|
20
|
+
this.initElement(element, core, parent);
|
|
21
|
+
|
|
22
|
+
this.fittingRectangle(element, core);
|
|
23
|
+
this.fittingPosition(element, core);
|
|
24
|
+
this.fittingBackground(element, core);
|
|
25
|
+
|
|
26
|
+
return element;
|
|
27
|
+
}
|
|
28
|
+
/* **************************************************************** *
|
|
29
|
+
* Draw
|
|
30
|
+
* **************************************************************** */
|
|
31
|
+
drawAdd (place, data, projector) {
|
|
32
|
+
const g = place.selectAll(`g.${this.name}`)
|
|
33
|
+
.data([data], (d) => { return d._id; })
|
|
34
|
+
.enter()
|
|
35
|
+
.append('g')
|
|
36
|
+
.attr('class', this.name)
|
|
37
|
+
.attr("transform", d => this.groupTransform(d, projector));
|
|
38
|
+
|
|
39
|
+
// modal は stroke 無し + 半透明の面。共通の drawBase(rect/polygon の
|
|
40
|
+
// 切替)を使い、追加の属性だけここで上書きする。
|
|
41
|
+
this.drawBase(g, projector)
|
|
42
|
+
.attr('stroke', null)
|
|
43
|
+
.attr('stroke-width', null)
|
|
44
|
+
.attr('fill-opacity', d => d.background.opacity);
|
|
45
|
+
}
|
|
46
|
+
drawUpdate (place, data) {
|
|
47
|
+
place.selectAll(`g.${this.name}`)
|
|
48
|
+
.data([data], (d) => { return d._id; });
|
|
49
|
+
}
|
|
50
|
+
drawDelete (place, data) {
|
|
51
|
+
place.selectAll(`g.${this.name}`)
|
|
52
|
+
.data([data], (d) => { return d._id; })
|
|
53
|
+
.exit()
|
|
54
|
+
.remove();
|
|
55
|
+
}
|
|
56
|
+
draw (place, data, projector) {
|
|
57
|
+
// this.drawDelete(place, data);
|
|
58
|
+
this.drawUpdate(place, data);
|
|
59
|
+
this.drawAdd(place, data, projector);
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/Rectum.js
CHANGED
|
@@ -5,8 +5,36 @@ import Projector from './Projector';
|
|
|
5
5
|
|
|
6
6
|
import { DrawerHierarchy } from './Drawer.js';
|
|
7
7
|
|
|
8
|
+
/** 要素のグループ(foreground レイヤの直下に、親 → 子の順で平らに並ぶ) */
|
|
9
|
+
const ELEMENT_GROUPS = 'g.frame, g.image, g.button, g.modal, g.dialog';
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* click / contextmenu を、コールバックへ知らせる(#195)。
|
|
13
|
+
* d3.sitemap / d3.deployment / d3.unchi / d3.dfd の notify と同じ作法。
|
|
14
|
+
*
|
|
15
|
+
* - コールバックがあるときだけ呼ばれる(呼ぶ側が、無ければ on() を付けない)。
|
|
16
|
+
* 渡していなければ何もしないので、ブラウザ標準のメニューが出て、イベントは外側へ届く
|
|
17
|
+
* - contextmenu: 左ボタンを押したまま(ドラッグ中)の右クリックは知らせない。
|
|
18
|
+
* それ以外は、ブラウザ標準のメニューを止め、外側へ伝えない。最後の引数に event を渡す
|
|
19
|
+
* - click: 外側へ伝えず、(core, element) で呼ぶ
|
|
20
|
+
*/
|
|
21
|
+
const notify = (callback, event, core, datum) => {
|
|
22
|
+
if (event.type === 'contextmenu') {
|
|
23
|
+
if (event.buttons & 1)
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
event.stopPropagation();
|
|
28
|
+
callback(core, datum, event);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
event.stopPropagation();
|
|
33
|
+
callback(core, datum);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* データクラス。ワイヤーフレーム要素の構築・保持を行い、
|
|
10
38
|
* 描画は Element(各 Element クラス)へ委譲する。
|
|
11
39
|
*
|
|
12
40
|
* 旧 D3Wireframe(assh0le 0.0.3 の Asshole クラス継承)を
|
|
@@ -22,6 +50,30 @@ export default class Rectum extends Colon {
|
|
|
22
50
|
// 回転ビュー(任意)。{ y, x, perspective, origin } を渡すと
|
|
23
51
|
// レイアウト平面を透視投影して描く(Projector 参照)。
|
|
24
52
|
this._rotation = (params && params.rotation) || null;
|
|
53
|
+
|
|
54
|
+
// コールバック(任意。0.3.0 から)。描画は行わず通知のみ
|
|
55
|
+
this._callbacks = this.initCallbacks(params);
|
|
56
|
+
|
|
57
|
+
// Ctrl + ドラッグで回転させた直後のクリックを、要素のクリックとして知らせないための印
|
|
58
|
+
this._rotate_moved = false;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* コールバック(すべて任意。0.3.0 から)。
|
|
62
|
+
* element.click(core, element) … 要素のクリック
|
|
63
|
+
* element.contextmenu(core, element, event) … 要素の右クリック
|
|
64
|
+
* core は入力のレコードそのもの、element は描画用に作った要素(位置は親の位置を足した絶対位置)。
|
|
65
|
+
* 入れ子の要素は、いちばん内側(上に描かれている)の要素だけが知らせる。
|
|
66
|
+
*/
|
|
67
|
+
initCallbacks (params) {
|
|
68
|
+
const callbacks = (params && params.callbacks) || {};
|
|
69
|
+
const element = callbacks.element || {};
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
element: {
|
|
73
|
+
click: element.click || null,
|
|
74
|
+
contextmenu: element.contextmenu || null,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
25
77
|
}
|
|
26
78
|
/* **************************************************************** *
|
|
27
79
|
* Rotation (回転ビュー)
|
|
@@ -64,7 +116,10 @@ export default class Rectum extends Colon {
|
|
|
64
116
|
lift: base.lift,
|
|
65
117
|
};
|
|
66
118
|
|
|
119
|
+
this._rotate_moved = false;
|
|
120
|
+
|
|
67
121
|
const move = (e) => {
|
|
122
|
+
this._rotate_moved = true;
|
|
68
123
|
this.rotation({
|
|
69
124
|
...rest,
|
|
70
125
|
y: this.clampAngle(start.y + (e.clientX - start.mx) * DEG_PER_PX),
|
|
@@ -74,6 +129,11 @@ export default class Rectum extends Colon {
|
|
|
74
129
|
const up = () => {
|
|
75
130
|
window.removeEventListener('mousemove', move);
|
|
76
131
|
window.removeEventListener('mouseup', up);
|
|
132
|
+
|
|
133
|
+
// 離したあとに届く click は、回転の操作の一部なので要素のクリックとして知らせない。
|
|
134
|
+
// click は mouseup の直後に届くので、タイマーで印を消す
|
|
135
|
+
// (mousedown で消す形にしないのは、d3.zoom が Ctrl なしの mousedown の伝播を止めるため)
|
|
136
|
+
setTimeout(() => { this._rotate_moved = false; }, 0);
|
|
77
137
|
};
|
|
78
138
|
|
|
79
139
|
window.addEventListener('mousemove', move);
|
|
@@ -122,58 +182,35 @@ export default class Rectum extends Colon {
|
|
|
122
182
|
|
|
123
183
|
this._rotation = v;
|
|
124
184
|
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
place.selectAll('*').remove();
|
|
185
|
+
// draw() が描いてあるものを消してから描き直す(0.3.0 から)
|
|
186
|
+
if (this.layer('foreground'))
|
|
128
187
|
this.draw();
|
|
129
|
-
}
|
|
130
188
|
|
|
131
189
|
return this;
|
|
132
190
|
}
|
|
133
191
|
/* **************************************************************** *
|
|
134
192
|
* Make Elements
|
|
135
193
|
* **************************************************************** */
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
let src = this.firstObject(source_sorted);
|
|
150
|
-
let trg = this.firstObject(target_sorted);
|
|
151
|
-
if (trg===null) {
|
|
152
|
-
// source にしか無いケース
|
|
153
|
-
if (src.visible!==false)
|
|
154
|
-
out.push(this.element.makeElement(src));
|
|
155
|
-
source_sorted.shift();
|
|
156
|
-
} else if (src===null) {
|
|
157
|
-
// target にしか無いやつは削除する。
|
|
158
|
-
target_sorted.shift();
|
|
159
|
-
} else if (src.id === trg._core.id) {
|
|
160
|
-
out.push(this.element.mergeCore(src, trg));
|
|
161
|
-
source_sorted.shift();
|
|
162
|
-
target_sorted.shift();
|
|
163
|
-
} else if (src.id < trg._core.id) {
|
|
164
|
-
// source にしか無いケース
|
|
165
|
-
out.push(this.element.makeElement(src));
|
|
166
|
-
source_sorted.shift();
|
|
167
|
-
} else {
|
|
168
|
-
// target にしか無いやつは削除する。
|
|
169
|
-
target_sorted.shift();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return out;
|
|
194
|
+
/**
|
|
195
|
+
* 根の要素を作る。data() のたびに、入力から作り直す(0.3.0 から。#195)。
|
|
196
|
+
*
|
|
197
|
+
* 0.2.1 までは、前の要素と突き合わせて(merge)いたが、入力の配列を並べ替えたうえで空にし、
|
|
198
|
+
* 同じ id(か id の無い)要素を 2 回目に渡すと TypeError で落ちていた。
|
|
199
|
+
*
|
|
200
|
+
* - 入力の配列は書き換えない(並べ替えは複製に対して行う)
|
|
201
|
+
* - 描く順番は、0.2.1 の 1 回目と同じ id の昇順(入力の順ではない)。比べ方も同じ
|
|
202
|
+
* - visible: false の根の要素は作らない(子は Element.makeElement が除く)
|
|
203
|
+
* - 自動の番号(id の無い要素・ラベル・アイコン)は、毎回 1 から振り直す
|
|
204
|
+
*/
|
|
205
|
+
sortRoots (list) {
|
|
206
|
+
return [...(list || [])].sort((a, b) => { return a.id<b.id ? -1 : 1; });
|
|
174
207
|
}
|
|
175
208
|
makeElements (list) {
|
|
176
|
-
|
|
209
|
+
this.element = new Element();
|
|
210
|
+
|
|
211
|
+
const new_list = this.sortRoots(list)
|
|
212
|
+
.filter(src => src.visible!==false)
|
|
213
|
+
.map(src => this.element.makeElement(src));
|
|
177
214
|
|
|
178
215
|
let pool = { ht: {}, list: [] };
|
|
179
216
|
|
|
@@ -211,6 +248,11 @@ export default class Rectum extends Colon {
|
|
|
211
248
|
|
|
212
249
|
return out;
|
|
213
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* 描く。描いてあるものを消してから、要素を描き直す(0.3.0 から。#195)。
|
|
253
|
+
* 各要素の描画は enter だけで、消す・更新する処理を持たないので、
|
|
254
|
+
* data() で要素を作り直しても、描いてあるものを消さないと図が変わらない(rotation() と同じやり方)。
|
|
255
|
+
*/
|
|
214
256
|
draw () {
|
|
215
257
|
const data = this.flatten(this._elements.list);
|
|
216
258
|
const place = this.layer('foreground');
|
|
@@ -218,7 +260,36 @@ export default class Rectum extends Colon {
|
|
|
218
260
|
if (!place)
|
|
219
261
|
return;
|
|
220
262
|
|
|
263
|
+
place.selectAll('*').remove();
|
|
264
|
+
|
|
221
265
|
this.element.draw(place, data, this.projector());
|
|
266
|
+
|
|
267
|
+
this.attachElementEvents(place);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* 要素のクリック・右クリックを知らせる(callbacks.element。0.3.0 から)。受けるのは要素のグループ(g.frame など)で、
|
|
271
|
+
* ラベルとアイコンは、その中にある。入れ子の要素は DOM では入れ子にならず、子が親より後(上)に描かれるので、
|
|
272
|
+
* いちばん内側の要素が受ける。コールバックがあるときだけ、カーソルを pointer にする。
|
|
273
|
+
* Ctrl + ドラッグで回転させた直後のクリックは知らせない。
|
|
274
|
+
*/
|
|
275
|
+
attachElementEvents (place) {
|
|
276
|
+
const { click, contextmenu } = this._callbacks.element;
|
|
277
|
+
|
|
278
|
+
if (!click && !contextmenu)
|
|
279
|
+
return;
|
|
280
|
+
|
|
281
|
+
const groups = place.selectAll(ELEMENT_GROUPS).style('cursor', 'pointer');
|
|
282
|
+
|
|
283
|
+
if (click)
|
|
284
|
+
groups.on('click', (event, d) => {
|
|
285
|
+
if (this._rotate_moved)
|
|
286
|
+
return;
|
|
287
|
+
|
|
288
|
+
notify(click, event, d._core, d);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
if (contextmenu)
|
|
292
|
+
groups.on('contextmenu', (event, d) => notify(contextmenu, event, d._core, d));
|
|
222
293
|
}
|
|
223
294
|
/* **************************************************************** *
|
|
224
295
|
* Data
|