squarified 0.1.0 → 0.1.1
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.ts +9 -1
- package/dist/index.js +20 -6
- package/dist/index.mjs +16 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -222,6 +222,13 @@ type NativeModule = ReturnType<typeof bindParentForModule>[number] & {
|
|
|
222
222
|
parent: NativeModule;
|
|
223
223
|
groups: NativeModule[];
|
|
224
224
|
};
|
|
225
|
+
declare function getNodeDepth(node: NativeModule): number;
|
|
226
|
+
declare function visit<T extends AnyObject>(data: T[], fn: (data: T) => boolean | void): T | null;
|
|
227
|
+
declare function findRelativeNode(c: HTMLCanvasElement, p: {
|
|
228
|
+
x: number;
|
|
229
|
+
y: number;
|
|
230
|
+
}, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
231
|
+
declare function findRelativeNodeById(id: string, layoutNodes: LayoutModule[]): LayoutModule | null;
|
|
225
232
|
|
|
226
233
|
type LayoutModule = {
|
|
227
234
|
node: NativeModule;
|
|
@@ -260,6 +267,7 @@ interface App {
|
|
|
260
267
|
setOptions: (options: TreemapOptions) => void;
|
|
261
268
|
resize: () => void;
|
|
262
269
|
use: (using: Using, register: (app: TreemapLayout) => void) => void;
|
|
270
|
+
zoom: (id: string) => void;
|
|
263
271
|
}
|
|
264
272
|
declare class Schedule extends etoile.Schedule {
|
|
265
273
|
}
|
|
@@ -280,4 +288,4 @@ declare class TreemapLayout extends Schedule {
|
|
|
280
288
|
declare function createTreemap(): App & EventMethods;
|
|
281
289
|
type TreemapInstanceAPI = TreemapLayout['api'];
|
|
282
290
|
|
|
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 };
|
|
291
|
+
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.js
CHANGED
|
@@ -1082,9 +1082,6 @@ function onZoom(ctx, node, root) {
|
|
|
1082
1082
|
const startTime = Date.now();
|
|
1083
1083
|
const animationDuration = 300;
|
|
1084
1084
|
const draw = ()=>{
|
|
1085
|
-
if (self.forceDestroy) {
|
|
1086
|
-
return;
|
|
1087
|
-
}
|
|
1088
1085
|
const elapsed = Date.now() - startTime;
|
|
1089
1086
|
const progress = Math.min(elapsed / animationDuration, 1);
|
|
1090
1087
|
const easedProgress = easing.cubicInOut(progress);
|
|
@@ -1301,13 +1298,15 @@ class TreemapLayout extends Schedule {
|
|
|
1301
1298
|
function createTreemap() {
|
|
1302
1299
|
let treemap = null;
|
|
1303
1300
|
let root = null;
|
|
1301
|
+
let installed = false;
|
|
1304
1302
|
const uses = [];
|
|
1305
1303
|
const context = {
|
|
1306
1304
|
init,
|
|
1307
1305
|
dispose,
|
|
1308
1306
|
setOptions,
|
|
1309
1307
|
resize,
|
|
1310
|
-
use
|
|
1308
|
+
use,
|
|
1309
|
+
zoom
|
|
1311
1310
|
};
|
|
1312
1311
|
function init(el) {
|
|
1313
1312
|
treemap = new TreemapLayout(el);
|
|
@@ -1338,8 +1337,11 @@ function createTreemap() {
|
|
|
1338
1337
|
throw new Error('Treemap not initialized');
|
|
1339
1338
|
}
|
|
1340
1339
|
treemap.data = bindParentForModule(options.data || []);
|
|
1341
|
-
|
|
1342
|
-
|
|
1340
|
+
if (!installed) {
|
|
1341
|
+
for (const registry of defaultRegistries){
|
|
1342
|
+
registry(context, treemap, treemap.render);
|
|
1343
|
+
}
|
|
1344
|
+
installed = true;
|
|
1343
1345
|
}
|
|
1344
1346
|
for (const use of uses){
|
|
1345
1347
|
use(treemap);
|
|
@@ -1353,6 +1355,13 @@ function createTreemap() {
|
|
|
1353
1355
|
break;
|
|
1354
1356
|
}
|
|
1355
1357
|
}
|
|
1358
|
+
function zoom(id) {
|
|
1359
|
+
if (!treemap) {
|
|
1360
|
+
throw new Error("treemap don't init.");
|
|
1361
|
+
}
|
|
1362
|
+
const node = findRelativeNodeById(id, treemap.layoutNodes);
|
|
1363
|
+
node && treemap.api.zoom(node);
|
|
1364
|
+
}
|
|
1356
1365
|
return context;
|
|
1357
1366
|
}
|
|
1358
1367
|
|
|
@@ -1429,10 +1438,15 @@ function colorMappings(app) {
|
|
|
1429
1438
|
};
|
|
1430
1439
|
}
|
|
1431
1440
|
|
|
1441
|
+
exports.TreemapLayout = TreemapLayout;
|
|
1432
1442
|
exports.c2m = c2m;
|
|
1433
1443
|
exports.createTreemap = createTreemap;
|
|
1434
1444
|
exports.defaultFontOptions = defaultFontOptions;
|
|
1435
1445
|
exports.defaultLayoutOptions = defaultLayoutOptions;
|
|
1446
|
+
exports.findRelativeNode = findRelativeNode;
|
|
1447
|
+
exports.findRelativeNodeById = findRelativeNodeById;
|
|
1436
1448
|
exports.flattenModule = flatten;
|
|
1449
|
+
exports.getNodeDepth = getNodeDepth;
|
|
1437
1450
|
exports.presetDecorator = presetDecorator;
|
|
1438
1451
|
exports.sortChildrenByKey = sortChildrenByKey;
|
|
1452
|
+
exports.visit = visit;
|
package/dist/index.mjs
CHANGED
|
@@ -1080,9 +1080,6 @@ function onZoom(ctx, node, root) {
|
|
|
1080
1080
|
const startTime = Date.now();
|
|
1081
1081
|
const animationDuration = 300;
|
|
1082
1082
|
const draw = ()=>{
|
|
1083
|
-
if (self.forceDestroy) {
|
|
1084
|
-
return;
|
|
1085
|
-
}
|
|
1086
1083
|
const elapsed = Date.now() - startTime;
|
|
1087
1084
|
const progress = Math.min(elapsed / animationDuration, 1);
|
|
1088
1085
|
const easedProgress = easing.cubicInOut(progress);
|
|
@@ -1299,13 +1296,15 @@ class TreemapLayout extends Schedule {
|
|
|
1299
1296
|
function createTreemap() {
|
|
1300
1297
|
let treemap = null;
|
|
1301
1298
|
let root = null;
|
|
1299
|
+
let installed = false;
|
|
1302
1300
|
const uses = [];
|
|
1303
1301
|
const context = {
|
|
1304
1302
|
init,
|
|
1305
1303
|
dispose,
|
|
1306
1304
|
setOptions,
|
|
1307
1305
|
resize,
|
|
1308
|
-
use
|
|
1306
|
+
use,
|
|
1307
|
+
zoom
|
|
1309
1308
|
};
|
|
1310
1309
|
function init(el) {
|
|
1311
1310
|
treemap = new TreemapLayout(el);
|
|
@@ -1336,8 +1335,11 @@ function createTreemap() {
|
|
|
1336
1335
|
throw new Error('Treemap not initialized');
|
|
1337
1336
|
}
|
|
1338
1337
|
treemap.data = bindParentForModule(options.data || []);
|
|
1339
|
-
|
|
1340
|
-
|
|
1338
|
+
if (!installed) {
|
|
1339
|
+
for (const registry of defaultRegistries){
|
|
1340
|
+
registry(context, treemap, treemap.render);
|
|
1341
|
+
}
|
|
1342
|
+
installed = true;
|
|
1341
1343
|
}
|
|
1342
1344
|
for (const use of uses){
|
|
1343
1345
|
use(treemap);
|
|
@@ -1351,6 +1353,13 @@ function createTreemap() {
|
|
|
1351
1353
|
break;
|
|
1352
1354
|
}
|
|
1353
1355
|
}
|
|
1356
|
+
function zoom(id) {
|
|
1357
|
+
if (!treemap) {
|
|
1358
|
+
throw new Error("treemap don't init.");
|
|
1359
|
+
}
|
|
1360
|
+
const node = findRelativeNodeById(id, treemap.layoutNodes);
|
|
1361
|
+
node && treemap.api.zoom(node);
|
|
1362
|
+
}
|
|
1354
1363
|
return context;
|
|
1355
1364
|
}
|
|
1356
1365
|
|
|
@@ -1427,4 +1436,4 @@ function colorMappings(app) {
|
|
|
1427
1436
|
};
|
|
1428
1437
|
}
|
|
1429
1438
|
|
|
1430
|
-
export { c2m, createTreemap, defaultFontOptions, defaultLayoutOptions, flatten as flattenModule, presetDecorator, sortChildrenByKey };
|
|
1439
|
+
export { TreemapLayout, c2m, createTreemap, defaultFontOptions, defaultLayoutOptions, findRelativeNode, findRelativeNodeById, flatten as flattenModule, getNodeDepth, presetDecorator, sortChildrenByKey, visit };
|