squarified 0.4.0 → 0.4.2
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/dom-event-BLJt9knO.mjs +1646 -0
- package/dist/dom-event-CeVZ44nB.js +1686 -0
- package/dist/index-BoUEaWVv.d.ts +520 -0
- package/dist/index.d.mts +1 -620
- package/dist/index.d.ts +1 -620
- package/dist/index.js +113 -100
- package/dist/index.mjs +82 -69
- package/dist/plugin.d.mts +74 -427
- package/dist/plugin.d.ts +74 -427
- package/dist/plugin.js +451 -372
- package/dist/plugin.mjs +440 -362
- package/package.json +9 -6
- package/dist/dom-event-BPqG0KO2.js +0 -1712
- package/dist/dom-event-DQ8OFrZa.mjs +0 -1471
package/dist/plugin.mjs
CHANGED
|
@@ -1,394 +1,472 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as definePlugin, H as smoothFrame, r as createRoundBlock, F as stackMatrixTransform, S as Schedule, K as DEFAULT_MATRIX_LOC, I as isScrollWheelOrRightButtonOnMouseupAndDown, G as stackMatrixTransformWithGraphAndLayer, p as hashCode, P as PI_2, o as isWheelEvent, y as mixinWithParams } from './dom-event-BLJt9knO.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
// Currently, etoile is an internal module, so we won't need too much easing functions.
|
|
4
|
+
// And the animation logic is implemented by user code.
|
|
5
|
+
const easing = {
|
|
6
|
+
linear: (k)=>k,
|
|
7
|
+
quadraticIn: (k)=>k * k,
|
|
8
|
+
quadraticOut: (k)=>k * (2 - k),
|
|
9
|
+
quadraticInOut: (k)=>{
|
|
10
|
+
if ((k *= 2) < 1) {
|
|
11
|
+
return 0.5 * k * k;
|
|
12
|
+
}
|
|
13
|
+
return -0.5 * (--k * (k - 2) - 1);
|
|
14
|
+
},
|
|
15
|
+
cubicIn: (k)=>k * k * k,
|
|
16
|
+
cubicOut: (k)=>{
|
|
17
|
+
if ((k *= 2) < 1) {
|
|
18
|
+
return 0.5 * k * k * k;
|
|
19
|
+
}
|
|
20
|
+
return 0.5 * ((k -= 2) * k * k + 2);
|
|
21
|
+
},
|
|
22
|
+
cubicInOut: (k)=>{
|
|
23
|
+
if ((k *= 2) < 1) {
|
|
24
|
+
return 0.5 * k * k * k;
|
|
25
|
+
}
|
|
26
|
+
return 0.5 * ((k -= 2) * k * k + 2);
|
|
27
|
+
}
|
|
20
28
|
};
|
|
29
|
+
|
|
30
|
+
class Highlight extends Schedule {
|
|
31
|
+
reset() {
|
|
32
|
+
this.destory();
|
|
33
|
+
this.update();
|
|
34
|
+
}
|
|
35
|
+
get canvas() {
|
|
36
|
+
return this.render.canvas;
|
|
37
|
+
}
|
|
38
|
+
setZIndexForHighlight(zIndex = '-1') {
|
|
39
|
+
this.canvas.style.zIndex = zIndex;
|
|
40
|
+
}
|
|
41
|
+
init() {
|
|
42
|
+
this.setZIndexForHighlight();
|
|
43
|
+
this.canvas.style.position = 'absolute';
|
|
44
|
+
this.canvas.style.pointerEvents = 'none';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
21
47
|
const ANIMATION_DURATION = 300;
|
|
22
|
-
const HIGH_LIGHT_OPACITY = .3;
|
|
48
|
+
const HIGH_LIGHT_OPACITY = 0.3;
|
|
23
49
|
const fill = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
50
|
+
desc: {
|
|
51
|
+
r: 255,
|
|
52
|
+
g: 255,
|
|
53
|
+
b: 255
|
|
54
|
+
},
|
|
55
|
+
mode: 'rgb'
|
|
30
56
|
};
|
|
31
57
|
const presetHighlightPlugin = definePlugin({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
58
|
+
name: 'treemap:preset-highlight',
|
|
59
|
+
onLoad () {
|
|
60
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
61
|
+
if (!meta) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!meta.highlight) {
|
|
65
|
+
meta.highlight = new Highlight(this.instance.to);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
onDOMEventTriggered (name, _, module, { stateManager: state, matrix }) {
|
|
69
|
+
if (name === 'mousemove') {
|
|
70
|
+
if (state.canTransition('MOVE')) {
|
|
71
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
72
|
+
if (!module) {
|
|
73
|
+
meta.highlight?.reset();
|
|
74
|
+
meta.highlight?.update();
|
|
75
|
+
meta.highlight?.setZIndexForHighlight();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const [x, y, w, h] = module.layout;
|
|
79
|
+
const effectiveRadius = Math.min(module.config.rectRadius, w / 4, h / 4);
|
|
80
|
+
smoothFrame((_, cleanup)=>{
|
|
81
|
+
cleanup();
|
|
82
|
+
meta.highlight?.reset();
|
|
83
|
+
const mask = createRoundBlock(x, y, w, h, {
|
|
84
|
+
fill,
|
|
85
|
+
opacity: HIGH_LIGHT_OPACITY,
|
|
86
|
+
radius: effectiveRadius,
|
|
87
|
+
padding: 0
|
|
88
|
+
});
|
|
89
|
+
meta.highlight?.add(mask);
|
|
90
|
+
meta.highlight?.setZIndexForHighlight('1');
|
|
91
|
+
stackMatrixTransform(mask, matrix.e, matrix.f, matrix.a);
|
|
92
|
+
meta.highlight?.update();
|
|
93
|
+
}, {
|
|
94
|
+
duration: ANIMATION_DURATION
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
onResize () {
|
|
100
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
101
|
+
if (!meta) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
meta.highlight?.render.initOptions({
|
|
105
|
+
...this.instance.render.options
|
|
106
|
+
});
|
|
107
|
+
meta.highlight?.reset();
|
|
108
|
+
meta.highlight?.init();
|
|
109
|
+
},
|
|
110
|
+
onDispose () {
|
|
111
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
112
|
+
if (meta && meta.highlight) {
|
|
113
|
+
meta.highlight.destory();
|
|
114
|
+
meta.highlight = null;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
meta: {
|
|
118
|
+
highlight: null
|
|
119
|
+
}
|
|
82
120
|
});
|
|
83
121
|
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/plugins/drag.ts
|
|
86
122
|
const presetDragElementPlugin = definePlugin({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
123
|
+
name: 'treemap:preset-drag-element',
|
|
124
|
+
onDOMEventTriggered (name, event, module, domEvent) {
|
|
125
|
+
const { stateManager: state, matrix, component } = domEvent;
|
|
126
|
+
switch(name){
|
|
127
|
+
case 'mousemove':
|
|
128
|
+
{
|
|
129
|
+
if (state.isInState('DRAGGING')) {
|
|
130
|
+
domEvent.silent('click');
|
|
131
|
+
} else {
|
|
132
|
+
domEvent.active('click');
|
|
133
|
+
}
|
|
134
|
+
const meta = getDragOptions.call(this);
|
|
135
|
+
if (!meta) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (meta.dragOptions.x === 0 && meta.dragOptions.y === 0) {
|
|
139
|
+
state.transition('IDLE');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
state.transition('DRAGGING');
|
|
143
|
+
if (state.isInState('DRAGGING')) {
|
|
144
|
+
const highlight = getHighlightInstance.call(this);
|
|
145
|
+
smoothFrame((_, cleanup)=>{
|
|
146
|
+
cleanup();
|
|
147
|
+
const { offsetX, offsetY } = event.native;
|
|
148
|
+
const drawX = offsetX - meta.dragOptions.x;
|
|
149
|
+
const drawY = offsetY - meta.dragOptions.y;
|
|
150
|
+
const lastX = meta.dragOptions.x;
|
|
151
|
+
const lastY = meta.dragOptions.y;
|
|
152
|
+
if (highlight?.highlight) {
|
|
153
|
+
highlight.highlight.reset();
|
|
154
|
+
highlight.highlight.setZIndexForHighlight();
|
|
155
|
+
}
|
|
156
|
+
matrix.translation(drawX, drawY);
|
|
157
|
+
meta.dragOptions.x = offsetX;
|
|
158
|
+
meta.dragOptions.y = offsetY;
|
|
159
|
+
meta.dragOptions.lastX = lastX;
|
|
160
|
+
meta.dragOptions.lastY = lastY;
|
|
161
|
+
component.cleanup();
|
|
162
|
+
component.draw(false, false);
|
|
163
|
+
stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
|
|
164
|
+
component.update();
|
|
165
|
+
return true;
|
|
166
|
+
}, {
|
|
167
|
+
duration: ANIMATION_DURATION,
|
|
168
|
+
deps: [
|
|
169
|
+
()=>state.isInState('IDLE')
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case 'mouseup':
|
|
176
|
+
{
|
|
177
|
+
if (state.isInState('PRESSED')) {
|
|
178
|
+
const meta = getDragOptions.call(this);
|
|
179
|
+
if (meta && meta.dragOptions) {
|
|
180
|
+
if (meta.dragOptions.x === meta.dragOptions.lastX && meta.dragOptions.y === meta.dragOptions.lastY) {
|
|
181
|
+
state.transition('IDLE');
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (state.isInState('DRAGGING') && state.canTransition('IDLE')) {
|
|
187
|
+
const highlight = getHighlightInstance.call(this);
|
|
188
|
+
if (highlight && highlight.highlight) {
|
|
189
|
+
highlight.highlight.reset();
|
|
190
|
+
highlight.highlight.setZIndexForHighlight();
|
|
191
|
+
}
|
|
192
|
+
const meta = getDragOptions.call(this);
|
|
193
|
+
if (meta && meta.dragOptions) {
|
|
194
|
+
meta.dragOptions.x = 0;
|
|
195
|
+
meta.dragOptions.y = 0;
|
|
196
|
+
meta.dragOptions.lastX = 0;
|
|
197
|
+
meta.dragOptions.lastY = 0;
|
|
198
|
+
state.transition('IDLE');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case 'mousedown':
|
|
204
|
+
{
|
|
205
|
+
if (isScrollWheelOrRightButtonOnMouseupAndDown(event.native)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const meta = getDragOptions.call(this);
|
|
209
|
+
if (!meta) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
meta.dragOptions.x = event.native.offsetX;
|
|
213
|
+
meta.dragOptions.y = event.native.offsetY;
|
|
214
|
+
meta.dragOptions.lastX = event.native.offsetX;
|
|
215
|
+
meta.dragOptions.lastY = event.native.offsetY;
|
|
216
|
+
state.transition('PRESSED');
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
meta: {
|
|
222
|
+
dragOptions: {
|
|
223
|
+
x: 0,
|
|
224
|
+
y: 0,
|
|
225
|
+
lastX: 0,
|
|
226
|
+
lastY: 0
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
onResize ({ matrix, stateManager: state }) {
|
|
230
|
+
matrix.create(DEFAULT_MATRIX_LOC);
|
|
231
|
+
state.reset();
|
|
232
|
+
}
|
|
181
233
|
});
|
|
182
234
|
function getHighlightInstance() {
|
|
183
|
-
|
|
235
|
+
return this.getPluginMetadata('treemap:preset-highlight');
|
|
184
236
|
}
|
|
185
237
|
function getDragOptions() {
|
|
186
|
-
|
|
187
|
-
|
|
238
|
+
const meta = this.getPluginMetadata('treemap:preset-drag-element');
|
|
239
|
+
return meta;
|
|
188
240
|
}
|
|
189
241
|
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region src/plugins/preset-color.ts
|
|
192
242
|
const presetColorPlugin = definePlugin({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
243
|
+
name: 'treemap:preset-color',
|
|
244
|
+
onModuleInit (modules) {
|
|
245
|
+
const colorMappings = {};
|
|
246
|
+
for(let i = 0; i < modules.length; i++){
|
|
247
|
+
const module = modules[i];
|
|
248
|
+
assignColorMappings(colorMappings, module, Math.abs(hashCode(module.node.id)) % PI_2, 0);
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
colorMappings
|
|
252
|
+
};
|
|
253
|
+
}
|
|
202
254
|
});
|
|
203
255
|
function assignColorMappings(colorMappings, module, ancestorHue, depth) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
256
|
+
const hueOffset = Math.abs(hashCode(module.node.id)) % 60 - 30;
|
|
257
|
+
const hue = (ancestorHue + hueOffset) % 360;
|
|
258
|
+
const saturation = Math.max(75 - depth * 5, 40);
|
|
259
|
+
const baseLightness = 55 - depth * 3;
|
|
260
|
+
const color = adjustColorToComfortableForHumanEye(hue, saturation, baseLightness);
|
|
261
|
+
colorMappings[module.node.id] = color;
|
|
262
|
+
if (module.node.isCombinedNode && module.node.originalNodes) {
|
|
263
|
+
for (const combined of module.node.originalNodes){
|
|
264
|
+
colorMappings[combined.id] = color;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (module.children && module.children.length) {
|
|
268
|
+
const childCount = module.children.length;
|
|
269
|
+
for(let i = 0; i < childCount; i++){
|
|
270
|
+
const childHueOffset = 40 * i / childCount;
|
|
271
|
+
const childHue = (hue + childHueOffset) % 360;
|
|
272
|
+
assignColorMappings(colorMappings, module.children[i], childHue, depth + 1);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
219
275
|
}
|
|
220
276
|
function adjustColorToComfortableForHumanEye(hue, saturation, lightness) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
277
|
+
hue = (hue % 360 + 360) % 360;
|
|
278
|
+
saturation = Math.min(Math.max(saturation, 40), 85);
|
|
279
|
+
lightness = Math.min(Math.max(lightness, 35), 75);
|
|
280
|
+
if (hue >= 60 && hue <= 180) {
|
|
281
|
+
saturation = Math.max(saturation - 10, 40);
|
|
282
|
+
lightness = Math.min(lightness + 5, 75);
|
|
283
|
+
} else if (hue >= 200 && hue <= 280) {
|
|
284
|
+
lightness = Math.min(lightness + 8, 75);
|
|
285
|
+
} else if (hue >= 0 && hue <= 30) {
|
|
286
|
+
saturation = Math.max(saturation - 5, 40);
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
mode: 'hsl',
|
|
290
|
+
desc: {
|
|
291
|
+
h: hue,
|
|
292
|
+
s: saturation,
|
|
293
|
+
l: lightness
|
|
294
|
+
}
|
|
295
|
+
};
|
|
237
296
|
}
|
|
238
297
|
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/plugins/wheel.ts
|
|
241
298
|
function presetScalePlugin(options) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
299
|
+
return definePlugin({
|
|
300
|
+
name: 'treemap:preset-scale',
|
|
301
|
+
onDOMEventTriggered (_, event, module, evt) {
|
|
302
|
+
if (isWheelEvent(event)) {
|
|
303
|
+
onWheel(this, event, evt);
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
meta: {
|
|
307
|
+
scaleOptions: {
|
|
308
|
+
scale: 1,
|
|
309
|
+
minScale: options?.min || 0.1,
|
|
310
|
+
maxScale: options?.max || Infinity,
|
|
311
|
+
scaleFactor: 0.05
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
onResize ({ matrix, stateManager: state }) {
|
|
315
|
+
const meta = getScaleOptions.call(this);
|
|
316
|
+
if (meta) {
|
|
317
|
+
meta.scaleOptions.scale = 1;
|
|
318
|
+
}
|
|
319
|
+
matrix.create(DEFAULT_MATRIX_LOC);
|
|
320
|
+
state.reset();
|
|
321
|
+
}
|
|
322
|
+
});
|
|
260
323
|
}
|
|
261
324
|
function getScaleOptions() {
|
|
262
|
-
|
|
263
|
-
|
|
325
|
+
const meta = this.getPluginMetadata('treemap:preset-scale');
|
|
326
|
+
return meta;
|
|
264
327
|
}
|
|
265
328
|
function onWheel(pluginContext, event, { stateManager: state, component, matrix }) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
329
|
+
event.native.preventDefault();
|
|
330
|
+
const meta = getScaleOptions.call(pluginContext);
|
|
331
|
+
if (!meta) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
|
|
335
|
+
const delta = event.native.deltaY < 0 ? scaleFactor : -scaleFactor;
|
|
336
|
+
const newScale = Math.max(minScale, Math.min(maxScale, scale + delta));
|
|
337
|
+
if (newScale === scale) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
state.transition('SCALING');
|
|
341
|
+
const mouseX = event.native.offsetX;
|
|
342
|
+
const mouseY = event.native.offsetY;
|
|
343
|
+
const scaleDiff = newScale / scale;
|
|
344
|
+
meta.scaleOptions.scale = newScale;
|
|
345
|
+
const highlight = getHighlightInstance.apply(pluginContext);
|
|
346
|
+
smoothFrame((_, cleanup)=>{
|
|
347
|
+
cleanup();
|
|
348
|
+
if (highlight && highlight.highlight) {
|
|
349
|
+
highlight.highlight.reset();
|
|
350
|
+
highlight.highlight.setZIndexForHighlight();
|
|
351
|
+
}
|
|
352
|
+
matrix.scale(scaleDiff, scaleDiff);
|
|
353
|
+
matrix.e = mouseX - (mouseX - matrix.e) * scaleDiff;
|
|
354
|
+
matrix.f = mouseY - (mouseY - matrix.f) * scaleDiff;
|
|
355
|
+
component.cleanup();
|
|
356
|
+
const { width, height } = component.render.options;
|
|
357
|
+
component.layoutNodes = component.calculateLayoutNodes(component.data, {
|
|
358
|
+
w: width,
|
|
359
|
+
h: height,
|
|
360
|
+
x: 0,
|
|
361
|
+
y: 0
|
|
362
|
+
}, matrix.a);
|
|
363
|
+
component.draw(true, false);
|
|
364
|
+
stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, newScale);
|
|
365
|
+
component.update();
|
|
366
|
+
if (state.canTransition('IDLE')) {
|
|
367
|
+
state.transition('IDLE');
|
|
368
|
+
}
|
|
369
|
+
return true;
|
|
370
|
+
}, {
|
|
371
|
+
duration: ANIMATION_DURATION
|
|
372
|
+
});
|
|
302
373
|
}
|
|
303
374
|
|
|
304
|
-
|
|
305
|
-
//#region src/plugins/zoomable.ts
|
|
306
|
-
const MAX_SCALE_MULTIPLIER = 2;
|
|
375
|
+
const MAX_SCALE_MULTIPLIER = 2.0;
|
|
307
376
|
const presetZoomablePlugin = definePlugin({
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
377
|
+
name: 'treemap:preset-zoomable',
|
|
378
|
+
onLoad (treemap, { stateManager: state, matrix }) {
|
|
379
|
+
return mixinWithParams(treemap, [
|
|
380
|
+
{
|
|
381
|
+
name: 'zoom',
|
|
382
|
+
fn: ()=>(id)=>{
|
|
383
|
+
const meta = this.getPluginMetadata('treemap:preset-zoomable');
|
|
384
|
+
if (!meta || state.isInState('ZOOMING')) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const targetModule = this.resolveModuleById(id);
|
|
388
|
+
if (!targetModule) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
meta.previousMatrixState = {
|
|
392
|
+
e: matrix.e,
|
|
393
|
+
f: matrix.f,
|
|
394
|
+
a: matrix.a,
|
|
395
|
+
d: matrix.d
|
|
396
|
+
};
|
|
397
|
+
const component = this.instance;
|
|
398
|
+
state.transition('ZOOMING');
|
|
399
|
+
const [nodeX, nodeY, nodeW, nodeH] = targetModule.layout;
|
|
400
|
+
const { width, height } = component.render.options;
|
|
401
|
+
const currentScale = matrix.a;
|
|
402
|
+
const scaleX = width / nodeW;
|
|
403
|
+
const scaleY = height / nodeH;
|
|
404
|
+
const fullScale = Math.min(scaleX, scaleY) * 0.9;
|
|
405
|
+
const targetScale = Math.min(fullScale, currentScale * MAX_SCALE_MULTIPLIER);
|
|
406
|
+
const scale = targetScale;
|
|
407
|
+
const nodeCenterX = nodeX + nodeW / 2;
|
|
408
|
+
const nodeCenterY = nodeY + nodeH / 2;
|
|
409
|
+
const viewCenterX = width / 2;
|
|
410
|
+
const viewCenterY = height / 2;
|
|
411
|
+
const targetE = viewCenterX - nodeCenterX * scale;
|
|
412
|
+
const targetF = viewCenterY - nodeCenterY * scale;
|
|
413
|
+
const scaleMeta = getScaleOptions.call(this);
|
|
414
|
+
if (scaleMeta) {
|
|
415
|
+
scaleMeta.scaleOptions.scale = scale;
|
|
416
|
+
}
|
|
417
|
+
const highlight = getHighlightInstance.call(this);
|
|
418
|
+
const dragMeta = getDragOptions.call(this);
|
|
419
|
+
if (dragMeta) {
|
|
420
|
+
dragMeta.dragOptions.x = 0;
|
|
421
|
+
dragMeta.dragOptions.y = 0;
|
|
422
|
+
dragMeta.dragOptions.lastX = 0;
|
|
423
|
+
dragMeta.dragOptions.lastY = 0;
|
|
424
|
+
}
|
|
425
|
+
const startMatrix = {
|
|
426
|
+
e: matrix.e,
|
|
427
|
+
f: matrix.f,
|
|
428
|
+
a: matrix.a,
|
|
429
|
+
d: matrix.d
|
|
430
|
+
};
|
|
431
|
+
smoothFrame((progress)=>{
|
|
432
|
+
const easedProgress = easing.cubicInOut(progress);
|
|
433
|
+
const currentE = startMatrix.e + (targetE - startMatrix.e) * easedProgress;
|
|
434
|
+
const currentF = startMatrix.f + (targetF - startMatrix.f) * easedProgress;
|
|
435
|
+
const currentA = startMatrix.a + (scale - startMatrix.a) * easedProgress;
|
|
436
|
+
const currentD = startMatrix.d + (scale - startMatrix.d) * easedProgress;
|
|
437
|
+
matrix.create(DEFAULT_MATRIX_LOC);
|
|
438
|
+
matrix.e = currentE;
|
|
439
|
+
matrix.f = currentF;
|
|
440
|
+
matrix.a = currentA;
|
|
441
|
+
matrix.d = currentD;
|
|
442
|
+
if (highlight?.highlight) {
|
|
443
|
+
highlight.highlight.reset();
|
|
444
|
+
highlight.highlight.setZIndexForHighlight();
|
|
445
|
+
}
|
|
446
|
+
component.cleanup();
|
|
447
|
+
const { width, height } = component.render.options;
|
|
448
|
+
component.layoutNodes = component.calculateLayoutNodes(component.data, {
|
|
449
|
+
w: width,
|
|
450
|
+
h: height,
|
|
451
|
+
x: 0,
|
|
452
|
+
y: 0
|
|
453
|
+
}, matrix.a);
|
|
454
|
+
component.draw(true, false);
|
|
455
|
+
stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
|
|
456
|
+
component.update();
|
|
457
|
+
}, {
|
|
458
|
+
duration: ANIMATION_DURATION,
|
|
459
|
+
onStop: ()=>{
|
|
460
|
+
state.reset();
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
]);
|
|
466
|
+
},
|
|
467
|
+
meta: {
|
|
468
|
+
isZooming: false
|
|
469
|
+
}
|
|
391
470
|
});
|
|
392
471
|
|
|
393
|
-
|
|
394
|
-
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
|
|
472
|
+
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
|