squarified 0.4.2 → 0.4.3
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 +4 -2
- package/dist/plugin.d.mts +16 -1
- package/dist/plugin.d.ts +16 -1
- package/dist/plugin.js +69 -1
- package/dist/plugin.mjs +70 -3
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
`squarified` is a minimal and powerful treemap component.
|
|
4
4
|
|
|
5
|
-
https://github.com/user-attachments/assets/caf30d9d-0a5a-446a-b767-7927bf4387c9
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
7
|
```shell
|
|
@@ -18,6 +16,10 @@ nonzzz.github.io/squarified/
|
|
|
18
16
|
|
|
19
17
|
Kanno
|
|
20
18
|
|
|
19
|
+
### Credits
|
|
20
|
+
|
|
21
|
+
Algorithm is ported from [esbuild Bundle Size Analyzer](https://esbuild.github.io/analyze/) by [Evan Wallace](https://github.com/evanw). Refactor algorithm to adjusted the layout.
|
|
22
|
+
|
|
21
23
|
### LICENSE
|
|
22
24
|
|
|
23
25
|
[MIT](./LICENSE)
|
package/dist/plugin.d.mts
CHANGED
|
@@ -25,6 +25,21 @@ declare const presetDragElementPlugin: {
|
|
|
25
25
|
onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
interface MenuRenderConfig {
|
|
29
|
+
html: string;
|
|
30
|
+
action: string;
|
|
31
|
+
}
|
|
32
|
+
interface MenuPluginOptions {
|
|
33
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
34
|
+
render?: (menu: HTMLDivElement) => MenuRenderConfig[];
|
|
35
|
+
onClick?: (action: string, module: LayoutModule | null) => void;
|
|
36
|
+
}
|
|
37
|
+
declare function presetMenuPlugin(options?: MenuPluginOptions): {
|
|
38
|
+
name: "treemap:preset-menu";
|
|
39
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, _: N, event: DOMEventMetadata<N>, __: LayoutModule | null, DOMEvent: DOMEvent): void;
|
|
40
|
+
onDispose(this: PluginContext): void;
|
|
41
|
+
};
|
|
42
|
+
|
|
28
43
|
declare const presetColorPlugin: {
|
|
29
44
|
name: "treemap:preset-color";
|
|
30
45
|
onModuleInit(this: PluginContext, modules: LayoutModule[]): {
|
|
@@ -75,4 +90,4 @@ declare const presetZoomablePlugin: {
|
|
|
75
90
|
meta: ZoomableMetadata;
|
|
76
91
|
};
|
|
77
92
|
|
|
78
|
-
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
|
|
93
|
+
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetMenuPlugin, presetScalePlugin, presetZoomablePlugin };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -25,6 +25,21 @@ declare const presetDragElementPlugin: {
|
|
|
25
25
|
onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
interface MenuRenderConfig {
|
|
29
|
+
html: string;
|
|
30
|
+
action: string;
|
|
31
|
+
}
|
|
32
|
+
interface MenuPluginOptions {
|
|
33
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
34
|
+
render?: (menu: HTMLDivElement) => MenuRenderConfig[];
|
|
35
|
+
onClick?: (action: string, module: LayoutModule | null) => void;
|
|
36
|
+
}
|
|
37
|
+
declare function presetMenuPlugin(options?: MenuPluginOptions): {
|
|
38
|
+
name: "treemap:preset-menu";
|
|
39
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, _: N, event: DOMEventMetadata<N>, __: LayoutModule | null, DOMEvent: DOMEvent): void;
|
|
40
|
+
onDispose(this: PluginContext): void;
|
|
41
|
+
};
|
|
42
|
+
|
|
28
43
|
declare const presetColorPlugin: {
|
|
29
44
|
name: "treemap:preset-color";
|
|
30
45
|
onModuleInit(this: PluginContext, modules: LayoutModule[]): {
|
|
@@ -75,4 +90,4 @@ declare const presetZoomablePlugin: {
|
|
|
75
90
|
meta: ZoomableMetadata;
|
|
76
91
|
};
|
|
77
92
|
|
|
78
|
-
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
|
|
93
|
+
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetMenuPlugin, presetScalePlugin, presetZoomablePlugin };
|
package/dist/plugin.js
CHANGED
|
@@ -241,6 +241,72 @@ function getDragOptions() {
|
|
|
241
241
|
return meta;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
function presetMenuPlugin(options) {
|
|
245
|
+
let menu = null;
|
|
246
|
+
let domEvent$1 = null;
|
|
247
|
+
const handleMenuClick = (e)=>{
|
|
248
|
+
if (!domEvent$1) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (!menu) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const target = e.target;
|
|
255
|
+
if (target.parentNode) {
|
|
256
|
+
const parent = target.parentNode;
|
|
257
|
+
const action = parent.getAttribute('data-action');
|
|
258
|
+
if (!action) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (options?.onClick) {
|
|
262
|
+
options.onClick(action, domEvent$1.findRelativeNode({
|
|
263
|
+
native: e,
|
|
264
|
+
kind: undefined
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
menu.style.display = 'none';
|
|
269
|
+
};
|
|
270
|
+
return domEvent.definePlugin({
|
|
271
|
+
name: 'treemap:preset-menu',
|
|
272
|
+
onDOMEventTriggered (_, event, __, DOMEvent) {
|
|
273
|
+
if (domEvent.isContextMenuEvent(event)) {
|
|
274
|
+
event.native.stopPropagation();
|
|
275
|
+
event.native.preventDefault();
|
|
276
|
+
if (!menu) {
|
|
277
|
+
menu = document.createElement('div');
|
|
278
|
+
domEvent$1 = DOMEvent;
|
|
279
|
+
Object.assign(menu.style, {
|
|
280
|
+
backgroundColor: '#fff',
|
|
281
|
+
...options?.style,
|
|
282
|
+
position: 'absolute',
|
|
283
|
+
zIndex: '9999'
|
|
284
|
+
});
|
|
285
|
+
menu.addEventListener('click', handleMenuClick);
|
|
286
|
+
if (menu && options?.render) {
|
|
287
|
+
const result = options.render(menu);
|
|
288
|
+
menu.innerHTML = result.map((item)=>{
|
|
289
|
+
return `<div data-action='${item.action}'>${item.html}</div>`;
|
|
290
|
+
}).join('');
|
|
291
|
+
}
|
|
292
|
+
document.body.append(menu);
|
|
293
|
+
}
|
|
294
|
+
menu.style.left = event.native.clientX + 'px';
|
|
295
|
+
menu.style.top = event.native.clientY + 'px';
|
|
296
|
+
menu.style.display = 'initial';
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
onDispose () {
|
|
300
|
+
if (!menu) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
menu.removeEventListener('click', handleMenuClick);
|
|
304
|
+
menu = null;
|
|
305
|
+
domEvent$1 = null;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
244
310
|
const presetColorPlugin = domEvent.definePlugin({
|
|
245
311
|
name: 'treemap:preset-color',
|
|
246
312
|
onModuleInit (modules) {
|
|
@@ -334,7 +400,8 @@ function onWheel(pluginContext, event, { stateManager: state, component, matrix
|
|
|
334
400
|
return;
|
|
335
401
|
}
|
|
336
402
|
const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
|
|
337
|
-
const
|
|
403
|
+
const dynamicScaleFactor = Math.max(scaleFactor, scale * 0.1);
|
|
404
|
+
const delta = event.native.deltaY < 0 ? dynamicScaleFactor : -dynamicScaleFactor;
|
|
338
405
|
const newScale = Math.max(minScale, Math.min(maxScale, scale + delta));
|
|
339
406
|
if (newScale === scale) {
|
|
340
407
|
return;
|
|
@@ -474,5 +541,6 @@ const presetZoomablePlugin = domEvent.definePlugin({
|
|
|
474
541
|
exports.presetColorPlugin = presetColorPlugin;
|
|
475
542
|
exports.presetDragElementPlugin = presetDragElementPlugin;
|
|
476
543
|
exports.presetHighlightPlugin = presetHighlightPlugin;
|
|
544
|
+
exports.presetMenuPlugin = presetMenuPlugin;
|
|
477
545
|
exports.presetScalePlugin = presetScalePlugin;
|
|
478
546
|
exports.presetZoomablePlugin = presetZoomablePlugin;
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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, j as isContextMenuEvent, p as hashCode, P as PI_2, o as isWheelEvent, y as mixinWithParams } from './dom-event-BLJt9knO.mjs';
|
|
2
2
|
|
|
3
3
|
// Currently, etoile is an internal module, so we won't need too much easing functions.
|
|
4
4
|
// And the animation logic is implemented by user code.
|
|
@@ -239,6 +239,72 @@ function getDragOptions() {
|
|
|
239
239
|
return meta;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
+
function presetMenuPlugin(options) {
|
|
243
|
+
let menu = null;
|
|
244
|
+
let domEvent = null;
|
|
245
|
+
const handleMenuClick = (e)=>{
|
|
246
|
+
if (!domEvent) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!menu) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const target = e.target;
|
|
253
|
+
if (target.parentNode) {
|
|
254
|
+
const parent = target.parentNode;
|
|
255
|
+
const action = parent.getAttribute('data-action');
|
|
256
|
+
if (!action) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (options?.onClick) {
|
|
260
|
+
options.onClick(action, domEvent.findRelativeNode({
|
|
261
|
+
native: e,
|
|
262
|
+
kind: undefined
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
menu.style.display = 'none';
|
|
267
|
+
};
|
|
268
|
+
return definePlugin({
|
|
269
|
+
name: 'treemap:preset-menu',
|
|
270
|
+
onDOMEventTriggered (_, event, __, DOMEvent) {
|
|
271
|
+
if (isContextMenuEvent(event)) {
|
|
272
|
+
event.native.stopPropagation();
|
|
273
|
+
event.native.preventDefault();
|
|
274
|
+
if (!menu) {
|
|
275
|
+
menu = document.createElement('div');
|
|
276
|
+
domEvent = DOMEvent;
|
|
277
|
+
Object.assign(menu.style, {
|
|
278
|
+
backgroundColor: '#fff',
|
|
279
|
+
...options?.style,
|
|
280
|
+
position: 'absolute',
|
|
281
|
+
zIndex: '9999'
|
|
282
|
+
});
|
|
283
|
+
menu.addEventListener('click', handleMenuClick);
|
|
284
|
+
if (menu && options?.render) {
|
|
285
|
+
const result = options.render(menu);
|
|
286
|
+
menu.innerHTML = result.map((item)=>{
|
|
287
|
+
return `<div data-action='${item.action}'>${item.html}</div>`;
|
|
288
|
+
}).join('');
|
|
289
|
+
}
|
|
290
|
+
document.body.append(menu);
|
|
291
|
+
}
|
|
292
|
+
menu.style.left = event.native.clientX + 'px';
|
|
293
|
+
menu.style.top = event.native.clientY + 'px';
|
|
294
|
+
menu.style.display = 'initial';
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
onDispose () {
|
|
298
|
+
if (!menu) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
menu.removeEventListener('click', handleMenuClick);
|
|
302
|
+
menu = null;
|
|
303
|
+
domEvent = null;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
242
308
|
const presetColorPlugin = definePlugin({
|
|
243
309
|
name: 'treemap:preset-color',
|
|
244
310
|
onModuleInit (modules) {
|
|
@@ -332,7 +398,8 @@ function onWheel(pluginContext, event, { stateManager: state, component, matrix
|
|
|
332
398
|
return;
|
|
333
399
|
}
|
|
334
400
|
const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
|
|
335
|
-
const
|
|
401
|
+
const dynamicScaleFactor = Math.max(scaleFactor, scale * 0.1);
|
|
402
|
+
const delta = event.native.deltaY < 0 ? dynamicScaleFactor : -dynamicScaleFactor;
|
|
336
403
|
const newScale = Math.max(minScale, Math.min(maxScale, scale + delta));
|
|
337
404
|
if (newScale === scale) {
|
|
338
405
|
return;
|
|
@@ -469,4 +536,4 @@ const presetZoomablePlugin = definePlugin({
|
|
|
469
536
|
}
|
|
470
537
|
});
|
|
471
538
|
|
|
472
|
-
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
|
|
539
|
+
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetMenuPlugin, presetScalePlugin, presetZoomablePlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squarified",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "squarified tree map",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"author": "Kanno",
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@microsoft/api-extractor": "^7.52.3",
|
|
38
37
|
"@swc/core": "^1.11.29",
|
|
39
38
|
"@types/markdown-it": "^14.1.2",
|
|
40
39
|
"@types/node": "^22.7.4",
|
|
@@ -57,7 +56,7 @@
|
|
|
57
56
|
"tinyglobby": "^0.2.13",
|
|
58
57
|
"tsx": "^4.19.2",
|
|
59
58
|
"typescript": "^5.7.3",
|
|
60
|
-
"vite-bundle-analyzer": "^0.
|
|
59
|
+
"vite-bundle-analyzer": "^0.22.0"
|
|
61
60
|
},
|
|
62
61
|
"pnpm": {
|
|
63
62
|
"overrides": {
|