squarified 0.2.0 → 0.2.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/README.md +39 -0
- package/dist/index.d.mts +29 -7
- package/dist/index.d.ts +29 -7
- package/dist/index.js +75 -53
- package/dist/index.mjs +75 -53
- package/package.json +14 -8
package/README.md
CHANGED
|
@@ -14,6 +14,45 @@ $ yarn add squarified
|
|
|
14
14
|
|
|
15
15
|
See the dev directory for a minimal example.
|
|
16
16
|
|
|
17
|
+
### API
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// convert data into expected data
|
|
21
|
+
declare function c2m<
|
|
22
|
+
T extends AnyObject & {
|
|
23
|
+
groups: any[]
|
|
24
|
+
},
|
|
25
|
+
K extends keyof T
|
|
26
|
+
>(data: T, key: K, modifier?: (data: T) => T): T & {
|
|
27
|
+
weight: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// preset theme layout (unstable)
|
|
31
|
+
declare function presetDecorator(app: TreemapLayout): void
|
|
32
|
+
|
|
33
|
+
declare function getNodeDepth(node: NativeModule): number
|
|
34
|
+
|
|
35
|
+
declare function visit<T extends AnyObject>(data: T[], fn: (data: T) => boolean | void): T | null
|
|
36
|
+
|
|
37
|
+
declare function findRelativeNode(p: {
|
|
38
|
+
x: number
|
|
39
|
+
y: number
|
|
40
|
+
}, layoutNodes: LayoutModule[]): LayoutModule | null
|
|
41
|
+
|
|
42
|
+
declare function findRelativeNodeById(id: string, layoutNodes: LayoutModule[]): LayoutModule | null
|
|
43
|
+
|
|
44
|
+
interface App {
|
|
45
|
+
init: (el: HTMLElement) => void
|
|
46
|
+
dispose: () => void
|
|
47
|
+
setOptions: (options: TreemapOptions) => void
|
|
48
|
+
resize: () => void
|
|
49
|
+
use: (using: Using, register: (app: TreemapLayout) => void) => void
|
|
50
|
+
zoom: (id: string) => void
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare function createTreemap(): App
|
|
54
|
+
```
|
|
55
|
+
|
|
17
56
|
### Auth
|
|
18
57
|
|
|
19
58
|
Kanno
|
package/dist/index.d.mts
CHANGED
|
@@ -93,7 +93,6 @@ declare class Render {
|
|
|
93
93
|
get canvas(): HTMLCanvasElement;
|
|
94
94
|
get ctx(): CanvasRenderingContext2D;
|
|
95
95
|
initOptions(userOptions?: Partial<RenderViewportOptions>): void;
|
|
96
|
-
update(schedule: Schedule): void;
|
|
97
96
|
destory(): void;
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -113,6 +112,10 @@ declare class Layer extends C implements S {
|
|
|
113
112
|
constructor(options?: Partial<LocOptions>);
|
|
114
113
|
get __instanceOf__(): DisplayType.Layer;
|
|
115
114
|
setCanvasOptions(options?: Partial<RenderViewportOptions>): void;
|
|
115
|
+
cleanCacheSnapshot(): {
|
|
116
|
+
dpr: number;
|
|
117
|
+
matrix: Matrix2D;
|
|
118
|
+
};
|
|
116
119
|
setCacheSnapshot(c: HTMLCanvasElement): void;
|
|
117
120
|
initLoc(options?: Partial<LocOptions>): void;
|
|
118
121
|
draw(ctx: CanvasRenderingContext2D): void;
|
|
@@ -161,10 +164,10 @@ declare class Event<EvtDefinition extends DefaultEventDefinition = DefaultEventD
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
type ApplyTo = string | Element;
|
|
164
|
-
declare class Schedule extends Box {
|
|
167
|
+
declare class Schedule<D extends DefaultEventDefinition = DefaultEventDefinition> extends Box {
|
|
165
168
|
render: Render;
|
|
166
169
|
to: Element;
|
|
167
|
-
event: Event
|
|
170
|
+
event: Event<D>;
|
|
168
171
|
constructor(to: ApplyTo, renderOptions?: Partial<RenderViewportOptions>);
|
|
169
172
|
update(): void;
|
|
170
173
|
execute(render: Render, graph?: Display): void;
|
|
@@ -244,7 +247,7 @@ type NativeModule = ReturnType<typeof bindParentForModule>[number] & {
|
|
|
244
247
|
};
|
|
245
248
|
declare function getNodeDepth(node: NativeModule): number;
|
|
246
249
|
declare function visit<T extends AnyObject>(data: T[], fn: (data: T) => boolean | void): T | null;
|
|
247
|
-
declare function findRelativeNode(
|
|
250
|
+
declare function findRelativeNode(p: {
|
|
248
251
|
x: number;
|
|
249
252
|
y: number;
|
|
250
253
|
}, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
@@ -276,20 +279,39 @@ interface EventMethods<C = TreemapInstanceAPI, D = PrimitiveEventDefinition> {
|
|
|
276
279
|
on<Evt extends keyof D>(evt: Evt, handler: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
277
280
|
off<Evt extends keyof D>(evt: keyof D, handler?: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
278
281
|
}
|
|
282
|
+
declare const internalEventMappings: {
|
|
283
|
+
readonly CLEAN_UP: "self:cleanup";
|
|
284
|
+
readonly ON_LOAD: "self:onload";
|
|
285
|
+
readonly ON_ZOOM: "zoom";
|
|
286
|
+
};
|
|
287
|
+
type InternalEventType = typeof internalEventMappings[keyof typeof internalEventMappings];
|
|
288
|
+
interface InternalEventMappings {
|
|
289
|
+
[internalEventMappings.CLEAN_UP]: () => void;
|
|
290
|
+
[internalEventMappings.ON_LOAD]: (width: number, height: number, root: HTMLElement) => void;
|
|
291
|
+
[internalEventMappings.ON_ZOOM]: (node: LayoutModule) => void;
|
|
292
|
+
}
|
|
293
|
+
type InternalEventDefinition = {
|
|
294
|
+
[key in InternalEventType]: InternalEventMappings[key];
|
|
295
|
+
};
|
|
279
296
|
|
|
280
297
|
interface TreemapOptions {
|
|
281
298
|
data: Module[];
|
|
282
299
|
}
|
|
283
300
|
type Using = 'decorator';
|
|
284
301
|
interface App {
|
|
285
|
-
init: (el:
|
|
302
|
+
init: (el: HTMLElement) => void;
|
|
286
303
|
dispose: () => void;
|
|
287
304
|
setOptions: (options: TreemapOptions) => void;
|
|
288
305
|
resize: () => void;
|
|
289
306
|
use: (using: Using, register: (app: TreemapLayout) => void) => void;
|
|
290
307
|
zoom: (id: string) => void;
|
|
291
308
|
}
|
|
292
|
-
|
|
309
|
+
/**
|
|
310
|
+
* This interface isn't stable it might be remove at next few versions.
|
|
311
|
+
* If you want set custom decorator pls see 'presetDecorator' for details.
|
|
312
|
+
*/
|
|
313
|
+
type unstable_use = (app: TreemapLayout) => void;
|
|
314
|
+
declare class TreemapLayout extends etoile.Schedule<InternalEventDefinition> {
|
|
293
315
|
data: NativeModule[];
|
|
294
316
|
layoutNodes: LayoutModule[];
|
|
295
317
|
decorator: RenderDecorator;
|
|
@@ -309,4 +331,4 @@ declare class TreemapLayout extends etoile.Schedule {
|
|
|
309
331
|
declare function createTreemap(): App & EventMethods;
|
|
310
332
|
type TreemapInstanceAPI = TreemapLayout['api'];
|
|
311
333
|
|
|
312
|
-
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 };
|
|
334
|
+
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, type unstable_use, visit };
|
package/dist/index.d.ts
CHANGED
|
@@ -93,7 +93,6 @@ declare class Render {
|
|
|
93
93
|
get canvas(): HTMLCanvasElement;
|
|
94
94
|
get ctx(): CanvasRenderingContext2D;
|
|
95
95
|
initOptions(userOptions?: Partial<RenderViewportOptions>): void;
|
|
96
|
-
update(schedule: Schedule): void;
|
|
97
96
|
destory(): void;
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -113,6 +112,10 @@ declare class Layer extends C implements S {
|
|
|
113
112
|
constructor(options?: Partial<LocOptions>);
|
|
114
113
|
get __instanceOf__(): DisplayType.Layer;
|
|
115
114
|
setCanvasOptions(options?: Partial<RenderViewportOptions>): void;
|
|
115
|
+
cleanCacheSnapshot(): {
|
|
116
|
+
dpr: number;
|
|
117
|
+
matrix: Matrix2D;
|
|
118
|
+
};
|
|
116
119
|
setCacheSnapshot(c: HTMLCanvasElement): void;
|
|
117
120
|
initLoc(options?: Partial<LocOptions>): void;
|
|
118
121
|
draw(ctx: CanvasRenderingContext2D): void;
|
|
@@ -161,10 +164,10 @@ declare class Event<EvtDefinition extends DefaultEventDefinition = DefaultEventD
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
type ApplyTo = string | Element;
|
|
164
|
-
declare class Schedule extends Box {
|
|
167
|
+
declare class Schedule<D extends DefaultEventDefinition = DefaultEventDefinition> extends Box {
|
|
165
168
|
render: Render;
|
|
166
169
|
to: Element;
|
|
167
|
-
event: Event
|
|
170
|
+
event: Event<D>;
|
|
168
171
|
constructor(to: ApplyTo, renderOptions?: Partial<RenderViewportOptions>);
|
|
169
172
|
update(): void;
|
|
170
173
|
execute(render: Render, graph?: Display): void;
|
|
@@ -244,7 +247,7 @@ type NativeModule = ReturnType<typeof bindParentForModule>[number] & {
|
|
|
244
247
|
};
|
|
245
248
|
declare function getNodeDepth(node: NativeModule): number;
|
|
246
249
|
declare function visit<T extends AnyObject>(data: T[], fn: (data: T) => boolean | void): T | null;
|
|
247
|
-
declare function findRelativeNode(
|
|
250
|
+
declare function findRelativeNode(p: {
|
|
248
251
|
x: number;
|
|
249
252
|
y: number;
|
|
250
253
|
}, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
@@ -276,20 +279,39 @@ interface EventMethods<C = TreemapInstanceAPI, D = PrimitiveEventDefinition> {
|
|
|
276
279
|
on<Evt extends keyof D>(evt: Evt, handler: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
277
280
|
off<Evt extends keyof D>(evt: keyof D, handler?: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
278
281
|
}
|
|
282
|
+
declare const internalEventMappings: {
|
|
283
|
+
readonly CLEAN_UP: "self:cleanup";
|
|
284
|
+
readonly ON_LOAD: "self:onload";
|
|
285
|
+
readonly ON_ZOOM: "zoom";
|
|
286
|
+
};
|
|
287
|
+
type InternalEventType = typeof internalEventMappings[keyof typeof internalEventMappings];
|
|
288
|
+
interface InternalEventMappings {
|
|
289
|
+
[internalEventMappings.CLEAN_UP]: () => void;
|
|
290
|
+
[internalEventMappings.ON_LOAD]: (width: number, height: number, root: HTMLElement) => void;
|
|
291
|
+
[internalEventMappings.ON_ZOOM]: (node: LayoutModule) => void;
|
|
292
|
+
}
|
|
293
|
+
type InternalEventDefinition = {
|
|
294
|
+
[key in InternalEventType]: InternalEventMappings[key];
|
|
295
|
+
};
|
|
279
296
|
|
|
280
297
|
interface TreemapOptions {
|
|
281
298
|
data: Module[];
|
|
282
299
|
}
|
|
283
300
|
type Using = 'decorator';
|
|
284
301
|
interface App {
|
|
285
|
-
init: (el:
|
|
302
|
+
init: (el: HTMLElement) => void;
|
|
286
303
|
dispose: () => void;
|
|
287
304
|
setOptions: (options: TreemapOptions) => void;
|
|
288
305
|
resize: () => void;
|
|
289
306
|
use: (using: Using, register: (app: TreemapLayout) => void) => void;
|
|
290
307
|
zoom: (id: string) => void;
|
|
291
308
|
}
|
|
292
|
-
|
|
309
|
+
/**
|
|
310
|
+
* This interface isn't stable it might be remove at next few versions.
|
|
311
|
+
* If you want set custom decorator pls see 'presetDecorator' for details.
|
|
312
|
+
*/
|
|
313
|
+
type unstable_use = (app: TreemapLayout) => void;
|
|
314
|
+
declare class TreemapLayout extends etoile.Schedule<InternalEventDefinition> {
|
|
293
315
|
data: NativeModule[];
|
|
294
316
|
layoutNodes: LayoutModule[];
|
|
295
317
|
decorator: RenderDecorator;
|
|
@@ -309,4 +331,4 @@ declare class TreemapLayout extends etoile.Schedule {
|
|
|
309
331
|
declare function createTreemap(): App & EventMethods;
|
|
310
332
|
type TreemapInstanceAPI = TreemapLayout['api'];
|
|
311
333
|
|
|
312
|
-
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 };
|
|
334
|
+
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, type unstable_use, visit };
|
package/dist/index.js
CHANGED
|
@@ -103,42 +103,44 @@ class Display {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
const ASSIGN_MAPPINGS = {
|
|
106
|
-
fillStyle:
|
|
107
|
-
strokeStyle:
|
|
108
|
-
font:
|
|
109
|
-
lineWidth:
|
|
110
|
-
textAlign:
|
|
111
|
-
textBaseline:
|
|
106
|
+
fillStyle: 1,
|
|
107
|
+
strokeStyle: 2,
|
|
108
|
+
font: 4,
|
|
109
|
+
lineWidth: 8,
|
|
110
|
+
textAlign: 16,
|
|
111
|
+
textBaseline: 32
|
|
112
112
|
};
|
|
113
|
+
const ASSIGN_MAPPINGS_MODE = ASSIGN_MAPPINGS.fillStyle | ASSIGN_MAPPINGS.strokeStyle | ASSIGN_MAPPINGS.font | ASSIGN_MAPPINGS.lineWidth | ASSIGN_MAPPINGS.textAlign | ASSIGN_MAPPINGS.textBaseline;
|
|
114
|
+
const CALL_MAPPINGS_MODE = 0;
|
|
113
115
|
function createInstruction() {
|
|
114
116
|
return {
|
|
115
117
|
mods: [],
|
|
116
118
|
fillStyle(...args) {
|
|
117
|
-
this.mods.push(["fillStyle", args]);
|
|
119
|
+
this.mods.push({ mod: ["fillStyle", args], type: ASSIGN_MAPPINGS.fillStyle });
|
|
118
120
|
},
|
|
119
121
|
fillRect(...args) {
|
|
120
|
-
this.mods.push(["fillRect", args]);
|
|
122
|
+
this.mods.push({ mod: ["fillRect", args], type: CALL_MAPPINGS_MODE });
|
|
121
123
|
},
|
|
122
124
|
strokeStyle(...args) {
|
|
123
|
-
this.mods.push(["strokeStyle", args]);
|
|
125
|
+
this.mods.push({ mod: ["strokeStyle", args], type: ASSIGN_MAPPINGS.strokeStyle });
|
|
124
126
|
},
|
|
125
127
|
lineWidth(...args) {
|
|
126
|
-
this.mods.push(["lineWidth", args]);
|
|
128
|
+
this.mods.push({ mod: ["lineWidth", args], type: ASSIGN_MAPPINGS.lineWidth });
|
|
127
129
|
},
|
|
128
130
|
strokeRect(...args) {
|
|
129
|
-
this.mods.push(["strokeRect", args]);
|
|
131
|
+
this.mods.push({ mod: ["strokeRect", args], type: CALL_MAPPINGS_MODE });
|
|
130
132
|
},
|
|
131
133
|
fillText(...args) {
|
|
132
|
-
this.mods.push(["fillText", args]);
|
|
134
|
+
this.mods.push({ mod: ["fillText", args], type: CALL_MAPPINGS_MODE });
|
|
133
135
|
},
|
|
134
136
|
font(...args) {
|
|
135
|
-
this.mods.push(["font", args]);
|
|
137
|
+
this.mods.push({ mod: ["font", args], type: ASSIGN_MAPPINGS.font });
|
|
136
138
|
},
|
|
137
139
|
textBaseline(...args) {
|
|
138
|
-
this.mods.push(["textBaseline", args]);
|
|
140
|
+
this.mods.push({ mod: ["textBaseline", args], type: ASSIGN_MAPPINGS.textBaseline });
|
|
139
141
|
},
|
|
140
142
|
textAlign(...args) {
|
|
141
|
-
this.mods.push(["textAlign", args]);
|
|
143
|
+
this.mods.push({ mod: ["textAlign", args], type: ASSIGN_MAPPINGS.textAlign });
|
|
142
144
|
}
|
|
143
145
|
};
|
|
144
146
|
}
|
|
@@ -177,9 +179,9 @@ class Graph extends S {
|
|
|
177
179
|
this.create();
|
|
178
180
|
const cap = this.instruction.mods.length;
|
|
179
181
|
for (let i = 0; i < cap; i++) {
|
|
180
|
-
const mod = this.instruction.mods[i];
|
|
182
|
+
const { mod, type } = this.instruction.mods[i];
|
|
181
183
|
const [direct, ...args] = mod;
|
|
182
|
-
if (
|
|
184
|
+
if (type & ASSIGN_MAPPINGS_MODE) {
|
|
183
185
|
ctx[direct] = args[0];
|
|
184
186
|
continue;
|
|
185
187
|
}
|
|
@@ -216,7 +218,7 @@ const asserts = {
|
|
|
216
218
|
|
|
217
219
|
var __defProp$8 = Object.defineProperty;
|
|
218
220
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
219
|
-
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, key + "" , value);
|
|
221
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
220
222
|
class C extends Display {
|
|
221
223
|
constructor() {
|
|
222
224
|
super();
|
|
@@ -286,25 +288,24 @@ class Box extends C {
|
|
|
286
288
|
clone() {
|
|
287
289
|
const box = new Box();
|
|
288
290
|
if (this.elements.length) {
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
+
const stack = [{ elements: this.elements, parent: box }];
|
|
292
|
+
while (stack.length > 0) {
|
|
293
|
+
const { elements, parent } = stack.pop();
|
|
291
294
|
const cap = elements.length;
|
|
292
295
|
for (let i = 0; i < cap; i++) {
|
|
293
296
|
const element = elements[i];
|
|
294
297
|
if (asserts.isBox(element)) {
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
298
|
+
const newBox = new Box();
|
|
299
|
+
newBox.parent = parent;
|
|
300
|
+
parent.add(newBox);
|
|
301
|
+
stack.push({ elements: element.elements, parent: newBox });
|
|
299
302
|
} else if (asserts.isGraph(element)) {
|
|
300
303
|
const el = element.clone();
|
|
301
304
|
el.parent = parent;
|
|
302
|
-
|
|
305
|
+
parent.add(el);
|
|
303
306
|
}
|
|
304
307
|
}
|
|
305
|
-
|
|
306
|
-
};
|
|
307
|
-
box.add(...traverse(this.elements, box));
|
|
308
|
+
}
|
|
308
309
|
}
|
|
309
310
|
return box;
|
|
310
311
|
}
|
|
@@ -352,10 +353,6 @@ class Render {
|
|
|
352
353
|
Object.assign(this.options, userOptions);
|
|
353
354
|
writeBoundingRectForCanvas(this.canvas, this.options.width, this.options.height, this.options.devicePixelRatio);
|
|
354
355
|
}
|
|
355
|
-
update(schedule) {
|
|
356
|
-
this.clear(this.options.width, this.options.height);
|
|
357
|
-
schedule.execute(this);
|
|
358
|
-
}
|
|
359
356
|
destory() {
|
|
360
357
|
}
|
|
361
358
|
}
|
|
@@ -398,10 +395,14 @@ class Layer extends C {
|
|
|
398
395
|
Object.assign(this.options, options);
|
|
399
396
|
writeBoundingRectForCanvas(this.c.c.canvas, options.width || 0, options.height || 0, options.devicePixelRatio || 1);
|
|
400
397
|
}
|
|
401
|
-
|
|
398
|
+
cleanCacheSnapshot() {
|
|
402
399
|
const dpr = this.options.devicePixelRatio || 1;
|
|
403
400
|
const matrix = this.matrix.create({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
|
|
404
401
|
this.ctx.clearRect(0, 0, this.options.width, this.options.height);
|
|
402
|
+
return { dpr, matrix };
|
|
403
|
+
}
|
|
404
|
+
setCacheSnapshot(c) {
|
|
405
|
+
const { matrix, dpr } = this.cleanCacheSnapshot();
|
|
405
406
|
matrix.transform(this.x, this.y, this.scaleX, this.scaleY, this.rotation, this.skewX, this.skewY);
|
|
406
407
|
applyCanvasTransform(this.ctx, matrix, dpr);
|
|
407
408
|
this.ctx.drawImage(c, 0, 0, this.options.width / dpr, this.options.height / dpr);
|
|
@@ -457,7 +458,7 @@ const runtime = {
|
|
|
457
458
|
|
|
458
459
|
var __defProp$5 = Object.defineProperty;
|
|
459
460
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
460
|
-
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
|
|
461
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
461
462
|
class Rect extends Graph {
|
|
462
463
|
constructor(options = {}) {
|
|
463
464
|
super(options);
|
|
@@ -515,7 +516,7 @@ class Text extends Graph {
|
|
|
515
516
|
|
|
516
517
|
var __defProp$3 = Object.defineProperty;
|
|
517
518
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
518
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, key + "" , value);
|
|
519
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
519
520
|
class Event {
|
|
520
521
|
constructor() {
|
|
521
522
|
__publicField$3(this, "eventCollections");
|
|
@@ -605,7 +606,8 @@ class Schedule extends Box {
|
|
|
605
606
|
this.render = new Render(this.to, renderOptions);
|
|
606
607
|
}
|
|
607
608
|
update() {
|
|
608
|
-
this.render.
|
|
609
|
+
this.render.clear(this.render.options.width, this.render.options.height);
|
|
610
|
+
this.execute(this.render, this);
|
|
609
611
|
const matrix = this.matrix.create({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
|
|
610
612
|
applyCanvasTransform(this.render.ctx, matrix, this.render.options.devicePixelRatio);
|
|
611
613
|
}
|
|
@@ -773,7 +775,7 @@ function visit(data, fn) {
|
|
|
773
775
|
}
|
|
774
776
|
return null;
|
|
775
777
|
}
|
|
776
|
-
function findRelativeNode(
|
|
778
|
+
function findRelativeNode(p, layoutNodes) {
|
|
777
779
|
return visit(layoutNodes, (node) => {
|
|
778
780
|
const [x, y, w, h] = node.layout;
|
|
779
781
|
if (p.x >= x && p.y >= y && p.x < x + w && p.y < y + h) {
|
|
@@ -910,6 +912,11 @@ var __defProp$1 = Object.defineProperty;
|
|
|
910
912
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
911
913
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
912
914
|
const primitiveEvents = ["click", "mousedown", "mousemove", "mouseup", "mouseover", "mouseout"];
|
|
915
|
+
const internalEventMappings = {
|
|
916
|
+
CLEAN_UP: "self:cleanup",
|
|
917
|
+
ON_LOAD: "self:onload",
|
|
918
|
+
ON_ZOOM: "zoom"
|
|
919
|
+
};
|
|
913
920
|
const fill = { desc: { r: 255, g: 255, b: 255 }, mode: "rgb" };
|
|
914
921
|
function smoothDrawing(c) {
|
|
915
922
|
const { self } = c;
|
|
@@ -943,7 +950,7 @@ function smoothDrawing(c) {
|
|
|
943
950
|
}
|
|
944
951
|
}
|
|
945
952
|
function applyZoomEvent(ctx) {
|
|
946
|
-
ctx.treemap.event.on(
|
|
953
|
+
ctx.treemap.event.on(internalEventMappings.ON_ZOOM, (node) => {
|
|
947
954
|
const root = null;
|
|
948
955
|
if (ctx.self.isDragging) return;
|
|
949
956
|
onZoom(ctx, node, root);
|
|
@@ -991,7 +998,7 @@ function bindPrimitiveEvent(c, ctx, evt, bus) {
|
|
|
991
998
|
);
|
|
992
999
|
const event = {
|
|
993
1000
|
native: e,
|
|
994
|
-
module: findRelativeNode(
|
|
1001
|
+
module: findRelativeNode({ x, y }, treemap.layoutNodes)
|
|
995
1002
|
};
|
|
996
1003
|
bus.emit(evt, event);
|
|
997
1004
|
};
|
|
@@ -1050,7 +1057,7 @@ class SelfEvent extends RegisterModule {
|
|
|
1050
1057
|
this.self.highlight.reset();
|
|
1051
1058
|
this.self.highlight.setDisplayLayerForHighlight();
|
|
1052
1059
|
this.self.event.off("mousemove", this.self.onmousemove);
|
|
1053
|
-
this.treemap.event.off(
|
|
1060
|
+
this.treemap.event.off(internalEventMappings.ON_ZOOM);
|
|
1054
1061
|
this.self.forceDestroy = true;
|
|
1055
1062
|
const { native } = metadata;
|
|
1056
1063
|
const x = native.offsetX;
|
|
@@ -1065,7 +1072,6 @@ class SelfEvent extends RegisterModule {
|
|
|
1065
1072
|
refreshBackgroundLayer(this);
|
|
1066
1073
|
}
|
|
1067
1074
|
this.treemap.reset();
|
|
1068
|
-
stackMatrixTransform(this.treemap.backgroundLayer, 0, 0, 0);
|
|
1069
1075
|
stackMatrixTransformWithGraphAndLayer(this.treemap.elements, this.self.translateX, this.self.translateY, this.self.scaleRatio);
|
|
1070
1076
|
this.treemap.update();
|
|
1071
1077
|
}
|
|
@@ -1110,7 +1116,6 @@ class SelfEvent extends RegisterModule {
|
|
|
1110
1116
|
treemap.reset();
|
|
1111
1117
|
this.self.highlight.reset();
|
|
1112
1118
|
this.self.highlight.setDisplayLayerForHighlight();
|
|
1113
|
-
stackMatrixTransform(this.treemap.backgroundLayer, 0, 0, 0);
|
|
1114
1119
|
const factor = absWheelDelta > 3 ? 1.4 : absWheelDelta > 1 ? 1.2 : 1.1;
|
|
1115
1120
|
const delta = wheelDelta > 0 ? factor : 1 / factor;
|
|
1116
1121
|
self.scaleRatio *= delta;
|
|
@@ -1151,7 +1156,7 @@ class SelfEvent extends RegisterModule {
|
|
|
1151
1156
|
selfEvt("wheel", this.onwheel);
|
|
1152
1157
|
applyZoomEvent({ treemap, self: this });
|
|
1153
1158
|
let installHightlightEvent = false;
|
|
1154
|
-
treemap.event.on(
|
|
1159
|
+
treemap.event.on(internalEventMappings.ON_LOAD, (width, height, root) => {
|
|
1155
1160
|
this.highlight.init(width, height, root);
|
|
1156
1161
|
if (!installHightlightEvent) {
|
|
1157
1162
|
bindPrimitiveEvent(this.highlight.highlight.render.canvas, { treemap, self: this }, "mousemove", event);
|
|
@@ -1163,7 +1168,7 @@ class SelfEvent extends RegisterModule {
|
|
|
1163
1168
|
}
|
|
1164
1169
|
this.highlight.reset();
|
|
1165
1170
|
});
|
|
1166
|
-
treemap.event.on(
|
|
1171
|
+
treemap.event.on(internalEventMappings.CLEAN_UP, () => {
|
|
1167
1172
|
this.currentNode = null;
|
|
1168
1173
|
this.scaleRatio = 1;
|
|
1169
1174
|
this.translateX = 0;
|
|
@@ -1216,6 +1221,10 @@ function onZoom(ctx, node, root) {
|
|
|
1216
1221
|
const c = treemap.render.canvas;
|
|
1217
1222
|
const boundingClientRect = c.getBoundingClientRect();
|
|
1218
1223
|
const [w, h] = estimateZoomingArea(node, root, boundingClientRect.width, boundingClientRect.height);
|
|
1224
|
+
if (self.layoutHeight !== w || self.layoutHeight !== h) {
|
|
1225
|
+
delete treemap.fontsCaches[node.node.id];
|
|
1226
|
+
delete treemap.ellispsisWidthCache[node.node.id];
|
|
1227
|
+
}
|
|
1219
1228
|
resetLayout(treemap, w, h);
|
|
1220
1229
|
const module = findRelativeNodeById(node.node.id, treemap.layoutNodes);
|
|
1221
1230
|
if (module) {
|
|
@@ -1228,10 +1237,6 @@ function onZoom(ctx, node, root) {
|
|
|
1228
1237
|
const initialTranslateY = self.translateY;
|
|
1229
1238
|
const startTime = Date.now();
|
|
1230
1239
|
const animationDuration = 300;
|
|
1231
|
-
if (self.layoutHeight !== w || self.layoutHeight !== h) {
|
|
1232
|
-
delete treemap.fontsCaches[module.node.id];
|
|
1233
|
-
delete treemap.ellispsisWidthCache[module.node.id];
|
|
1234
|
-
}
|
|
1235
1240
|
const { run, stop } = createEffectScope();
|
|
1236
1241
|
run(() => {
|
|
1237
1242
|
const elapsed = Date.now() - startTime;
|
|
@@ -1290,9 +1295,24 @@ function createHighlight() {
|
|
|
1290
1295
|
};
|
|
1291
1296
|
}
|
|
1292
1297
|
function refreshBackgroundLayer(c) {
|
|
1293
|
-
const { treemap } = c;
|
|
1294
|
-
const { backgroundLayer } = treemap;
|
|
1298
|
+
const { treemap, self } = c;
|
|
1299
|
+
const { backgroundLayer, render } = treemap;
|
|
1300
|
+
const { canvas, ctx, options: { width: ow, height: oh } } = render;
|
|
1301
|
+
const { layoutWidth: sw, layoutHeight: sh, scaleRatio: ss } = self;
|
|
1302
|
+
const capture = sw * ss >= ow && sh * ss >= oh;
|
|
1295
1303
|
backgroundLayer.__refresh__ = false;
|
|
1304
|
+
if (!capture && !self.forceDestroy) {
|
|
1305
|
+
resetLayout(treemap, sw * ss, sh * ss);
|
|
1306
|
+
render.clear(ow, oh);
|
|
1307
|
+
const { dpr } = backgroundLayer.cleanCacheSnapshot();
|
|
1308
|
+
drawGraphIntoCanvas(backgroundLayer, { c: canvas, ctx, dpr }, (opts, graph) => {
|
|
1309
|
+
if (asserts.isLayer(graph) && !graph.__refresh__) {
|
|
1310
|
+
graph.setCacheSnapshot(opts.c);
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
self.triggerZoom = false;
|
|
1314
|
+
return true;
|
|
1315
|
+
}
|
|
1296
1316
|
}
|
|
1297
1317
|
|
|
1298
1318
|
var __defProp = Object.defineProperty;
|
|
@@ -1419,6 +1439,8 @@ class TreemapLayout extends etoile.Schedule {
|
|
|
1419
1439
|
for (const node of this.layoutNodes) {
|
|
1420
1440
|
this.drawBackgroundNode(node);
|
|
1421
1441
|
}
|
|
1442
|
+
} else {
|
|
1443
|
+
this.bgLayer.initLoc();
|
|
1422
1444
|
}
|
|
1423
1445
|
if (!this.fgBox.elements.length || refresh) {
|
|
1424
1446
|
this.render.ctx.textBaseline = "middle";
|
|
@@ -1434,7 +1456,7 @@ class TreemapLayout extends etoile.Schedule {
|
|
|
1434
1456
|
get api() {
|
|
1435
1457
|
return {
|
|
1436
1458
|
zoom: (node) => {
|
|
1437
|
-
this.event.emit(
|
|
1459
|
+
this.event.emit(internalEventMappings.ON_ZOOM, node);
|
|
1438
1460
|
}
|
|
1439
1461
|
};
|
|
1440
1462
|
}
|
|
@@ -1484,8 +1506,8 @@ function createTreemap() {
|
|
|
1484
1506
|
treemap.backgroundLayer.initLoc();
|
|
1485
1507
|
treemap.backgroundLayer.matrix = treemap.backgroundLayer.matrix.create({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
|
|
1486
1508
|
treemap.fontsCaches = /* @__PURE__ */ Object.create(null);
|
|
1487
|
-
treemap.event.emit(
|
|
1488
|
-
treemap.event.emit(
|
|
1509
|
+
treemap.event.emit(internalEventMappings.CLEAN_UP);
|
|
1510
|
+
treemap.event.emit(internalEventMappings.ON_LOAD, width, height, root);
|
|
1489
1511
|
resetLayout(treemap, width, height);
|
|
1490
1512
|
treemap.update();
|
|
1491
1513
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -101,42 +101,44 @@ class Display {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
const ASSIGN_MAPPINGS = {
|
|
104
|
-
fillStyle:
|
|
105
|
-
strokeStyle:
|
|
106
|
-
font:
|
|
107
|
-
lineWidth:
|
|
108
|
-
textAlign:
|
|
109
|
-
textBaseline:
|
|
104
|
+
fillStyle: 1,
|
|
105
|
+
strokeStyle: 2,
|
|
106
|
+
font: 4,
|
|
107
|
+
lineWidth: 8,
|
|
108
|
+
textAlign: 16,
|
|
109
|
+
textBaseline: 32
|
|
110
110
|
};
|
|
111
|
+
const ASSIGN_MAPPINGS_MODE = ASSIGN_MAPPINGS.fillStyle | ASSIGN_MAPPINGS.strokeStyle | ASSIGN_MAPPINGS.font | ASSIGN_MAPPINGS.lineWidth | ASSIGN_MAPPINGS.textAlign | ASSIGN_MAPPINGS.textBaseline;
|
|
112
|
+
const CALL_MAPPINGS_MODE = 0;
|
|
111
113
|
function createInstruction() {
|
|
112
114
|
return {
|
|
113
115
|
mods: [],
|
|
114
116
|
fillStyle(...args) {
|
|
115
|
-
this.mods.push(["fillStyle", args]);
|
|
117
|
+
this.mods.push({ mod: ["fillStyle", args], type: ASSIGN_MAPPINGS.fillStyle });
|
|
116
118
|
},
|
|
117
119
|
fillRect(...args) {
|
|
118
|
-
this.mods.push(["fillRect", args]);
|
|
120
|
+
this.mods.push({ mod: ["fillRect", args], type: CALL_MAPPINGS_MODE });
|
|
119
121
|
},
|
|
120
122
|
strokeStyle(...args) {
|
|
121
|
-
this.mods.push(["strokeStyle", args]);
|
|
123
|
+
this.mods.push({ mod: ["strokeStyle", args], type: ASSIGN_MAPPINGS.strokeStyle });
|
|
122
124
|
},
|
|
123
125
|
lineWidth(...args) {
|
|
124
|
-
this.mods.push(["lineWidth", args]);
|
|
126
|
+
this.mods.push({ mod: ["lineWidth", args], type: ASSIGN_MAPPINGS.lineWidth });
|
|
125
127
|
},
|
|
126
128
|
strokeRect(...args) {
|
|
127
|
-
this.mods.push(["strokeRect", args]);
|
|
129
|
+
this.mods.push({ mod: ["strokeRect", args], type: CALL_MAPPINGS_MODE });
|
|
128
130
|
},
|
|
129
131
|
fillText(...args) {
|
|
130
|
-
this.mods.push(["fillText", args]);
|
|
132
|
+
this.mods.push({ mod: ["fillText", args], type: CALL_MAPPINGS_MODE });
|
|
131
133
|
},
|
|
132
134
|
font(...args) {
|
|
133
|
-
this.mods.push(["font", args]);
|
|
135
|
+
this.mods.push({ mod: ["font", args], type: ASSIGN_MAPPINGS.font });
|
|
134
136
|
},
|
|
135
137
|
textBaseline(...args) {
|
|
136
|
-
this.mods.push(["textBaseline", args]);
|
|
138
|
+
this.mods.push({ mod: ["textBaseline", args], type: ASSIGN_MAPPINGS.textBaseline });
|
|
137
139
|
},
|
|
138
140
|
textAlign(...args) {
|
|
139
|
-
this.mods.push(["textAlign", args]);
|
|
141
|
+
this.mods.push({ mod: ["textAlign", args], type: ASSIGN_MAPPINGS.textAlign });
|
|
140
142
|
}
|
|
141
143
|
};
|
|
142
144
|
}
|
|
@@ -175,9 +177,9 @@ class Graph extends S {
|
|
|
175
177
|
this.create();
|
|
176
178
|
const cap = this.instruction.mods.length;
|
|
177
179
|
for (let i = 0; i < cap; i++) {
|
|
178
|
-
const mod = this.instruction.mods[i];
|
|
180
|
+
const { mod, type } = this.instruction.mods[i];
|
|
179
181
|
const [direct, ...args] = mod;
|
|
180
|
-
if (
|
|
182
|
+
if (type & ASSIGN_MAPPINGS_MODE) {
|
|
181
183
|
ctx[direct] = args[0];
|
|
182
184
|
continue;
|
|
183
185
|
}
|
|
@@ -214,7 +216,7 @@ const asserts = {
|
|
|
214
216
|
|
|
215
217
|
var __defProp$8 = Object.defineProperty;
|
|
216
218
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
217
|
-
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, key + "" , value);
|
|
219
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
218
220
|
class C extends Display {
|
|
219
221
|
constructor() {
|
|
220
222
|
super();
|
|
@@ -284,25 +286,24 @@ class Box extends C {
|
|
|
284
286
|
clone() {
|
|
285
287
|
const box = new Box();
|
|
286
288
|
if (this.elements.length) {
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
+
const stack = [{ elements: this.elements, parent: box }];
|
|
290
|
+
while (stack.length > 0) {
|
|
291
|
+
const { elements, parent } = stack.pop();
|
|
289
292
|
const cap = elements.length;
|
|
290
293
|
for (let i = 0; i < cap; i++) {
|
|
291
294
|
const element = elements[i];
|
|
292
295
|
if (asserts.isBox(element)) {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
296
|
+
const newBox = new Box();
|
|
297
|
+
newBox.parent = parent;
|
|
298
|
+
parent.add(newBox);
|
|
299
|
+
stack.push({ elements: element.elements, parent: newBox });
|
|
297
300
|
} else if (asserts.isGraph(element)) {
|
|
298
301
|
const el = element.clone();
|
|
299
302
|
el.parent = parent;
|
|
300
|
-
|
|
303
|
+
parent.add(el);
|
|
301
304
|
}
|
|
302
305
|
}
|
|
303
|
-
|
|
304
|
-
};
|
|
305
|
-
box.add(...traverse(this.elements, box));
|
|
306
|
+
}
|
|
306
307
|
}
|
|
307
308
|
return box;
|
|
308
309
|
}
|
|
@@ -350,10 +351,6 @@ class Render {
|
|
|
350
351
|
Object.assign(this.options, userOptions);
|
|
351
352
|
writeBoundingRectForCanvas(this.canvas, this.options.width, this.options.height, this.options.devicePixelRatio);
|
|
352
353
|
}
|
|
353
|
-
update(schedule) {
|
|
354
|
-
this.clear(this.options.width, this.options.height);
|
|
355
|
-
schedule.execute(this);
|
|
356
|
-
}
|
|
357
354
|
destory() {
|
|
358
355
|
}
|
|
359
356
|
}
|
|
@@ -396,10 +393,14 @@ class Layer extends C {
|
|
|
396
393
|
Object.assign(this.options, options);
|
|
397
394
|
writeBoundingRectForCanvas(this.c.c.canvas, options.width || 0, options.height || 0, options.devicePixelRatio || 1);
|
|
398
395
|
}
|
|
399
|
-
|
|
396
|
+
cleanCacheSnapshot() {
|
|
400
397
|
const dpr = this.options.devicePixelRatio || 1;
|
|
401
398
|
const matrix = this.matrix.create({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
|
|
402
399
|
this.ctx.clearRect(0, 0, this.options.width, this.options.height);
|
|
400
|
+
return { dpr, matrix };
|
|
401
|
+
}
|
|
402
|
+
setCacheSnapshot(c) {
|
|
403
|
+
const { matrix, dpr } = this.cleanCacheSnapshot();
|
|
403
404
|
matrix.transform(this.x, this.y, this.scaleX, this.scaleY, this.rotation, this.skewX, this.skewY);
|
|
404
405
|
applyCanvasTransform(this.ctx, matrix, dpr);
|
|
405
406
|
this.ctx.drawImage(c, 0, 0, this.options.width / dpr, this.options.height / dpr);
|
|
@@ -455,7 +456,7 @@ const runtime = {
|
|
|
455
456
|
|
|
456
457
|
var __defProp$5 = Object.defineProperty;
|
|
457
458
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
458
|
-
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
|
|
459
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
459
460
|
class Rect extends Graph {
|
|
460
461
|
constructor(options = {}) {
|
|
461
462
|
super(options);
|
|
@@ -513,7 +514,7 @@ class Text extends Graph {
|
|
|
513
514
|
|
|
514
515
|
var __defProp$3 = Object.defineProperty;
|
|
515
516
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
516
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, key + "" , value);
|
|
517
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
517
518
|
class Event {
|
|
518
519
|
constructor() {
|
|
519
520
|
__publicField$3(this, "eventCollections");
|
|
@@ -603,7 +604,8 @@ class Schedule extends Box {
|
|
|
603
604
|
this.render = new Render(this.to, renderOptions);
|
|
604
605
|
}
|
|
605
606
|
update() {
|
|
606
|
-
this.render.
|
|
607
|
+
this.render.clear(this.render.options.width, this.render.options.height);
|
|
608
|
+
this.execute(this.render, this);
|
|
607
609
|
const matrix = this.matrix.create({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
|
|
608
610
|
applyCanvasTransform(this.render.ctx, matrix, this.render.options.devicePixelRatio);
|
|
609
611
|
}
|
|
@@ -771,7 +773,7 @@ function visit(data, fn) {
|
|
|
771
773
|
}
|
|
772
774
|
return null;
|
|
773
775
|
}
|
|
774
|
-
function findRelativeNode(
|
|
776
|
+
function findRelativeNode(p, layoutNodes) {
|
|
775
777
|
return visit(layoutNodes, (node) => {
|
|
776
778
|
const [x, y, w, h] = node.layout;
|
|
777
779
|
if (p.x >= x && p.y >= y && p.x < x + w && p.y < y + h) {
|
|
@@ -908,6 +910,11 @@ var __defProp$1 = Object.defineProperty;
|
|
|
908
910
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
909
911
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
910
912
|
const primitiveEvents = ["click", "mousedown", "mousemove", "mouseup", "mouseover", "mouseout"];
|
|
913
|
+
const internalEventMappings = {
|
|
914
|
+
CLEAN_UP: "self:cleanup",
|
|
915
|
+
ON_LOAD: "self:onload",
|
|
916
|
+
ON_ZOOM: "zoom"
|
|
917
|
+
};
|
|
911
918
|
const fill = { desc: { r: 255, g: 255, b: 255 }, mode: "rgb" };
|
|
912
919
|
function smoothDrawing(c) {
|
|
913
920
|
const { self } = c;
|
|
@@ -941,7 +948,7 @@ function smoothDrawing(c) {
|
|
|
941
948
|
}
|
|
942
949
|
}
|
|
943
950
|
function applyZoomEvent(ctx) {
|
|
944
|
-
ctx.treemap.event.on(
|
|
951
|
+
ctx.treemap.event.on(internalEventMappings.ON_ZOOM, (node) => {
|
|
945
952
|
const root = null;
|
|
946
953
|
if (ctx.self.isDragging) return;
|
|
947
954
|
onZoom(ctx, node, root);
|
|
@@ -989,7 +996,7 @@ function bindPrimitiveEvent(c, ctx, evt, bus) {
|
|
|
989
996
|
);
|
|
990
997
|
const event = {
|
|
991
998
|
native: e,
|
|
992
|
-
module: findRelativeNode(
|
|
999
|
+
module: findRelativeNode({ x, y }, treemap.layoutNodes)
|
|
993
1000
|
};
|
|
994
1001
|
bus.emit(evt, event);
|
|
995
1002
|
};
|
|
@@ -1048,7 +1055,7 @@ class SelfEvent extends RegisterModule {
|
|
|
1048
1055
|
this.self.highlight.reset();
|
|
1049
1056
|
this.self.highlight.setDisplayLayerForHighlight();
|
|
1050
1057
|
this.self.event.off("mousemove", this.self.onmousemove);
|
|
1051
|
-
this.treemap.event.off(
|
|
1058
|
+
this.treemap.event.off(internalEventMappings.ON_ZOOM);
|
|
1052
1059
|
this.self.forceDestroy = true;
|
|
1053
1060
|
const { native } = metadata;
|
|
1054
1061
|
const x = native.offsetX;
|
|
@@ -1063,7 +1070,6 @@ class SelfEvent extends RegisterModule {
|
|
|
1063
1070
|
refreshBackgroundLayer(this);
|
|
1064
1071
|
}
|
|
1065
1072
|
this.treemap.reset();
|
|
1066
|
-
stackMatrixTransform(this.treemap.backgroundLayer, 0, 0, 0);
|
|
1067
1073
|
stackMatrixTransformWithGraphAndLayer(this.treemap.elements, this.self.translateX, this.self.translateY, this.self.scaleRatio);
|
|
1068
1074
|
this.treemap.update();
|
|
1069
1075
|
}
|
|
@@ -1108,7 +1114,6 @@ class SelfEvent extends RegisterModule {
|
|
|
1108
1114
|
treemap.reset();
|
|
1109
1115
|
this.self.highlight.reset();
|
|
1110
1116
|
this.self.highlight.setDisplayLayerForHighlight();
|
|
1111
|
-
stackMatrixTransform(this.treemap.backgroundLayer, 0, 0, 0);
|
|
1112
1117
|
const factor = absWheelDelta > 3 ? 1.4 : absWheelDelta > 1 ? 1.2 : 1.1;
|
|
1113
1118
|
const delta = wheelDelta > 0 ? factor : 1 / factor;
|
|
1114
1119
|
self.scaleRatio *= delta;
|
|
@@ -1149,7 +1154,7 @@ class SelfEvent extends RegisterModule {
|
|
|
1149
1154
|
selfEvt("wheel", this.onwheel);
|
|
1150
1155
|
applyZoomEvent({ treemap, self: this });
|
|
1151
1156
|
let installHightlightEvent = false;
|
|
1152
|
-
treemap.event.on(
|
|
1157
|
+
treemap.event.on(internalEventMappings.ON_LOAD, (width, height, root) => {
|
|
1153
1158
|
this.highlight.init(width, height, root);
|
|
1154
1159
|
if (!installHightlightEvent) {
|
|
1155
1160
|
bindPrimitiveEvent(this.highlight.highlight.render.canvas, { treemap, self: this }, "mousemove", event);
|
|
@@ -1161,7 +1166,7 @@ class SelfEvent extends RegisterModule {
|
|
|
1161
1166
|
}
|
|
1162
1167
|
this.highlight.reset();
|
|
1163
1168
|
});
|
|
1164
|
-
treemap.event.on(
|
|
1169
|
+
treemap.event.on(internalEventMappings.CLEAN_UP, () => {
|
|
1165
1170
|
this.currentNode = null;
|
|
1166
1171
|
this.scaleRatio = 1;
|
|
1167
1172
|
this.translateX = 0;
|
|
@@ -1214,6 +1219,10 @@ function onZoom(ctx, node, root) {
|
|
|
1214
1219
|
const c = treemap.render.canvas;
|
|
1215
1220
|
const boundingClientRect = c.getBoundingClientRect();
|
|
1216
1221
|
const [w, h] = estimateZoomingArea(node, root, boundingClientRect.width, boundingClientRect.height);
|
|
1222
|
+
if (self.layoutHeight !== w || self.layoutHeight !== h) {
|
|
1223
|
+
delete treemap.fontsCaches[node.node.id];
|
|
1224
|
+
delete treemap.ellispsisWidthCache[node.node.id];
|
|
1225
|
+
}
|
|
1217
1226
|
resetLayout(treemap, w, h);
|
|
1218
1227
|
const module = findRelativeNodeById(node.node.id, treemap.layoutNodes);
|
|
1219
1228
|
if (module) {
|
|
@@ -1226,10 +1235,6 @@ function onZoom(ctx, node, root) {
|
|
|
1226
1235
|
const initialTranslateY = self.translateY;
|
|
1227
1236
|
const startTime = Date.now();
|
|
1228
1237
|
const animationDuration = 300;
|
|
1229
|
-
if (self.layoutHeight !== w || self.layoutHeight !== h) {
|
|
1230
|
-
delete treemap.fontsCaches[module.node.id];
|
|
1231
|
-
delete treemap.ellispsisWidthCache[module.node.id];
|
|
1232
|
-
}
|
|
1233
1238
|
const { run, stop } = createEffectScope();
|
|
1234
1239
|
run(() => {
|
|
1235
1240
|
const elapsed = Date.now() - startTime;
|
|
@@ -1288,9 +1293,24 @@ function createHighlight() {
|
|
|
1288
1293
|
};
|
|
1289
1294
|
}
|
|
1290
1295
|
function refreshBackgroundLayer(c) {
|
|
1291
|
-
const { treemap } = c;
|
|
1292
|
-
const { backgroundLayer } = treemap;
|
|
1296
|
+
const { treemap, self } = c;
|
|
1297
|
+
const { backgroundLayer, render } = treemap;
|
|
1298
|
+
const { canvas, ctx, options: { width: ow, height: oh } } = render;
|
|
1299
|
+
const { layoutWidth: sw, layoutHeight: sh, scaleRatio: ss } = self;
|
|
1300
|
+
const capture = sw * ss >= ow && sh * ss >= oh;
|
|
1293
1301
|
backgroundLayer.__refresh__ = false;
|
|
1302
|
+
if (!capture && !self.forceDestroy) {
|
|
1303
|
+
resetLayout(treemap, sw * ss, sh * ss);
|
|
1304
|
+
render.clear(ow, oh);
|
|
1305
|
+
const { dpr } = backgroundLayer.cleanCacheSnapshot();
|
|
1306
|
+
drawGraphIntoCanvas(backgroundLayer, { c: canvas, ctx, dpr }, (opts, graph) => {
|
|
1307
|
+
if (asserts.isLayer(graph) && !graph.__refresh__) {
|
|
1308
|
+
graph.setCacheSnapshot(opts.c);
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
self.triggerZoom = false;
|
|
1312
|
+
return true;
|
|
1313
|
+
}
|
|
1294
1314
|
}
|
|
1295
1315
|
|
|
1296
1316
|
var __defProp = Object.defineProperty;
|
|
@@ -1417,6 +1437,8 @@ class TreemapLayout extends etoile.Schedule {
|
|
|
1417
1437
|
for (const node of this.layoutNodes) {
|
|
1418
1438
|
this.drawBackgroundNode(node);
|
|
1419
1439
|
}
|
|
1440
|
+
} else {
|
|
1441
|
+
this.bgLayer.initLoc();
|
|
1420
1442
|
}
|
|
1421
1443
|
if (!this.fgBox.elements.length || refresh) {
|
|
1422
1444
|
this.render.ctx.textBaseline = "middle";
|
|
@@ -1432,7 +1454,7 @@ class TreemapLayout extends etoile.Schedule {
|
|
|
1432
1454
|
get api() {
|
|
1433
1455
|
return {
|
|
1434
1456
|
zoom: (node) => {
|
|
1435
|
-
this.event.emit(
|
|
1457
|
+
this.event.emit(internalEventMappings.ON_ZOOM, node);
|
|
1436
1458
|
}
|
|
1437
1459
|
};
|
|
1438
1460
|
}
|
|
@@ -1482,8 +1504,8 @@ function createTreemap() {
|
|
|
1482
1504
|
treemap.backgroundLayer.initLoc();
|
|
1483
1505
|
treemap.backgroundLayer.matrix = treemap.backgroundLayer.matrix.create({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
|
|
1484
1506
|
treemap.fontsCaches = /* @__PURE__ */ Object.create(null);
|
|
1485
|
-
treemap.event.emit(
|
|
1486
|
-
treemap.event.emit(
|
|
1507
|
+
treemap.event.emit(internalEventMappings.CLEAN_UP);
|
|
1508
|
+
treemap.event.emit(internalEventMappings.ON_LOAD, width, height, root);
|
|
1487
1509
|
resetLayout(treemap, width, height);
|
|
1488
1510
|
treemap.update();
|
|
1489
1511
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squarified",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "squarified tree map",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
10
|
+
"squarified/__source__": "./src/index.ts",
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
}
|
|
@@ -16,11 +16,6 @@
|
|
|
16
16
|
"squarified",
|
|
17
17
|
"tree-map"
|
|
18
18
|
],
|
|
19
|
-
"files": [
|
|
20
|
-
"dist",
|
|
21
|
-
"LICENSE",
|
|
22
|
-
"README.md"
|
|
23
|
-
],
|
|
24
19
|
"repository": {
|
|
25
20
|
"type": "git",
|
|
26
21
|
"url": "git+https://github.com/nonzzz/squarified.git"
|
|
@@ -33,7 +28,18 @@
|
|
|
33
28
|
"esbuild": "^0.24.0",
|
|
34
29
|
"eslint": "8",
|
|
35
30
|
"eslint-config-kagura": "^2.2.1",
|
|
36
|
-
"jiek": "^
|
|
31
|
+
"jiek": "^2.1.11",
|
|
37
32
|
"typescript": "^5.6.2"
|
|
33
|
+
},
|
|
34
|
+
"typesVersions": {
|
|
35
|
+
"<5.0": {
|
|
36
|
+
"*": [
|
|
37
|
+
"*",
|
|
38
|
+
"./*",
|
|
39
|
+
"./*/index.d.ts",
|
|
40
|
+
"./*/index.d.mts",
|
|
41
|
+
"./*/index.d.cts"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
}
|