squarified 0.5.0 → 0.6.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 +235 -10
- package/dist/index.d.mts +352 -1
- package/dist/index.d.ts +352 -1
- package/dist/index.js +1953 -82
- package/dist/index.mjs +1940 -51
- package/package.json +2 -2
- package/dist/dom-event-Bkw3ecGf.mjs +0 -1648
- package/dist/dom-event-Dz0I7Z12.js +0 -1688
- package/dist/index-Dskgz6nc.d.ts +0 -521
- package/dist/plugin.d.mts +0 -103
- package/dist/plugin.d.ts +0 -103
- package/dist/plugin.js +0 -643
- package/dist/plugin.mjs +0 -636
package/README.md
CHANGED
|
@@ -1,25 +1,250 @@
|
|
|
1
1
|
# Squarified
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A minimal and powerful treemap visualization library for creating interactive hierarchical data visualizations.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Lightweight**: Minimal bundle size with maximum performance
|
|
8
|
+
- 🎨 **Customizable**: Rich theming and styling options
|
|
9
|
+
- 🔌 **Plugin System**: Extensible architecture with built-in plugins
|
|
10
|
+
- 📱 **Responsive**: Automatic resizing
|
|
11
|
+
- ⚡ **Interactive**: Built-in zoom, drag, highlight, and menu interactions
|
|
12
|
+
- 🎯 **TypeScript**: Full type safety and excellent DX
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
6
15
|
|
|
7
16
|
```shell
|
|
8
|
-
|
|
17
|
+
npm install squarified
|
|
18
|
+
# or
|
|
19
|
+
yarn add squarified
|
|
20
|
+
# or
|
|
21
|
+
pnpm add squarified
|
|
9
22
|
```
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
## Quick Start
|
|
12
25
|
|
|
13
|
-
|
|
26
|
+
```typescript
|
|
27
|
+
import { c2m, createTreemap, sortChildrenByKey } from 'squarified'
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
// Create a treemap instance
|
|
30
|
+
const treemap = createTreemap({
|
|
31
|
+
plugins: [
|
|
32
|
+
// Add built-in plugins for interactions
|
|
33
|
+
]
|
|
34
|
+
})
|
|
16
35
|
|
|
17
|
-
|
|
36
|
+
// Initialize with a DOM element
|
|
37
|
+
const container = document.querySelector('#treemap-container')
|
|
38
|
+
treemap.init(container)
|
|
39
|
+
|
|
40
|
+
// Set your data
|
|
41
|
+
treemap.setOptions({
|
|
42
|
+
data: [
|
|
43
|
+
{
|
|
44
|
+
id: 'root',
|
|
45
|
+
label: 'Root',
|
|
46
|
+
weight: 100,
|
|
47
|
+
groups: [
|
|
48
|
+
{ id: 'child1', label: 'Child 1', weight: 60 },
|
|
49
|
+
{ id: 'child2', label: 'Child 2', weight: 40 }
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Complete Example
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import {
|
|
60
|
+
c2m,
|
|
61
|
+
createTreemap,
|
|
62
|
+
presetColorPlugin,
|
|
63
|
+
presetDragElementPlugin,
|
|
64
|
+
presetHighlightPlugin,
|
|
65
|
+
presetMenuPlugin,
|
|
66
|
+
presetScalePlugin,
|
|
67
|
+
presetZoomablePlugin,
|
|
68
|
+
sortChildrenByKey
|
|
69
|
+
} from 'squarified'
|
|
70
|
+
|
|
71
|
+
// Create treemap with plugins
|
|
72
|
+
const treemap = createTreemap({
|
|
73
|
+
plugins: [
|
|
74
|
+
presetColorPlugin,
|
|
75
|
+
presetZoomablePlugin,
|
|
76
|
+
presetHighlightPlugin,
|
|
77
|
+
presetDragElementPlugin,
|
|
78
|
+
presetScalePlugin(),
|
|
79
|
+
presetMenuPlugin({
|
|
80
|
+
style: {
|
|
81
|
+
borderRadius: '5px',
|
|
82
|
+
padding: '6px 12px',
|
|
83
|
+
backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
84
|
+
color: 'white',
|
|
85
|
+
cursor: 'pointer',
|
|
86
|
+
userSelect: 'none'
|
|
87
|
+
},
|
|
88
|
+
render: () => [
|
|
89
|
+
{ html: '<span>🔍 Zoom In</span>', action: 'zoom' },
|
|
90
|
+
{ html: '<span>🔄 Reset</span>', action: 'reset' }
|
|
91
|
+
],
|
|
92
|
+
onClick(action, module) {
|
|
93
|
+
switch (action) {
|
|
94
|
+
case 'zoom':
|
|
95
|
+
if (module?.node.id) {
|
|
96
|
+
treemap.zoom(module.node.id)
|
|
97
|
+
}
|
|
98
|
+
break
|
|
99
|
+
case 'reset':
|
|
100
|
+
treemap.resize()
|
|
101
|
+
break
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// Convert and prepare data
|
|
109
|
+
async function loadData() {
|
|
110
|
+
const response = await fetch('/api/data')
|
|
111
|
+
const rawData = await response.json()
|
|
112
|
+
|
|
113
|
+
// Transform data structure
|
|
114
|
+
const convertedData = rawData.map((item) => ({
|
|
115
|
+
...item,
|
|
116
|
+
groups: item.children?.map((child) => convertChildrenToGroups(child))
|
|
117
|
+
}))
|
|
118
|
+
|
|
119
|
+
// Convert to treemap format and sort
|
|
120
|
+
const treemapData = sortChildrenByKey(
|
|
121
|
+
convertedData.map((item) =>
|
|
122
|
+
c2m(item, 'value', (d) => ({
|
|
123
|
+
...d,
|
|
124
|
+
id: d.path,
|
|
125
|
+
label: d.name
|
|
126
|
+
}))
|
|
127
|
+
),
|
|
128
|
+
'weight'
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
return treemapData
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Initialize
|
|
135
|
+
const container = document.querySelector('#app')
|
|
136
|
+
treemap.init(container)
|
|
137
|
+
|
|
138
|
+
// Load and set data
|
|
139
|
+
loadData().then((data) => {
|
|
140
|
+
treemap.setOptions({ data })
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// Handle events
|
|
144
|
+
treemap.on('click', (event, module) => {
|
|
145
|
+
console.log('Clicked:', module?.node)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
// Auto-resize on container changes
|
|
149
|
+
new ResizeObserver(() => {
|
|
150
|
+
treemap.resize()
|
|
151
|
+
}).observe(container)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## API Reference
|
|
155
|
+
|
|
156
|
+
### Creating a Treemap
|
|
157
|
+
|
|
158
|
+
#### `createTreemap(options?)`
|
|
159
|
+
|
|
160
|
+
Creates a new treemap instance.
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
interface CreateTreemapOptions {
|
|
164
|
+
plugins?: Plugin[]
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Instance Methods
|
|
169
|
+
|
|
170
|
+
#### `init(element: HTMLElement)`
|
|
171
|
+
|
|
172
|
+
Initialize the treemap with a DOM container.
|
|
173
|
+
|
|
174
|
+
#### `setOptions(options: TreemapOptions)`
|
|
18
175
|
|
|
19
|
-
|
|
176
|
+
Update treemap configuration and data.
|
|
20
177
|
|
|
21
|
-
|
|
178
|
+
#### `resize()`
|
|
22
179
|
|
|
23
|
-
|
|
180
|
+
Manually trigger a resize recalculation.
|
|
181
|
+
|
|
182
|
+
#### `on(event: string, handler: Function)`
|
|
183
|
+
|
|
184
|
+
Subscribe to treemap events.
|
|
185
|
+
|
|
186
|
+
#### `dispose()`
|
|
187
|
+
|
|
188
|
+
Clean up the treemap instance.
|
|
189
|
+
|
|
190
|
+
### Data Format
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
interface TreemapNode {
|
|
194
|
+
id: string
|
|
195
|
+
label: string
|
|
196
|
+
weight: number
|
|
197
|
+
groups?: TreemapNode[]
|
|
198
|
+
// Custom properties...
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Utility Functions
|
|
203
|
+
|
|
204
|
+
#### `c2m(data, weightKey, transform?)`
|
|
205
|
+
|
|
206
|
+
Convert hierarchical data to treemap format.
|
|
207
|
+
|
|
208
|
+
#### `sortChildrenByKey(data, key)`
|
|
209
|
+
|
|
210
|
+
Sort treemap nodes by a specific key.
|
|
211
|
+
|
|
212
|
+
## Built-in Plugins
|
|
213
|
+
|
|
214
|
+
- **presetColorPlugin**: Automatic color assignment
|
|
215
|
+
- **presetZoomablePlugin**: Zoom interactions
|
|
216
|
+
- **presetHighlightPlugin**: Hover highlighting
|
|
217
|
+
- **presetDragElementPlugin**: Drag interactions
|
|
218
|
+
- **presetScalePlugin**: Scaling controls
|
|
219
|
+
- **presetMenuPlugin**: Context menus
|
|
220
|
+
|
|
221
|
+
## Browser Support
|
|
222
|
+
|
|
223
|
+
- Chrome/Edge 80+
|
|
224
|
+
- Firefox 75+
|
|
225
|
+
- Safari 13+
|
|
226
|
+
|
|
227
|
+
## Performance
|
|
228
|
+
|
|
229
|
+
Squarified is optimized for performance with:
|
|
230
|
+
|
|
231
|
+
- Canvas-based rendering
|
|
232
|
+
- Efficient layout algorithms
|
|
233
|
+
- Smart redraw optimizations
|
|
234
|
+
- Memory-conscious design
|
|
235
|
+
|
|
236
|
+
## Contributing
|
|
237
|
+
|
|
238
|
+
Contributions are welcome! Please read our [contributing guide](CONTRIBUTING.md) for details.
|
|
239
|
+
|
|
240
|
+
## License
|
|
24
241
|
|
|
25
242
|
[MIT](./LICENSE)
|
|
243
|
+
|
|
244
|
+
## Auth
|
|
245
|
+
|
|
246
|
+
Kanno
|
|
247
|
+
|
|
248
|
+
## Credits
|
|
249
|
+
|
|
250
|
+
Algorithm ported from [esbuild Bundle Size Analyzer](https://esbuild.github.io/analyze/) by [Evan Wallace](https://github.com/evanw), refactored and optimized for general-purpose treemap visualization.
|
package/dist/index.d.mts
CHANGED
|
@@ -1 +1,352 @@
|
|
|
1
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
type Any = any
|
|
3
|
+
|
|
4
|
+
type AnyObject = Record<keyof Any, Any>
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
interface MatrixLoc {
|
|
8
|
+
a: number;
|
|
9
|
+
b: number;
|
|
10
|
+
c: number;
|
|
11
|
+
d: number;
|
|
12
|
+
e: number;
|
|
13
|
+
f: number;
|
|
14
|
+
}
|
|
15
|
+
declare class Matrix2D implements MatrixLoc {
|
|
16
|
+
a: number;
|
|
17
|
+
b: number;
|
|
18
|
+
c: number;
|
|
19
|
+
d: number;
|
|
20
|
+
e: number;
|
|
21
|
+
f: number;
|
|
22
|
+
constructor(loc?: Partial<MatrixLoc>);
|
|
23
|
+
create(loc: MatrixLoc): this;
|
|
24
|
+
transform(x: number, y: number, scaleX: number, scaleY: number, rotation: number, skewX: number, skewY: number): this;
|
|
25
|
+
translation(x: number, y: number): this;
|
|
26
|
+
scale(a: number, d: number): this;
|
|
27
|
+
private skew;
|
|
28
|
+
private roate;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare const enum DisplayType {
|
|
32
|
+
Graph = "Graph",
|
|
33
|
+
Box = "Box",
|
|
34
|
+
Text = "Text",
|
|
35
|
+
RoundRect = "RoundRect",
|
|
36
|
+
Bitmap = "Bitmap"
|
|
37
|
+
}
|
|
38
|
+
declare abstract class Display {
|
|
39
|
+
parent: Display | null;
|
|
40
|
+
id: number;
|
|
41
|
+
matrix: Matrix2D;
|
|
42
|
+
abstract get __instanceOf__(): DisplayType;
|
|
43
|
+
constructor();
|
|
44
|
+
destory(): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare abstract class C extends Display {
|
|
48
|
+
elements: Display[];
|
|
49
|
+
constructor();
|
|
50
|
+
abstract get __instanceOf__(): DisplayType;
|
|
51
|
+
add(...elements: Display[]): void;
|
|
52
|
+
remove(...elements: Display[]): void;
|
|
53
|
+
destory(): void;
|
|
54
|
+
}
|
|
55
|
+
declare class Box extends C {
|
|
56
|
+
elements: Display[];
|
|
57
|
+
constructor();
|
|
58
|
+
add(...elements: Display[]): void;
|
|
59
|
+
remove(...elements: Display[]): void;
|
|
60
|
+
destory(): void;
|
|
61
|
+
get __instanceOf__(): DisplayType.Box;
|
|
62
|
+
clone(): Box;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface RGBColor {
|
|
66
|
+
r: number;
|
|
67
|
+
g: number;
|
|
68
|
+
b: number;
|
|
69
|
+
a?: number;
|
|
70
|
+
}
|
|
71
|
+
interface HLSColor {
|
|
72
|
+
h: number;
|
|
73
|
+
l: number;
|
|
74
|
+
s: number;
|
|
75
|
+
a?: number;
|
|
76
|
+
}
|
|
77
|
+
interface ColorDecoratorResultHLS {
|
|
78
|
+
mode?: 'hsl';
|
|
79
|
+
desc: HLSColor;
|
|
80
|
+
}
|
|
81
|
+
interface ColorDecoratorResultRGB {
|
|
82
|
+
mode: 'rgb';
|
|
83
|
+
desc: RGBColor;
|
|
84
|
+
}
|
|
85
|
+
type ColorDecoratorResult = ColorDecoratorResultHLS | ColorDecoratorResultRGB;
|
|
86
|
+
|
|
87
|
+
type EventCallback<P = Any[]> = P extends Any[] ? (...args: P) => Any : never;
|
|
88
|
+
type DefaultEventDefinition = Record<string, EventCallback>;
|
|
89
|
+
type BindThisParameter<T, C = unknown> = T extends (...args: infer P) => infer R ? (this: C, ...args: P) => R : never;
|
|
90
|
+
interface EventCollectionData<EvtDefinition extends DefaultEventDefinition, C = unknown> {
|
|
91
|
+
name: string;
|
|
92
|
+
handler: BindThisParameter<EvtDefinition[keyof EvtDefinition], C>;
|
|
93
|
+
ctx: C;
|
|
94
|
+
silent: boolean;
|
|
95
|
+
}
|
|
96
|
+
type EventCollections<EvtDefinition extends DefaultEventDefinition> = Record<keyof EvtDefinition, EventCollectionData<EvtDefinition>[]>;
|
|
97
|
+
declare class Event<EvtDefinition extends DefaultEventDefinition = DefaultEventDefinition> {
|
|
98
|
+
eventCollections: EventCollections<EvtDefinition>;
|
|
99
|
+
constructor();
|
|
100
|
+
on<C, Evt extends keyof EvtDefinition>(evt: Evt, handler: BindThisParameter<EvtDefinition[Evt], unknown extends C ? this : C>, c?: C): void;
|
|
101
|
+
off(evt: keyof EvtDefinition, handler?: BindThisParameter<EvtDefinition[keyof EvtDefinition], unknown>): void;
|
|
102
|
+
silent(evt: keyof EvtDefinition, handler?: BindThisParameter<EvtDefinition[keyof EvtDefinition], unknown>): void;
|
|
103
|
+
active(evt: keyof EvtDefinition, handler?: BindThisParameter<EvtDefinition[keyof EvtDefinition], unknown>): void;
|
|
104
|
+
emit(evt: keyof EvtDefinition, ...args: Parameters<EvtDefinition[keyof EvtDefinition]>): void;
|
|
105
|
+
bindWithContext<C>(c: C): (evt: keyof EvtDefinition, handler: BindThisParameter<EvtDefinition[keyof EvtDefinition], unknown extends C ? this : C>) => void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface RenderViewportOptions {
|
|
109
|
+
width: number;
|
|
110
|
+
height: number;
|
|
111
|
+
devicePixelRatio: number;
|
|
112
|
+
shaow?: boolean;
|
|
113
|
+
}
|
|
114
|
+
declare class Canvas {
|
|
115
|
+
canvas: HTMLCanvasElement;
|
|
116
|
+
ctx: CanvasRenderingContext2D;
|
|
117
|
+
constructor(options: RenderViewportOptions);
|
|
118
|
+
setOptions(options: RenderViewportOptions): void;
|
|
119
|
+
}
|
|
120
|
+
declare class Render {
|
|
121
|
+
options: RenderViewportOptions;
|
|
122
|
+
private container;
|
|
123
|
+
constructor(to: HTMLElement, options: RenderViewportOptions);
|
|
124
|
+
clear(width: number, height: number): void;
|
|
125
|
+
get canvas(): HTMLCanvasElement;
|
|
126
|
+
get ctx(): CanvasRenderingContext2D;
|
|
127
|
+
initOptions(userOptions?: Partial<RenderViewportOptions>): void;
|
|
128
|
+
destory(): void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type ApplyTo = string | HTMLElement;
|
|
132
|
+
declare class Schedule<D extends DefaultEventDefinition = DefaultEventDefinition> extends Box {
|
|
133
|
+
render: Render;
|
|
134
|
+
to: HTMLElement;
|
|
135
|
+
event: Event<D>;
|
|
136
|
+
constructor(to: ApplyTo, renderOptions?: Partial<RenderViewportOptions>);
|
|
137
|
+
update(): void;
|
|
138
|
+
execute(render: Render, graph?: Display): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
declare const DOM_EVENTS: readonly ["click", "mousedown", "mousemove", "mouseup", "mouseover", "mouseout", "wheel"];
|
|
142
|
+
type DOMEventType = typeof DOM_EVENTS[number];
|
|
143
|
+
interface DOMLoc {
|
|
144
|
+
x: number;
|
|
145
|
+
y: number;
|
|
146
|
+
}
|
|
147
|
+
interface DOMEventMetadata<T extends keyof HTMLElementEventMap = Any> {
|
|
148
|
+
native: HTMLElementEventMap[T];
|
|
149
|
+
loc: DOMLoc;
|
|
150
|
+
}
|
|
151
|
+
type DOMEventCallback<T extends DOMEventType> = (metadata: DOMEventMetadata<T>) => void;
|
|
152
|
+
type DOMEventDefinition<API = unknown> = {
|
|
153
|
+
[K in DOMEventType]: BindThisParameter<DOMEventCallback<K>, API>;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
declare abstract class Cache {
|
|
157
|
+
abstract key: string;
|
|
158
|
+
abstract get state(): boolean;
|
|
159
|
+
abstract flush(...args: never): void;
|
|
160
|
+
abstract destroy(): void;
|
|
161
|
+
}
|
|
162
|
+
declare class RenderCache extends Canvas implements Cache {
|
|
163
|
+
key: string;
|
|
164
|
+
private $memory;
|
|
165
|
+
constructor(opts: RenderViewportOptions);
|
|
166
|
+
get state(): boolean;
|
|
167
|
+
flush(treemap: TreemapLayout, matrix?: Matrix2D): void;
|
|
168
|
+
destroy(): void;
|
|
169
|
+
}
|
|
170
|
+
declare class FontCache implements Cache {
|
|
171
|
+
key: string;
|
|
172
|
+
private fonts;
|
|
173
|
+
ellispsis: Record<string, number>;
|
|
174
|
+
constructor();
|
|
175
|
+
get state(): boolean;
|
|
176
|
+
flush(treemap: TreemapLayout, matrix?: Matrix2D): void;
|
|
177
|
+
destroy(): void;
|
|
178
|
+
queryFontById(id: string, byDefault: () => number): number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type ColorMappings = Record<string, ColorDecoratorResult>;
|
|
182
|
+
type Rect = {
|
|
183
|
+
w: number;
|
|
184
|
+
h: number;
|
|
185
|
+
};
|
|
186
|
+
type Series<T> = {
|
|
187
|
+
max: T;
|
|
188
|
+
min: T;
|
|
189
|
+
};
|
|
190
|
+
interface RenderColor {
|
|
191
|
+
mappings: ColorMappings;
|
|
192
|
+
}
|
|
193
|
+
interface RenderLayout {
|
|
194
|
+
titleAreaHeight: Series<number>;
|
|
195
|
+
rectBorderRadius: number;
|
|
196
|
+
rectBorderWidth: number;
|
|
197
|
+
rectGap: number;
|
|
198
|
+
}
|
|
199
|
+
interface RenderFont {
|
|
200
|
+
color: string;
|
|
201
|
+
fontSize: Series<number>;
|
|
202
|
+
fontFamily: string;
|
|
203
|
+
}
|
|
204
|
+
interface RenderDecorator {
|
|
205
|
+
color: RenderColor;
|
|
206
|
+
layout: RenderLayout;
|
|
207
|
+
font: RenderFont;
|
|
208
|
+
}
|
|
209
|
+
declare const defaultLayoutOptions: {
|
|
210
|
+
titleAreaHeight: {
|
|
211
|
+
max: number;
|
|
212
|
+
min: number;
|
|
213
|
+
};
|
|
214
|
+
rectGap: number;
|
|
215
|
+
rectBorderRadius: number;
|
|
216
|
+
rectBorderWidth: number;
|
|
217
|
+
};
|
|
218
|
+
declare const defaultFontOptions: {
|
|
219
|
+
color: string;
|
|
220
|
+
fontSize: {
|
|
221
|
+
max: number;
|
|
222
|
+
min: number;
|
|
223
|
+
};
|
|
224
|
+
fontFamily: string;
|
|
225
|
+
};
|
|
226
|
+
declare function presetDecorator(app: TreemapLayout): void;
|
|
227
|
+
|
|
228
|
+
declare function sortChildrenByKey<T extends AnyObject, K extends keyof T = 'weight'>(data: T[], ...keys: K[]): T[];
|
|
229
|
+
declare function c2m<T extends AnyObject & {
|
|
230
|
+
groups: Any[];
|
|
231
|
+
}, K extends keyof T>(data: T, key: K, modifier?: (data: T) => T): T & {
|
|
232
|
+
weight: number;
|
|
233
|
+
};
|
|
234
|
+
declare function flatten<T extends AnyObject & {
|
|
235
|
+
groups: T[];
|
|
236
|
+
}>(data: T[]): Omit<T, "groups">[];
|
|
237
|
+
type Module = ReturnType<typeof c2m>;
|
|
238
|
+
declare function bindParentForModule<T extends Module & {
|
|
239
|
+
parent: Module;
|
|
240
|
+
}>(modules: Module[], parent?: Module): T[];
|
|
241
|
+
type NativeModule = ReturnType<typeof bindParentForModule>[number] & {
|
|
242
|
+
id: string;
|
|
243
|
+
parent: NativeModule;
|
|
244
|
+
groups: NativeModule[];
|
|
245
|
+
};
|
|
246
|
+
declare function getNodeDepth(node: NativeModule): number;
|
|
247
|
+
declare function visit<T extends AnyObject>(data: T[], fn: (data: T) => boolean | void): T | null;
|
|
248
|
+
declare function findRelativeNode(p: {
|
|
249
|
+
x: number;
|
|
250
|
+
y: number;
|
|
251
|
+
}, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
252
|
+
declare function findRelativeNodeById(id: string, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
253
|
+
|
|
254
|
+
type LayoutModule = {
|
|
255
|
+
node: NativeModule;
|
|
256
|
+
layout: [number, number, number, number];
|
|
257
|
+
children: LayoutModule[];
|
|
258
|
+
decorator: {
|
|
259
|
+
titleHeight: number;
|
|
260
|
+
rectBorderRadius: number;
|
|
261
|
+
rectGap: number;
|
|
262
|
+
rectBorderWidth: number;
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
interface PrimitiveEventMetadata<T extends keyof HTMLElementEventMap> {
|
|
267
|
+
native: HTMLElementEventMap[T];
|
|
268
|
+
module: LayoutModule | null;
|
|
269
|
+
}
|
|
270
|
+
type ExposedEventCallback<T extends DOMEventType> = (metadata: PrimitiveEventMetadata<T>) => void;
|
|
271
|
+
type ExposedEventDefinition = {
|
|
272
|
+
[K in DOMEventType]: BindThisParameter<ExposedEventCallback<K>, TreemapInstanceAPI>;
|
|
273
|
+
};
|
|
274
|
+
interface ExposedEventMethods<C = TreemapInstanceAPI, D = ExposedEventDefinition> {
|
|
275
|
+
on<Evt extends keyof D>(evt: Evt, handler: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
276
|
+
off<Evt extends keyof D>(evt: keyof D, handler?: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
277
|
+
}
|
|
278
|
+
declare const INTERNAL_EVENT_MAPPINGS: {
|
|
279
|
+
readonly ON_ZOOM: 1;
|
|
280
|
+
readonly ON_CLEANUP: 3;
|
|
281
|
+
};
|
|
282
|
+
type InternalEventType = typeof INTERNAL_EVENT_MAPPINGS[keyof typeof INTERNAL_EVENT_MAPPINGS];
|
|
283
|
+
interface InternalEventMappings {
|
|
284
|
+
[INTERNAL_EVENT_MAPPINGS.ON_ZOOM]: (node: LayoutModule) => void;
|
|
285
|
+
[INTERNAL_EVENT_MAPPINGS.ON_CLEANUP]: () => void;
|
|
286
|
+
}
|
|
287
|
+
type InternalEventDefinition = {
|
|
288
|
+
[key in InternalEventType]: InternalEventMappings[key];
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
interface TreemapOptions {
|
|
292
|
+
data: Module[];
|
|
293
|
+
}
|
|
294
|
+
type UseKind = 'decorator';
|
|
295
|
+
interface App {
|
|
296
|
+
init: (el: HTMLElement) => void;
|
|
297
|
+
dispose: () => void;
|
|
298
|
+
setOptions: (options: TreemapOptions) => void;
|
|
299
|
+
resize: () => void;
|
|
300
|
+
use: (using: UseKind, register: (app: TreemapLayout) => void) => void;
|
|
301
|
+
zoom: (id: string) => void;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* This interface isn't stable it might be remove at next few versions.
|
|
305
|
+
* If you want set custom decorator pls see 'presetDecorator' for details.
|
|
306
|
+
*/
|
|
307
|
+
type unstable_use = (app: TreemapLayout) => void;
|
|
308
|
+
declare class Highlight extends Schedule<DOMEventDefinition> {
|
|
309
|
+
reset(): void;
|
|
310
|
+
get canvas(): HTMLCanvasElement;
|
|
311
|
+
setZIndexForHighlight(zIndex?: string): void;
|
|
312
|
+
init(): void;
|
|
313
|
+
}
|
|
314
|
+
declare class TreemapLayout extends Schedule<InternalEventDefinition> {
|
|
315
|
+
data: NativeModule[];
|
|
316
|
+
layoutNodes: LayoutModule[];
|
|
317
|
+
decorator: RenderDecorator;
|
|
318
|
+
bgBox: Box;
|
|
319
|
+
fgBox: Box;
|
|
320
|
+
highlight: Highlight;
|
|
321
|
+
renderCache: RenderCache;
|
|
322
|
+
fontCache: FontCache;
|
|
323
|
+
constructor(...args: ConstructorParameters<typeof Schedule>);
|
|
324
|
+
drawBackgroundNode(node: LayoutModule): void;
|
|
325
|
+
drawForegroundNode(node: LayoutModule): void;
|
|
326
|
+
reset(refresh?: boolean): void;
|
|
327
|
+
get api(): {
|
|
328
|
+
zoom: (node: LayoutModule | null) => void;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
declare function createTreemap(): App & ExposedEventMethods;
|
|
332
|
+
type TreemapInstanceAPI = TreemapLayout['api'];
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @deprecated compat `PrimitiveEvent` using `DOMEventType` replace it. (will be removed in the next three versions.)
|
|
336
|
+
*/
|
|
337
|
+
type PrimitiveEvent = DOMEventType;
|
|
338
|
+
/**
|
|
339
|
+
* @deprecated compat `EventMethods` using `ExposedEventMethods` replace it. (will be removed in the next three versions.)
|
|
340
|
+
*/
|
|
341
|
+
type EventMethods = ExposedEventMethods;
|
|
342
|
+
/**
|
|
343
|
+
* @deprecated compat `PrimitiveEventCallback` using `ExposedEventCallback` replace it. (will be removed in the next three versions.)
|
|
344
|
+
*/
|
|
345
|
+
type PrimitiveEventCallback<T extends PrimitiveEvent> = ExposedEventCallback<T>;
|
|
346
|
+
/**
|
|
347
|
+
* @deprecated compat `PrimitiveEventDefinition` using `ExposedEventDefinition` replace it. (will be removed in the next three versions.)
|
|
348
|
+
*/
|
|
349
|
+
type PrimitiveEventDefinition = ExposedEventDefinition;
|
|
350
|
+
|
|
351
|
+
export { TreemapLayout, c2m, createTreemap, defaultFontOptions, defaultLayoutOptions, findRelativeNode, findRelativeNodeById, flatten as flattenModule, getNodeDepth, presetDecorator, sortChildrenByKey, visit };
|
|
352
|
+
export type { App, ColorMappings, DOMEventType, EventMethods, ExposedEventCallback, ExposedEventDefinition, ExposedEventMethods, LayoutModule, Module, NativeModule, PrimitiveEvent, PrimitiveEventCallback, PrimitiveEventDefinition, PrimitiveEventMetadata, Rect, RenderColor, RenderDecorator, RenderFont, RenderLayout, Series, TreemapInstanceAPI, TreemapOptions, unstable_use };
|