squarified 0.1.0 → 0.1.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/index.d.mts +314 -0
- package/dist/index.d.ts +34 -3
- package/dist/index.js +1252 -1285
- package/dist/index.mjs +1248 -1286
- package/package.json +9 -13
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
interface MatrixLoc {
|
|
2
|
+
a: number;
|
|
3
|
+
b: number;
|
|
4
|
+
c: number;
|
|
5
|
+
d: number;
|
|
6
|
+
e: number;
|
|
7
|
+
f: number;
|
|
8
|
+
}
|
|
9
|
+
declare class Matrix2D {
|
|
10
|
+
a: number;
|
|
11
|
+
b: number;
|
|
12
|
+
c: number;
|
|
13
|
+
d: number;
|
|
14
|
+
e: number;
|
|
15
|
+
f: number;
|
|
16
|
+
constructor(loc?: Partial<MatrixLoc>);
|
|
17
|
+
create(loc: MatrixLoc): this;
|
|
18
|
+
transform(x: number, y: number, scaleX: number, scaleY: number, rotation: number, skewX: number, skewY: number): this;
|
|
19
|
+
private translation;
|
|
20
|
+
private scale;
|
|
21
|
+
private skew;
|
|
22
|
+
private roate;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const enum DisplayType {
|
|
26
|
+
Graph = "Graph",
|
|
27
|
+
Box = "Box",
|
|
28
|
+
Rect = "Rect",
|
|
29
|
+
Text = "Text"
|
|
30
|
+
}
|
|
31
|
+
declare abstract class Display {
|
|
32
|
+
parent: Display | null;
|
|
33
|
+
id: number;
|
|
34
|
+
matrix: Matrix2D;
|
|
35
|
+
abstract get __instanceOf__(): string;
|
|
36
|
+
constructor();
|
|
37
|
+
destory(): void;
|
|
38
|
+
}
|
|
39
|
+
interface GraphStyleSheet {
|
|
40
|
+
stroke: string;
|
|
41
|
+
opacity: number;
|
|
42
|
+
font: string;
|
|
43
|
+
lineWidth: number;
|
|
44
|
+
}
|
|
45
|
+
interface LocOptions {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
scaleX: number;
|
|
51
|
+
scaleY: number;
|
|
52
|
+
rotation: number;
|
|
53
|
+
skewX: number;
|
|
54
|
+
skewY: number;
|
|
55
|
+
}
|
|
56
|
+
interface GraphOptions extends LocOptions {
|
|
57
|
+
}
|
|
58
|
+
type Mod = [string, ...any[]];
|
|
59
|
+
interface Instruction {
|
|
60
|
+
mods: Mod[];
|
|
61
|
+
fillStyle(...args: any[]): void;
|
|
62
|
+
fillRect(...args: any[]): void;
|
|
63
|
+
strokeStyle(...args: any[]): void;
|
|
64
|
+
lineWidth(...args: any[]): void;
|
|
65
|
+
strokeRect(...args: any[]): void;
|
|
66
|
+
fillText(...args: any[]): void;
|
|
67
|
+
font(...args: any[]): void;
|
|
68
|
+
textBaseline(...args: any[]): void;
|
|
69
|
+
textAlign(...args: any[]): void;
|
|
70
|
+
}
|
|
71
|
+
declare function createInstruction(): Instruction;
|
|
72
|
+
declare abstract class S extends Display {
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
scaleX: number;
|
|
78
|
+
scaleY: number;
|
|
79
|
+
rotation: number;
|
|
80
|
+
skewX: number;
|
|
81
|
+
skewY: number;
|
|
82
|
+
constructor(options?: Partial<LocOptions>);
|
|
83
|
+
}
|
|
84
|
+
declare abstract class Graph extends S {
|
|
85
|
+
instruction: ReturnType<typeof createInstruction>;
|
|
86
|
+
__refresh__: boolean;
|
|
87
|
+
__options__: Partial<LocOptions>;
|
|
88
|
+
abstract style: GraphStyleSheet;
|
|
89
|
+
constructor(options?: Partial<GraphOptions>);
|
|
90
|
+
abstract create(): void;
|
|
91
|
+
abstract clone(): Graph;
|
|
92
|
+
abstract get __shape__(): string;
|
|
93
|
+
render(ctx: CanvasRenderingContext2D): void;
|
|
94
|
+
get __instanceOf__(): DisplayType.Graph;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
declare class Box extends Display {
|
|
98
|
+
elements: Display[];
|
|
99
|
+
constructor();
|
|
100
|
+
add(...elements: Display[]): void;
|
|
101
|
+
remove(...elements: Display[]): void;
|
|
102
|
+
destory(): void;
|
|
103
|
+
get __instanceOf__(): DisplayType.Box;
|
|
104
|
+
clone(): Box;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface RGBColor {
|
|
108
|
+
r: number;
|
|
109
|
+
g: number;
|
|
110
|
+
b: number;
|
|
111
|
+
a?: number;
|
|
112
|
+
}
|
|
113
|
+
interface HLSColor {
|
|
114
|
+
h: number;
|
|
115
|
+
l: number;
|
|
116
|
+
s: number;
|
|
117
|
+
a?: number;
|
|
118
|
+
}
|
|
119
|
+
interface ColorDecoratorResultHLS {
|
|
120
|
+
mode?: 'hsl';
|
|
121
|
+
desc: HLSColor;
|
|
122
|
+
}
|
|
123
|
+
interface ColorDecoratorResultRGB {
|
|
124
|
+
mode: 'rgb';
|
|
125
|
+
desc: RGBColor;
|
|
126
|
+
}
|
|
127
|
+
type ColorDecoratorResult = ColorDecoratorResultHLS | ColorDecoratorResultRGB;
|
|
128
|
+
|
|
129
|
+
type EventCallback<P = any[]> = P extends any[] ? (...args: P) => any : never;
|
|
130
|
+
type DefaultEventDefinition = Record<string, EventCallback>;
|
|
131
|
+
type BindThisParameter<T, C = unknown> = T extends (...args: infer P) => infer R ? (this: C, ...args: P) => R : never;
|
|
132
|
+
interface EventCollectionData<EvtDefinition extends DefaultEventDefinition, C = unknown> {
|
|
133
|
+
name: string;
|
|
134
|
+
handler: BindThisParameter<EvtDefinition[keyof EvtDefinition], C>;
|
|
135
|
+
ctx: C;
|
|
136
|
+
}
|
|
137
|
+
type EventCollections<EvtDefinition extends DefaultEventDefinition> = Record<keyof EvtDefinition, EventCollectionData<EvtDefinition>[]>;
|
|
138
|
+
declare class Event<EvtDefinition extends DefaultEventDefinition = DefaultEventDefinition> {
|
|
139
|
+
eventCollections: EventCollections<EvtDefinition>;
|
|
140
|
+
constructor();
|
|
141
|
+
on<C, Evt extends keyof EvtDefinition>(evt: Evt, handler: BindThisParameter<EvtDefinition[Evt], unknown extends C ? this : C>, c?: C): void;
|
|
142
|
+
off(evt: keyof EvtDefinition, handler?: BindThisParameter<EvtDefinition[keyof EvtDefinition], unknown>): void;
|
|
143
|
+
emit(evt: keyof EvtDefinition, ...args: Parameters<EvtDefinition[keyof EvtDefinition]>): void;
|
|
144
|
+
bindWithContext<C>(c: C): (evt: keyof EvtDefinition, handler: BindThisParameter<EvtDefinition[keyof EvtDefinition], unknown extends C ? this : C>) => void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface RenderViewportOptions {
|
|
148
|
+
width: number;
|
|
149
|
+
height: number;
|
|
150
|
+
devicePixelRatio: number;
|
|
151
|
+
}
|
|
152
|
+
declare class Render {
|
|
153
|
+
canvas: HTMLCanvasElement;
|
|
154
|
+
ctx: CanvasRenderingContext2D;
|
|
155
|
+
options: RenderViewportOptions;
|
|
156
|
+
constructor(to: Element, options: RenderViewportOptions);
|
|
157
|
+
clear(width: number, height: number): void;
|
|
158
|
+
initOptions(userOptions?: Partial<RenderViewportOptions>): void;
|
|
159
|
+
update(schedule: Schedule$1): void;
|
|
160
|
+
destory(): void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
type ApplyTo = string | Element;
|
|
164
|
+
declare class Schedule$1 extends Box {
|
|
165
|
+
render: Render;
|
|
166
|
+
to: Element;
|
|
167
|
+
event: Event;
|
|
168
|
+
constructor(to: ApplyTo, renderOptions?: Partial<RenderViewportOptions>);
|
|
169
|
+
applyTransform(matrix: Matrix2D): void;
|
|
170
|
+
update(): void;
|
|
171
|
+
execute(render: Render, graph?: Display): void;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare function traverse(graphs: Display[], handler: (graph: Graph) => void): void;
|
|
175
|
+
declare const etoile: {
|
|
176
|
+
Schedule: typeof Schedule$1;
|
|
177
|
+
traverse: typeof traverse;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
type ColorMappings = Record<string, ColorDecoratorResult>;
|
|
181
|
+
type Rect = {
|
|
182
|
+
w: number;
|
|
183
|
+
h: number;
|
|
184
|
+
};
|
|
185
|
+
type Series<T> = {
|
|
186
|
+
max: T;
|
|
187
|
+
min: T;
|
|
188
|
+
};
|
|
189
|
+
interface RenderColor {
|
|
190
|
+
mappings: ColorMappings;
|
|
191
|
+
}
|
|
192
|
+
interface RenderLayout {
|
|
193
|
+
titleAreaHeight: Series<number>;
|
|
194
|
+
rectBorderRadius: number;
|
|
195
|
+
rectBorderWidth: number;
|
|
196
|
+
rectGap: number;
|
|
197
|
+
}
|
|
198
|
+
interface RenderFont {
|
|
199
|
+
color: string;
|
|
200
|
+
fontSize: Series<number>;
|
|
201
|
+
fontFamily: string;
|
|
202
|
+
}
|
|
203
|
+
interface RenderDecorator {
|
|
204
|
+
color: RenderColor;
|
|
205
|
+
layout: RenderLayout;
|
|
206
|
+
font: RenderFont;
|
|
207
|
+
}
|
|
208
|
+
declare const defaultLayoutOptions: {
|
|
209
|
+
titleAreaHeight: {
|
|
210
|
+
max: number;
|
|
211
|
+
min: number;
|
|
212
|
+
};
|
|
213
|
+
rectGap: number;
|
|
214
|
+
rectBorderRadius: number;
|
|
215
|
+
rectBorderWidth: number;
|
|
216
|
+
};
|
|
217
|
+
declare const defaultFontOptions: {
|
|
218
|
+
color: string;
|
|
219
|
+
fontSize: {
|
|
220
|
+
max: number;
|
|
221
|
+
min: number;
|
|
222
|
+
};
|
|
223
|
+
fontFamily: string;
|
|
224
|
+
};
|
|
225
|
+
declare function presetDecorator(app: TreemapLayout): void;
|
|
226
|
+
|
|
227
|
+
type AnyObject = Record<keyof any, any>;
|
|
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(c: HTMLCanvasElement, 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
|
+
declare const primitiveEvents: readonly ["click", "mousedown", "mousemove", "mouseup", "mouseover", "mouseout"];
|
|
267
|
+
type PrimitiveEvent = typeof primitiveEvents[number];
|
|
268
|
+
interface PrimitiveEventMetadata<T extends keyof HTMLElementEventMap> {
|
|
269
|
+
native: HTMLElementEventMap[T];
|
|
270
|
+
module: LayoutModule;
|
|
271
|
+
}
|
|
272
|
+
type PrimitiveEventCallback<T extends PrimitiveEvent> = (metadata: PrimitiveEventMetadata<T>) => void;
|
|
273
|
+
type PrimitiveEventDefinition = {
|
|
274
|
+
[key in PrimitiveEvent]: BindThisParameter<PrimitiveEventCallback<key>, TreemapInstanceAPI>;
|
|
275
|
+
};
|
|
276
|
+
interface EventMethods<C = TreemapInstanceAPI, D = PrimitiveEventDefinition> {
|
|
277
|
+
on<Evt extends keyof D>(evt: Evt, handler: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
278
|
+
off<Evt extends keyof D>(evt: keyof D, handler?: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
interface TreemapOptions {
|
|
282
|
+
data: Module[];
|
|
283
|
+
}
|
|
284
|
+
type Using = 'decorator';
|
|
285
|
+
interface App {
|
|
286
|
+
init: (el: Element) => void;
|
|
287
|
+
dispose: () => void;
|
|
288
|
+
setOptions: (options: TreemapOptions) => void;
|
|
289
|
+
resize: () => void;
|
|
290
|
+
use: (using: Using, register: (app: TreemapLayout) => void) => void;
|
|
291
|
+
zoom: (id: string) => void;
|
|
292
|
+
}
|
|
293
|
+
declare class Schedule extends etoile.Schedule {
|
|
294
|
+
}
|
|
295
|
+
declare class TreemapLayout extends Schedule {
|
|
296
|
+
data: NativeModule[];
|
|
297
|
+
layoutNodes: LayoutModule[];
|
|
298
|
+
decorator: RenderDecorator;
|
|
299
|
+
private bgBox;
|
|
300
|
+
private fgBox;
|
|
301
|
+
fontsCaches: Record<string, number>;
|
|
302
|
+
ellispsisWidthCache: Record<string, number>;
|
|
303
|
+
constructor(...args: ConstructorParameters<typeof Schedule>);
|
|
304
|
+
drawBackgroundNode(node: LayoutModule): void;
|
|
305
|
+
drawForegroundNode(node: LayoutModule): void;
|
|
306
|
+
reset(): void;
|
|
307
|
+
get api(): {
|
|
308
|
+
zoom: (node: LayoutModule) => void;
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
declare function createTreemap(): App & EventMethods;
|
|
312
|
+
type TreemapInstanceAPI = TreemapLayout['api'];
|
|
313
|
+
|
|
314
|
+
export { type App, type ColorMappings, type EventMethods, type LayoutModule, type Module, type NativeModule, type PrimitiveEvent, type PrimitiveEventCallback, type PrimitiveEventDefinition, type PrimitiveEventMetadata, type Rect, type RenderColor, type RenderDecorator, type RenderFont, type RenderLayout, type Series, type TreemapInstanceAPI, TreemapLayout, type TreemapOptions, c2m, createTreemap, defaultFontOptions, defaultLayoutOptions, findRelativeNode, findRelativeNodeById, flatten as flattenModule, getNodeDepth, presetDecorator, sortChildrenByKey, visit };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,13 +22,26 @@ declare class Matrix2D {
|
|
|
22
22
|
private roate;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
declare
|
|
25
|
+
declare const enum DisplayType {
|
|
26
|
+
Graph = "Graph",
|
|
27
|
+
Box = "Box",
|
|
28
|
+
Rect = "Rect",
|
|
29
|
+
Text = "Text"
|
|
30
|
+
}
|
|
31
|
+
declare abstract class Display {
|
|
26
32
|
parent: Display | null;
|
|
27
33
|
id: number;
|
|
28
34
|
matrix: Matrix2D;
|
|
35
|
+
abstract get __instanceOf__(): string;
|
|
29
36
|
constructor();
|
|
30
37
|
destory(): void;
|
|
31
38
|
}
|
|
39
|
+
interface GraphStyleSheet {
|
|
40
|
+
stroke: string;
|
|
41
|
+
opacity: number;
|
|
42
|
+
font: string;
|
|
43
|
+
lineWidth: number;
|
|
44
|
+
}
|
|
32
45
|
interface LocOptions {
|
|
33
46
|
width: number;
|
|
34
47
|
height: number;
|
|
@@ -56,7 +69,7 @@ interface Instruction {
|
|
|
56
69
|
textAlign(...args: any[]): void;
|
|
57
70
|
}
|
|
58
71
|
declare function createInstruction(): Instruction;
|
|
59
|
-
declare class S extends Display {
|
|
72
|
+
declare abstract class S extends Display {
|
|
60
73
|
width: number;
|
|
61
74
|
height: number;
|
|
62
75
|
x: number;
|
|
@@ -70,9 +83,15 @@ declare class S extends Display {
|
|
|
70
83
|
}
|
|
71
84
|
declare abstract class Graph extends S {
|
|
72
85
|
instruction: ReturnType<typeof createInstruction>;
|
|
86
|
+
__refresh__: boolean;
|
|
87
|
+
__options__: Partial<LocOptions>;
|
|
88
|
+
abstract style: GraphStyleSheet;
|
|
73
89
|
constructor(options?: Partial<GraphOptions>);
|
|
74
90
|
abstract create(): void;
|
|
91
|
+
abstract clone(): Graph;
|
|
92
|
+
abstract get __shape__(): string;
|
|
75
93
|
render(ctx: CanvasRenderingContext2D): void;
|
|
94
|
+
get __instanceOf__(): DisplayType.Graph;
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
declare class Box extends Display {
|
|
@@ -81,6 +100,8 @@ declare class Box extends Display {
|
|
|
81
100
|
add(...elements: Display[]): void;
|
|
82
101
|
remove(...elements: Display[]): void;
|
|
83
102
|
destory(): void;
|
|
103
|
+
get __instanceOf__(): DisplayType.Box;
|
|
104
|
+
clone(): Box;
|
|
84
105
|
}
|
|
85
106
|
|
|
86
107
|
interface RGBColor {
|
|
@@ -222,6 +243,13 @@ type NativeModule = ReturnType<typeof bindParentForModule>[number] & {
|
|
|
222
243
|
parent: NativeModule;
|
|
223
244
|
groups: NativeModule[];
|
|
224
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(c: HTMLCanvasElement, p: {
|
|
249
|
+
x: number;
|
|
250
|
+
y: number;
|
|
251
|
+
}, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
252
|
+
declare function findRelativeNodeById(id: string, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
225
253
|
|
|
226
254
|
type LayoutModule = {
|
|
227
255
|
node: NativeModule;
|
|
@@ -260,6 +288,7 @@ interface App {
|
|
|
260
288
|
setOptions: (options: TreemapOptions) => void;
|
|
261
289
|
resize: () => void;
|
|
262
290
|
use: (using: Using, register: (app: TreemapLayout) => void) => void;
|
|
291
|
+
zoom: (id: string) => void;
|
|
263
292
|
}
|
|
264
293
|
declare class Schedule extends etoile.Schedule {
|
|
265
294
|
}
|
|
@@ -269,6 +298,8 @@ declare class TreemapLayout extends Schedule {
|
|
|
269
298
|
decorator: RenderDecorator;
|
|
270
299
|
private bgBox;
|
|
271
300
|
private fgBox;
|
|
301
|
+
fontsCaches: Record<string, number>;
|
|
302
|
+
ellispsisWidthCache: Record<string, number>;
|
|
272
303
|
constructor(...args: ConstructorParameters<typeof Schedule>);
|
|
273
304
|
drawBackgroundNode(node: LayoutModule): void;
|
|
274
305
|
drawForegroundNode(node: LayoutModule): void;
|
|
@@ -280,4 +311,4 @@ declare class TreemapLayout extends Schedule {
|
|
|
280
311
|
declare function createTreemap(): App & EventMethods;
|
|
281
312
|
type TreemapInstanceAPI = TreemapLayout['api'];
|
|
282
313
|
|
|
283
|
-
export { type App, type ColorMappings, type Rect, type RenderColor, type RenderDecorator, type RenderFont, type RenderLayout, type Series, type TreemapInstanceAPI, c2m, createTreemap, defaultFontOptions, defaultLayoutOptions, flatten as flattenModule, presetDecorator, sortChildrenByKey };
|
|
314
|
+
export { type App, type ColorMappings, type EventMethods, type LayoutModule, type Module, type NativeModule, type PrimitiveEvent, type PrimitiveEventCallback, type PrimitiveEventDefinition, type PrimitiveEventMetadata, type Rect, type RenderColor, type RenderDecorator, type RenderFont, type RenderLayout, type Series, type TreemapInstanceAPI, TreemapLayout, type TreemapOptions, c2m, createTreemap, defaultFontOptions, defaultLayoutOptions, findRelativeNode, findRelativeNodeById, flatten as flattenModule, getNodeDepth, presetDecorator, sortChildrenByKey, visit };
|