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/plugin.mjs CHANGED
@@ -1,394 +1,472 @@
1
- import { DEFAULT_MATRIX_LOC, PI_2, Schedule, createRoundBlock, definePlugin, easing, hashCode, isScrollWheelOrRightButtonOnMouseupAndDown, isWheelEvent, mixinWithParams, smoothFrame, stackMatrixTransform, stackMatrixTransformWithGraphAndLayer } from "./dom-event-DQ8OFrZa.mjs";
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
- //#region src/plugins/highlight.ts
4
- var Highlight = class extends Schedule {
5
- reset() {
6
- this.destory();
7
- this.update();
8
- }
9
- get canvas() {
10
- return this.render.canvas;
11
- }
12
- setZIndexForHighlight(zIndex = "-1") {
13
- this.canvas.style.zIndex = zIndex;
14
- }
15
- init() {
16
- this.setZIndexForHighlight();
17
- this.canvas.style.position = "absolute";
18
- this.canvas.style.pointerEvents = "none";
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
- desc: {
25
- r: 255,
26
- g: 255,
27
- b: 255
28
- },
29
- mode: "rgb"
50
+ desc: {
51
+ r: 255,
52
+ g: 255,
53
+ b: 255
54
+ },
55
+ mode: 'rgb'
30
56
  };
31
57
  const presetHighlightPlugin = definePlugin({
32
- name: "treemap:preset-highlight",
33
- onLoad() {
34
- const meta = this.getPluginMetadata("treemap:preset-highlight");
35
- if (!meta) return;
36
- if (!meta.highlight) meta.highlight = new Highlight(this.instance.to);
37
- },
38
- onDOMEventTriggered(name, _, module, { stateManager: state, matrix }) {
39
- if (name === "mousemove") {
40
- if (state.canTransition("MOVE")) {
41
- const meta = this.getPluginMetadata("treemap:preset-highlight");
42
- if (!module) {
43
- meta.highlight?.reset();
44
- meta.highlight?.update();
45
- meta.highlight?.setZIndexForHighlight();
46
- return;
47
- }
48
- const [x, y, w, h] = module.layout;
49
- const effectiveRadius = Math.min(module.config.rectRadius, w / 4, h / 4);
50
- smoothFrame((_$1, cleanup) => {
51
- cleanup();
52
- meta.highlight?.reset();
53
- const mask = createRoundBlock(x, y, w, h, {
54
- fill,
55
- opacity: HIGH_LIGHT_OPACITY,
56
- radius: effectiveRadius,
57
- padding: 0
58
- });
59
- meta.highlight?.add(mask);
60
- meta.highlight?.setZIndexForHighlight("1");
61
- stackMatrixTransform(mask, matrix.e, matrix.f, matrix.a);
62
- meta.highlight?.update();
63
- }, { duration: ANIMATION_DURATION });
64
- }
65
- }
66
- },
67
- onResize() {
68
- const meta = this.getPluginMetadata("treemap:preset-highlight");
69
- if (!meta) return;
70
- meta.highlight?.render.initOptions({ ...this.instance.render.options });
71
- meta.highlight?.reset();
72
- meta.highlight?.init();
73
- },
74
- onDispose() {
75
- const meta = this.getPluginMetadata("treemap:preset-highlight");
76
- if (meta && meta.highlight) {
77
- meta.highlight.destory();
78
- meta.highlight = null;
79
- }
80
- },
81
- meta: { highlight: null }
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
- name: "treemap:preset-drag-element",
88
- onDOMEventTriggered(name, event, module, domEvent) {
89
- const { stateManager: state, matrix, component } = domEvent;
90
- switch (name) {
91
- case "mousemove": {
92
- if (state.isInState("DRAGGING")) domEvent.silent("click");
93
- else domEvent.active("click");
94
- const meta = getDragOptions.call(this);
95
- if (!meta) return;
96
- if (meta.dragOptions.x === 0 && meta.dragOptions.y === 0) {
97
- state.transition("IDLE");
98
- return;
99
- }
100
- state.transition("DRAGGING");
101
- if (state.isInState("DRAGGING")) {
102
- const highlight = getHighlightInstance.call(this);
103
- smoothFrame((_, cleanup) => {
104
- cleanup();
105
- const { offsetX, offsetY } = event.native;
106
- const drawX = offsetX - meta.dragOptions.x;
107
- const drawY = offsetY - meta.dragOptions.y;
108
- const lastX = meta.dragOptions.x;
109
- const lastY = meta.dragOptions.y;
110
- if (highlight?.highlight) {
111
- highlight.highlight.reset();
112
- highlight.highlight.setZIndexForHighlight();
113
- }
114
- matrix.translation(drawX, drawY);
115
- meta.dragOptions.x = offsetX;
116
- meta.dragOptions.y = offsetY;
117
- meta.dragOptions.lastX = lastX;
118
- meta.dragOptions.lastY = lastY;
119
- component.cleanup();
120
- component.draw(false, false);
121
- stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
122
- component.update();
123
- return true;
124
- }, {
125
- duration: ANIMATION_DURATION,
126
- deps: [() => state.isInState("IDLE")]
127
- });
128
- }
129
- break;
130
- }
131
- case "mouseup": {
132
- if (state.isInState("PRESSED")) {
133
- const meta = getDragOptions.call(this);
134
- if (meta && meta.dragOptions) {
135
- if (meta.dragOptions.x === meta.dragOptions.lastX && meta.dragOptions.y === meta.dragOptions.lastY) {
136
- state.transition("IDLE");
137
- return;
138
- }
139
- }
140
- }
141
- if (state.isInState("DRAGGING") && state.canTransition("IDLE")) {
142
- const highlight = getHighlightInstance.call(this);
143
- if (highlight && highlight.highlight) {
144
- highlight.highlight.reset();
145
- highlight.highlight.setZIndexForHighlight();
146
- }
147
- const meta = getDragOptions.call(this);
148
- if (meta && meta.dragOptions) {
149
- meta.dragOptions.x = 0;
150
- meta.dragOptions.y = 0;
151
- meta.dragOptions.lastX = 0;
152
- meta.dragOptions.lastY = 0;
153
- state.transition("IDLE");
154
- }
155
- }
156
- break;
157
- }
158
- case "mousedown": {
159
- if (isScrollWheelOrRightButtonOnMouseupAndDown(event.native)) return;
160
- const meta = getDragOptions.call(this);
161
- if (!meta) return;
162
- meta.dragOptions.x = event.native.offsetX;
163
- meta.dragOptions.y = event.native.offsetY;
164
- meta.dragOptions.lastX = event.native.offsetX;
165
- meta.dragOptions.lastY = event.native.offsetY;
166
- state.transition("PRESSED");
167
- break;
168
- }
169
- }
170
- },
171
- meta: { dragOptions: {
172
- x: 0,
173
- y: 0,
174
- lastX: 0,
175
- lastY: 0
176
- } },
177
- onResize({ matrix, stateManager: state }) {
178
- matrix.create(DEFAULT_MATRIX_LOC);
179
- state.reset();
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
- return this.getPluginMetadata("treemap:preset-highlight");
235
+ return this.getPluginMetadata('treemap:preset-highlight');
184
236
  }
185
237
  function getDragOptions() {
186
- const meta = this.getPluginMetadata("treemap:preset-drag-element");
187
- return meta;
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
- name: "treemap:preset-color",
194
- onModuleInit(modules) {
195
- const colorMappings = {};
196
- for (let i = 0; i < modules.length; i++) {
197
- const module = modules[i];
198
- assignColorMappings(colorMappings, module, Math.abs(hashCode(module.node.id)) % PI_2, 0);
199
- }
200
- return { colorMappings };
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
- const hueOffset = Math.abs(hashCode(module.node.id)) % 60 - 30;
205
- const hue = (ancestorHue + hueOffset) % 360;
206
- const saturation = Math.max(75 - depth * 5, 40);
207
- const baseLightness = 55 - depth * 3;
208
- const color = adjustColorToComfortableForHumanEye(hue, saturation, baseLightness);
209
- colorMappings[module.node.id] = color;
210
- if (module.node.isCombinedNode && module.node.originalNodes) for (const combined of module.node.originalNodes) colorMappings[combined.id] = color;
211
- if (module.children && module.children.length) {
212
- const childCount = module.children.length;
213
- for (let i = 0; i < childCount; i++) {
214
- const childHueOffset = 40 * i / childCount;
215
- const childHue = (hue + childHueOffset) % 360;
216
- assignColorMappings(colorMappings, module.children[i], childHue, depth + 1);
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
- hue = (hue % 360 + 360) % 360;
222
- saturation = Math.min(Math.max(saturation, 40), 85);
223
- lightness = Math.min(Math.max(lightness, 35), 75);
224
- if (hue >= 60 && hue <= 180) {
225
- saturation = Math.max(saturation - 10, 40);
226
- lightness = Math.min(lightness + 5, 75);
227
- } else if (hue >= 200 && hue <= 280) lightness = Math.min(lightness + 8, 75);
228
- else if (hue >= 0 && hue <= 30) saturation = Math.max(saturation - 5, 40);
229
- return {
230
- mode: "hsl",
231
- desc: {
232
- h: hue,
233
- s: saturation,
234
- l: lightness
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
- return definePlugin({
243
- name: "treemap:preset-scale",
244
- onDOMEventTriggered(_, event, module, evt) {
245
- if (isWheelEvent(event)) onWheel(this, event, evt);
246
- },
247
- meta: { scaleOptions: {
248
- scale: 1,
249
- minScale: options?.min || .1,
250
- maxScale: options?.max || Infinity,
251
- scaleFactor: .05
252
- } },
253
- onResize({ matrix, stateManager: state }) {
254
- const meta = getScaleOptions.call(this);
255
- if (meta) meta.scaleOptions.scale = 1;
256
- matrix.create(DEFAULT_MATRIX_LOC);
257
- state.reset();
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
- const meta = this.getPluginMetadata("treemap:preset-scale");
263
- return meta;
325
+ const meta = this.getPluginMetadata('treemap:preset-scale');
326
+ return meta;
264
327
  }
265
328
  function onWheel(pluginContext, event, { stateManager: state, component, matrix }) {
266
- event.native.preventDefault();
267
- const meta = getScaleOptions.call(pluginContext);
268
- if (!meta) return;
269
- const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
270
- const delta = event.native.deltaY < 0 ? scaleFactor : -scaleFactor;
271
- const newScale = Math.max(minScale, Math.min(maxScale, scale + delta));
272
- if (newScale === scale) return;
273
- state.transition("SCALING");
274
- const mouseX = event.native.offsetX;
275
- const mouseY = event.native.offsetY;
276
- const scaleDiff = newScale / scale;
277
- meta.scaleOptions.scale = newScale;
278
- const highlight = getHighlightInstance.apply(pluginContext);
279
- smoothFrame((_, cleanup) => {
280
- cleanup();
281
- if (highlight && highlight.highlight) {
282
- highlight.highlight.reset();
283
- highlight.highlight.setZIndexForHighlight();
284
- }
285
- matrix.scale(scaleDiff, scaleDiff);
286
- matrix.e = mouseX - (mouseX - matrix.e) * scaleDiff;
287
- matrix.f = mouseY - (mouseY - matrix.f) * scaleDiff;
288
- component.cleanup();
289
- const { width, height } = component.render.options;
290
- component.layoutNodes = component.calculateLayoutNodes(component.data, {
291
- w: width,
292
- h: height,
293
- x: 0,
294
- y: 0
295
- }, matrix.a);
296
- component.draw(true, false);
297
- stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, newScale);
298
- component.update();
299
- if (state.canTransition("IDLE")) state.transition("IDLE");
300
- return true;
301
- }, { duration: ANIMATION_DURATION });
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
- //#endregion
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
- name: "treemap:preset-zoomable",
309
- onLoad(treemap, { stateManager: state, matrix }) {
310
- return mixinWithParams(treemap, [{
311
- name: "zoom",
312
- fn: () => (id) => {
313
- const meta = this.getPluginMetadata("treemap:preset-zoomable");
314
- if (!meta || state.isInState("ZOOMING")) return;
315
- const targetModule = this.resolveModuleById(id);
316
- if (!targetModule) return;
317
- meta.previousMatrixState = {
318
- e: matrix.e,
319
- f: matrix.f,
320
- a: matrix.a,
321
- d: matrix.d
322
- };
323
- const component = this.instance;
324
- state.transition("ZOOMING");
325
- const [nodeX, nodeY, nodeW, nodeH] = targetModule.layout;
326
- const { width, height } = component.render.options;
327
- const currentScale = matrix.a;
328
- const scaleX = width / nodeW;
329
- const scaleY = height / nodeH;
330
- const fullScale = Math.min(scaleX, scaleY) * .9;
331
- const targetScale = Math.min(fullScale, currentScale * MAX_SCALE_MULTIPLIER);
332
- const scale = targetScale;
333
- const nodeCenterX = nodeX + nodeW / 2;
334
- const nodeCenterY = nodeY + nodeH / 2;
335
- const viewCenterX = width / 2;
336
- const viewCenterY = height / 2;
337
- const targetE = viewCenterX - nodeCenterX * scale;
338
- const targetF = viewCenterY - nodeCenterY * scale;
339
- const scaleMeta = getScaleOptions.call(this);
340
- if (scaleMeta) scaleMeta.scaleOptions.scale = scale;
341
- const highlight = getHighlightInstance.call(this);
342
- const dragMeta = getDragOptions.call(this);
343
- if (dragMeta) {
344
- dragMeta.dragOptions.x = 0;
345
- dragMeta.dragOptions.y = 0;
346
- dragMeta.dragOptions.lastX = 0;
347
- dragMeta.dragOptions.lastY = 0;
348
- }
349
- const startMatrix = {
350
- e: matrix.e,
351
- f: matrix.f,
352
- a: matrix.a,
353
- d: matrix.d
354
- };
355
- smoothFrame((progress) => {
356
- const easedProgress = easing.cubicInOut(progress);
357
- const currentE = startMatrix.e + (targetE - startMatrix.e) * easedProgress;
358
- const currentF = startMatrix.f + (targetF - startMatrix.f) * easedProgress;
359
- const currentA = startMatrix.a + (scale - startMatrix.a) * easedProgress;
360
- const currentD = startMatrix.d + (scale - startMatrix.d) * easedProgress;
361
- matrix.create(DEFAULT_MATRIX_LOC);
362
- matrix.e = currentE;
363
- matrix.f = currentF;
364
- matrix.a = currentA;
365
- matrix.d = currentD;
366
- if (highlight?.highlight) {
367
- highlight.highlight.reset();
368
- highlight.highlight.setZIndexForHighlight();
369
- }
370
- component.cleanup();
371
- const { width: width$1, height: height$1 } = component.render.options;
372
- component.layoutNodes = component.calculateLayoutNodes(component.data, {
373
- w: width$1,
374
- h: height$1,
375
- x: 0,
376
- y: 0
377
- }, matrix.a);
378
- component.draw(true, false);
379
- stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
380
- component.update();
381
- }, {
382
- duration: ANIMATION_DURATION,
383
- onStop: () => {
384
- state.reset();
385
- }
386
- });
387
- }
388
- }]);
389
- },
390
- meta: { isZooming: false }
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
- //#endregion
394
- export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
472
+ export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };