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