squarified 0.5.0 → 0.6.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/README.md +235 -10
- package/dist/{dom-event-Bkw3ecGf.mjs → dom-event-CKb3Ko4-.mjs} +151 -92
- package/dist/{dom-event-Dz0I7Z12.js → dom-event-CxIxc4YC.js} +150 -94
- package/dist/{index-Dskgz6nc.d.ts → index-Bb8ZzMCD.d.ts} +37 -38
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -8
- package/dist/index.mjs +4 -7
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +47 -27
- package/dist/plugin.mjs +47 -27
- package/package.json +2 -2
|
@@ -90,7 +90,6 @@ var DisplayType = /*#__PURE__*/ function(DisplayType) {
|
|
|
90
90
|
DisplayType["Box"] = "Box";
|
|
91
91
|
DisplayType["Text"] = "Text";
|
|
92
92
|
DisplayType["RoundRect"] = "RoundRect";
|
|
93
|
-
DisplayType["Bitmap"] = "Bitmap";
|
|
94
93
|
return DisplayType;
|
|
95
94
|
}({});
|
|
96
95
|
class Display {
|
|
@@ -293,12 +292,10 @@ class S extends Display {
|
|
|
293
292
|
class Graph extends S {
|
|
294
293
|
instruction;
|
|
295
294
|
__options__;
|
|
296
|
-
__widget__;
|
|
297
295
|
constructor(options = {}){
|
|
298
296
|
super(options);
|
|
299
297
|
this.instruction = createInstruction();
|
|
300
298
|
this.__options__ = options;
|
|
301
|
-
this.__widget__ = null;
|
|
302
299
|
}
|
|
303
300
|
render(ctx) {
|
|
304
301
|
this.create();
|
|
@@ -335,15 +332,11 @@ function isRoundRect(display) {
|
|
|
335
332
|
function isText(display) {
|
|
336
333
|
return isGraph(display) && display.__shape__ === DisplayType.Text;
|
|
337
334
|
}
|
|
338
|
-
function isBitmap(display) {
|
|
339
|
-
return isGraph(display) && display.__shape__ === DisplayType.Bitmap;
|
|
340
|
-
}
|
|
341
335
|
const asserts = {
|
|
342
336
|
isGraph,
|
|
343
337
|
isBox,
|
|
344
338
|
isText,
|
|
345
|
-
isRoundRect
|
|
346
|
-
isBitmap
|
|
339
|
+
isRoundRect
|
|
347
340
|
};
|
|
348
341
|
|
|
349
342
|
class C extends Display {
|
|
@@ -743,16 +736,6 @@ function applyCanvasTransform(ctx, matrix, dpr) {
|
|
|
743
736
|
ctx.setTransform(matrix.a * dpr, matrix.b * dpr, matrix.c * dpr, matrix.d * dpr, matrix.e * dpr, matrix.f * dpr);
|
|
744
737
|
}
|
|
745
738
|
function mixin(app, methods) {
|
|
746
|
-
methods.forEach(({ name, fn })=>{
|
|
747
|
-
Object.defineProperty(app, name, {
|
|
748
|
-
value: fn(app),
|
|
749
|
-
writable: false
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
// @ts-expect-error not
|
|
753
|
-
return app;
|
|
754
|
-
}
|
|
755
|
-
function mixinWithParams(app, methods) {
|
|
756
739
|
methods.forEach(({ name, fn })=>{
|
|
757
740
|
Object.defineProperty(app, name, {
|
|
758
741
|
value: fn(app),
|
|
@@ -762,12 +745,6 @@ function mixinWithParams(app, methods) {
|
|
|
762
745
|
});
|
|
763
746
|
return app;
|
|
764
747
|
}
|
|
765
|
-
function prettyStrJoin(...s) {
|
|
766
|
-
return s.join('');
|
|
767
|
-
}
|
|
768
|
-
function isMacOS() {
|
|
769
|
-
return /Mac OS X/.test(navigator.userAgent);
|
|
770
|
-
}
|
|
771
748
|
function typedForIn(obj, callback) {
|
|
772
749
|
for(const key in obj){
|
|
773
750
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -1127,12 +1104,15 @@ function squarify(data, rect, config, scale = 1) {
|
|
|
1127
1104
|
if (!processedData.length) {
|
|
1128
1105
|
return result;
|
|
1129
1106
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1107
|
+
let workingRect = rect;
|
|
1108
|
+
if (scaledGap > 0) {
|
|
1109
|
+
workingRect = {
|
|
1110
|
+
x: rect.x + scaledGap / 2,
|
|
1111
|
+
y: rect.y + scaledGap / 2,
|
|
1112
|
+
w: Math.max(0, rect.w - scaledGap),
|
|
1113
|
+
h: Math.max(0, rect.h - scaledGap)
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1136
1116
|
const worst = (start, end, shortestSide, totalWeight, aspectRatio)=>{
|
|
1137
1117
|
const max = processedData[start].weight * aspectRatio;
|
|
1138
1118
|
const min = processedData[end].weight * aspectRatio;
|
|
@@ -1184,39 +1164,43 @@ function squarify(data, rect, config, scale = 1) {
|
|
|
1184
1164
|
w = upper - lower;
|
|
1185
1165
|
h = splited;
|
|
1186
1166
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
if (
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1167
|
+
if (currentGap > 0) {
|
|
1168
|
+
const edgeGap = currentGap / 2;
|
|
1169
|
+
if (!isFirst) {
|
|
1170
|
+
if (isHorizontalLayout) {
|
|
1171
|
+
y += edgeGap;
|
|
1172
|
+
h = Math.max(0, h - edgeGap);
|
|
1173
|
+
} else {
|
|
1174
|
+
x += edgeGap;
|
|
1175
|
+
w = Math.max(0, w - edgeGap);
|
|
1176
|
+
}
|
|
1195
1177
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1178
|
+
if (!isLast) {
|
|
1179
|
+
if (isHorizontalLayout) {
|
|
1180
|
+
h = Math.max(0, h - edgeGap);
|
|
1181
|
+
} else {
|
|
1182
|
+
w = Math.max(0, w - edgeGap);
|
|
1183
|
+
}
|
|
1202
1184
|
}
|
|
1203
1185
|
}
|
|
1204
1186
|
const nodeDepth = getNodeDepth(children) || 1;
|
|
1205
1187
|
const { titleAreaHeight } = config;
|
|
1206
1188
|
const diff = titleAreaHeight.max / nodeDepth;
|
|
1207
1189
|
const titleHeight = diff < titleAreaHeight.min ? titleAreaHeight.min : diff;
|
|
1208
|
-
w = Math.max(
|
|
1209
|
-
h = Math.max(
|
|
1190
|
+
w = Math.max(1, w);
|
|
1191
|
+
h = Math.max(1, h);
|
|
1210
1192
|
let childrenLayout = [];
|
|
1211
1193
|
const hasValidChildren = children.groups && children.groups.length > 0;
|
|
1212
1194
|
if (hasValidChildren) {
|
|
1195
|
+
const childGapOffset = currentGap > 0 ? currentGap : 0;
|
|
1213
1196
|
const childRect = {
|
|
1214
|
-
x: x +
|
|
1197
|
+
x: x + childGapOffset,
|
|
1215
1198
|
y: y + titleHeight,
|
|
1216
|
-
w: Math.max(0, w -
|
|
1217
|
-
h: Math.max(0, h - titleHeight -
|
|
1199
|
+
w: Math.max(0, w - childGapOffset * 2),
|
|
1200
|
+
h: Math.max(0, h - titleHeight - childGapOffset)
|
|
1218
1201
|
};
|
|
1219
|
-
|
|
1202
|
+
const minChildSize = currentRadius > 0 ? currentRadius * 2 : 1;
|
|
1203
|
+
if (childRect.w >= minChildSize && childRect.h >= minChildSize) {
|
|
1220
1204
|
childrenLayout = squarify(children.groups || [], childRect, {
|
|
1221
1205
|
...config,
|
|
1222
1206
|
rectGap: currentGap,
|
|
@@ -1242,16 +1226,17 @@ function squarify(data, rect, config, scale = 1) {
|
|
|
1242
1226
|
areaInLayout += area;
|
|
1243
1227
|
}
|
|
1244
1228
|
start = end;
|
|
1229
|
+
const rectGapOffset = currentGap > 0 ? currentGap : 0;
|
|
1245
1230
|
if (isHorizontalLayout) {
|
|
1246
|
-
rect.x += splited +
|
|
1247
|
-
rect.w
|
|
1231
|
+
rect.x += splited + rectGapOffset;
|
|
1232
|
+
rect.w = Math.max(0, rect.w - splited - rectGapOffset);
|
|
1248
1233
|
} else {
|
|
1249
|
-
rect.y += splited +
|
|
1250
|
-
rect.h
|
|
1234
|
+
rect.y += splited + rectGapOffset;
|
|
1235
|
+
rect.h = Math.max(0, rect.h - splited - rectGapOffset);
|
|
1251
1236
|
}
|
|
1252
1237
|
}
|
|
1253
1238
|
};
|
|
1254
|
-
recursion(0,
|
|
1239
|
+
recursion(0, workingRect);
|
|
1255
1240
|
return result;
|
|
1256
1241
|
}
|
|
1257
1242
|
|
|
@@ -1298,6 +1283,7 @@ class PluginDriver {
|
|
|
1298
1283
|
this.plugins.forEach((plugin)=>{
|
|
1299
1284
|
const hook = plugin[hookName];
|
|
1300
1285
|
if (hook) {
|
|
1286
|
+
// @ts-expect-error fixme
|
|
1301
1287
|
const hookResult = hook.call(this.pluginContext, ...args);
|
|
1302
1288
|
if (hookResult) {
|
|
1303
1289
|
Object.assign(finalResult, hookResult);
|
|
@@ -1353,6 +1339,65 @@ class Component extends Schedule {
|
|
|
1353
1339
|
this.caches = new DefaultMap(()=>14);
|
|
1354
1340
|
this.layoutNodes = [];
|
|
1355
1341
|
}
|
|
1342
|
+
clearFontCacheInAABB(aabb) {
|
|
1343
|
+
const affectedModules = this.getModulesInAABB(this.layoutNodes, aabb);
|
|
1344
|
+
for (const module of affectedModules){
|
|
1345
|
+
this.caches.delete(module.node.id);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
getModulesInAABB(modules, aabb) {
|
|
1349
|
+
const result = [];
|
|
1350
|
+
for (const module of modules){
|
|
1351
|
+
const [x, y, w, h] = module.layout;
|
|
1352
|
+
const moduleAABB = {
|
|
1353
|
+
x,
|
|
1354
|
+
y,
|
|
1355
|
+
width: w,
|
|
1356
|
+
height: h
|
|
1357
|
+
};
|
|
1358
|
+
if (this.isAABBIntersecting(moduleAABB, aabb)) {
|
|
1359
|
+
result.push(module);
|
|
1360
|
+
if (module.children && module.children.length > 0) {
|
|
1361
|
+
result.push(...this.getModulesInAABB(module.children, aabb));
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
return result;
|
|
1366
|
+
}
|
|
1367
|
+
getViewportAABB(matrixE, matrixF, scale) {
|
|
1368
|
+
const { width, height } = this.render.options;
|
|
1369
|
+
const worldX = -matrixE / scale;
|
|
1370
|
+
const worldY = -matrixF / scale;
|
|
1371
|
+
const worldWidth = width / scale;
|
|
1372
|
+
const worldHeight = height / scale;
|
|
1373
|
+
return {
|
|
1374
|
+
x: worldX,
|
|
1375
|
+
y: worldY,
|
|
1376
|
+
width: worldWidth,
|
|
1377
|
+
height: worldHeight
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
getAABBUnion(a, b) {
|
|
1381
|
+
const minX = Math.min(a.x, b.x);
|
|
1382
|
+
const minY = Math.min(a.y, b.y);
|
|
1383
|
+
const maxX = Math.max(a.x + a.width, b.x + b.width);
|
|
1384
|
+
const maxY = Math.max(a.y + a.height, b.y + b.height);
|
|
1385
|
+
return {
|
|
1386
|
+
x: minX,
|
|
1387
|
+
y: minY,
|
|
1388
|
+
width: maxX - minX,
|
|
1389
|
+
height: maxY - minY
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
handleTransformCacheInvalidation(oldMatrix, newMatrix) {
|
|
1393
|
+
const oldViewportAABB = this.getViewportAABB(oldMatrix.e, oldMatrix.f, oldMatrix.a);
|
|
1394
|
+
const newViewportAABB = this.getViewportAABB(newMatrix.e, newMatrix.f, newMatrix.a);
|
|
1395
|
+
const affectedAABB = this.getAABBUnion(oldViewportAABB, newViewportAABB);
|
|
1396
|
+
this.clearFontCacheInAABB(affectedAABB);
|
|
1397
|
+
}
|
|
1398
|
+
isAABBIntersecting(a, b) {
|
|
1399
|
+
return !(a.x + a.width < b.x || b.x + b.width < a.x || a.y + a.height < b.y || b.y + b.height < a.y);
|
|
1400
|
+
}
|
|
1356
1401
|
drawBroundRect(node) {
|
|
1357
1402
|
const [x, y, w, h] = node.layout;
|
|
1358
1403
|
const { rectRadius } = node.config;
|
|
@@ -1363,7 +1408,6 @@ class Component extends Schedule {
|
|
|
1363
1408
|
padding: 0,
|
|
1364
1409
|
radius: effectiveRadius
|
|
1365
1410
|
});
|
|
1366
|
-
rect.__widget__ = node;
|
|
1367
1411
|
this.rectLayer.add(rect);
|
|
1368
1412
|
for (const child of node.children){
|
|
1369
1413
|
this.drawBroundRect(child);
|
|
@@ -1437,11 +1481,16 @@ class Component extends Schedule {
|
|
|
1437
1481
|
}
|
|
1438
1482
|
calculateLayoutNodes(data, rect, scale = 1) {
|
|
1439
1483
|
const config = {
|
|
1440
|
-
titleAreaHeight: this.config.layout?.titleAreaHeight
|
|
1441
|
-
rectRadius: this.config.layout?.rectRadius
|
|
1442
|
-
rectGap: this.config.layout?.rectGap
|
|
1484
|
+
titleAreaHeight: this.config.layout?.titleAreaHeight ?? DEFAULT_TITLE_AREA_HEIGHT,
|
|
1485
|
+
rectRadius: this.config.layout?.rectRadius ?? DEFAULT_RECT_BORDER_RADIUS,
|
|
1486
|
+
rectGap: this.config.layout?.rectGap ?? DEFAULT_RECT_GAP
|
|
1443
1487
|
};
|
|
1444
|
-
|
|
1488
|
+
const layoutNodes = squarify(data, rect, config, scale);
|
|
1489
|
+
const result = this.pluginDriver.cascadeHook('onLayoutCalculated', layoutNodes, rect, config);
|
|
1490
|
+
if (result && result.layoutNodes?.length) {
|
|
1491
|
+
return result.layoutNodes;
|
|
1492
|
+
}
|
|
1493
|
+
return layoutNodes;
|
|
1445
1494
|
}
|
|
1446
1495
|
}
|
|
1447
1496
|
function evaluateOptimalFontSize(c, text, config, desiredW, desiredH) {
|
|
@@ -1450,39 +1499,25 @@ function evaluateOptimalFontSize(c, text, config, desiredW, desiredH) {
|
|
|
1450
1499
|
const { fontSize, family } = config;
|
|
1451
1500
|
let min = fontSize.min;
|
|
1452
1501
|
let max = fontSize.max;
|
|
1453
|
-
const cache = new Map();
|
|
1454
1502
|
while(max - min >= 1){
|
|
1455
1503
|
const current = min + (max - min) / 2;
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
cache.set(current, {
|
|
1462
|
-
width,
|
|
1463
|
-
height
|
|
1464
|
-
});
|
|
1465
|
-
}
|
|
1466
|
-
const { width, height } = cache.get(current);
|
|
1467
|
-
if (width > desiredW || height > desiredH) {
|
|
1468
|
-
max = current;
|
|
1469
|
-
} else {
|
|
1504
|
+
c.font = `${current}px ${family}`;
|
|
1505
|
+
const textWidth = c.measureText(text).width;
|
|
1506
|
+
const metrics = c.measureText(text);
|
|
1507
|
+
const textHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
|
|
1508
|
+
if (textWidth <= desiredW && textHeight <= desiredH) {
|
|
1470
1509
|
min = current;
|
|
1510
|
+
} else {
|
|
1511
|
+
max = current;
|
|
1471
1512
|
}
|
|
1472
1513
|
}
|
|
1473
1514
|
return Math.floor(min);
|
|
1474
1515
|
}
|
|
1475
1516
|
function getTextLayout(c, text, width, height) {
|
|
1476
|
-
const
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
valid: true,
|
|
1481
|
-
text: '...',
|
|
1482
|
-
direction: 'vertical',
|
|
1483
|
-
width: ellipsisWidth / 3
|
|
1484
|
-
};
|
|
1485
|
-
}
|
|
1517
|
+
const textWidth = c.measureText(text).width;
|
|
1518
|
+
const metrics = c.measureText(text);
|
|
1519
|
+
const textHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
|
|
1520
|
+
if (textHeight > height) {
|
|
1486
1521
|
return {
|
|
1487
1522
|
valid: false,
|
|
1488
1523
|
text: '',
|
|
@@ -1490,8 +1525,7 @@ function getTextLayout(c, text, width, height) {
|
|
|
1490
1525
|
width: 0
|
|
1491
1526
|
};
|
|
1492
1527
|
}
|
|
1493
|
-
|
|
1494
|
-
if (textWidth < width) {
|
|
1528
|
+
if (textWidth <= width) {
|
|
1495
1529
|
return {
|
|
1496
1530
|
valid: true,
|
|
1497
1531
|
text,
|
|
@@ -1499,16 +1533,41 @@ function getTextLayout(c, text, width, height) {
|
|
|
1499
1533
|
width: textWidth
|
|
1500
1534
|
};
|
|
1501
1535
|
}
|
|
1502
|
-
|
|
1536
|
+
const ellipsisWidth = c.measureText('...').width;
|
|
1537
|
+
if (width <= ellipsisWidth) {
|
|
1538
|
+
return {
|
|
1539
|
+
valid: false,
|
|
1540
|
+
text: '',
|
|
1541
|
+
direction: 'horizontal',
|
|
1542
|
+
width: 0
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
let left = 0;
|
|
1546
|
+
let right = text.length;
|
|
1547
|
+
let bestFit = '';
|
|
1548
|
+
while(left <= right){
|
|
1549
|
+
const mid = Math.floor((left + right) / 2);
|
|
1550
|
+
const substring = text.substring(0, mid);
|
|
1551
|
+
const subWidth = c.measureText(substring).width;
|
|
1552
|
+
if (subWidth + ellipsisWidth <= width) {
|
|
1553
|
+
bestFit = substring;
|
|
1554
|
+
left = mid + 1;
|
|
1555
|
+
} else {
|
|
1556
|
+
right = mid - 1;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
return bestFit.length > 0 ? {
|
|
1560
|
+
valid: true,
|
|
1561
|
+
text: bestFit + '...',
|
|
1562
|
+
direction: 'horizontal',
|
|
1563
|
+
width
|
|
1564
|
+
} : {
|
|
1503
1565
|
valid: true,
|
|
1504
1566
|
text: '...',
|
|
1505
1567
|
direction: 'horizontal',
|
|
1506
1568
|
width: ellipsisWidth
|
|
1507
1569
|
};
|
|
1508
1570
|
}
|
|
1509
|
-
function measureTextWidth(c, text) {
|
|
1510
|
-
return c.measureText(text).width;
|
|
1511
|
-
}
|
|
1512
1571
|
|
|
1513
1572
|
// I think those event is enough for user.
|
|
1514
1573
|
const DOM_EVENTS = [
|
|
@@ -1669,16 +1728,13 @@ exports.getNodeDepth = getNodeDepth;
|
|
|
1669
1728
|
exports.hashCode = hashCode;
|
|
1670
1729
|
exports.isClickEvent = isClickEvent;
|
|
1671
1730
|
exports.isContextMenuEvent = isContextMenuEvent;
|
|
1672
|
-
exports.isMacOS = isMacOS;
|
|
1673
1731
|
exports.isMouseEvent = isMouseEvent;
|
|
1674
1732
|
exports.isScrollWheelOrRightButtonOnMouseupAndDown = isScrollWheelOrRightButtonOnMouseupAndDown;
|
|
1675
1733
|
exports.isWheelEvent = isWheelEvent;
|
|
1676
1734
|
exports.logger = logger;
|
|
1677
1735
|
exports.mixin = mixin;
|
|
1678
|
-
exports.mixinWithParams = mixinWithParams;
|
|
1679
1736
|
exports.noop = noop;
|
|
1680
1737
|
exports.perferNumeric = perferNumeric;
|
|
1681
|
-
exports.prettyStrJoin = prettyStrJoin;
|
|
1682
1738
|
exports.raf = raf;
|
|
1683
1739
|
exports.smoothFrame = smoothFrame;
|
|
1684
1740
|
exports.sortChildrenByKey = sortChildrenByKey;
|
|
@@ -33,8 +33,7 @@ declare const enum DisplayType {
|
|
|
33
33
|
Graph = "Graph",
|
|
34
34
|
Box = "Box",
|
|
35
35
|
Text = "Text",
|
|
36
|
-
RoundRect = "RoundRect"
|
|
37
|
-
Bitmap = "Bitmap"
|
|
36
|
+
RoundRect = "RoundRect"
|
|
38
37
|
}
|
|
39
38
|
declare abstract class Display {
|
|
40
39
|
parent: Display | null;
|
|
@@ -106,7 +105,6 @@ declare abstract class S extends Display {
|
|
|
106
105
|
declare abstract class Graph extends S {
|
|
107
106
|
instruction: ReturnType<typeof createInstruction>;
|
|
108
107
|
__options__: Partial<LocOptions>;
|
|
109
|
-
__widget__: Any;
|
|
110
108
|
abstract style: GraphStyleSheet;
|
|
111
109
|
constructor(options?: Partial<GraphOptions>);
|
|
112
110
|
abstract create(): void;
|
|
@@ -262,16 +260,6 @@ interface GraphicConfig {
|
|
|
262
260
|
layout?: GraphicLayout;
|
|
263
261
|
font?: GraphicFont;
|
|
264
262
|
}
|
|
265
|
-
/**
|
|
266
|
-
* @deprecated `TreemapInstanceAPI` don't provide methods anymore. (will be removed in the future versions)
|
|
267
|
-
* Keep it only for migration convenience
|
|
268
|
-
*/
|
|
269
|
-
interface TreemapInstanceAPI {
|
|
270
|
-
/**
|
|
271
|
-
* @deprecated don't call this method anymore.
|
|
272
|
-
*/
|
|
273
|
-
zoom: () => void;
|
|
274
|
-
}
|
|
275
263
|
|
|
276
264
|
declare function sortChildrenByKey<T extends AnyObject, K extends keyof T = 'weight'>(data: T[], ...keys: K[]): T[];
|
|
277
265
|
declare function c2m<T extends AnyObject & {
|
|
@@ -332,14 +320,6 @@ declare function createTitleText(text: string, x: number, y: number, font: strin
|
|
|
332
320
|
declare const raf: ((callback: FrameRequestCallback) => number) & typeof requestAnimationFrame;
|
|
333
321
|
declare function createCanvasElement(): HTMLCanvasElement;
|
|
334
322
|
declare function applyCanvasTransform(ctx: CanvasRenderingContext2D, matrix: Matrix2D, dpr: number): void;
|
|
335
|
-
interface InheritedCollections<T = object> {
|
|
336
|
-
name: string;
|
|
337
|
-
fn: (instance: T) => void;
|
|
338
|
-
}
|
|
339
|
-
type MixinHelp<T extends InheritedCollections[]> = T extends [infer L, ...infer R] ? L extends InheritedCollections ? R extends InheritedCollections[] ? {
|
|
340
|
-
[key in L['name']]: L['fn'];
|
|
341
|
-
} & MixinHelp<R> : Record<string, never> : Record<string, never> : Record<string, never>;
|
|
342
|
-
declare function mixin<T extends AnyObject, const I extends InheritedCollections<T>[]>(app: T, methods: I): T & MixinHelp<I>;
|
|
343
323
|
interface InheritedCollectionsWithParamter<T = Any> {
|
|
344
324
|
name: string;
|
|
345
325
|
fn: (instance: T) => (...args: Any[]) => Any;
|
|
@@ -347,11 +327,7 @@ interface InheritedCollectionsWithParamter<T = Any> {
|
|
|
347
327
|
type MixinHelpWithParamater<T extends InheritedCollectionsWithParamter[]> = T extends [infer L, ...infer R] ? L extends InheritedCollectionsWithParamter ? R extends InheritedCollectionsWithParamter[] ? {
|
|
348
328
|
[key in L['name']]: ReturnType<L['fn']>;
|
|
349
329
|
} & MixinHelpWithParamater<R> : Record<string, never> : Record<string, never> : Record<string, never>;
|
|
350
|
-
declare function
|
|
351
|
-
type Tail<T extends string[]> = T extends readonly [infer _, ...infer Rest] ? Rest : [];
|
|
352
|
-
type StrJoin<T extends string[], F extends string> = T extends readonly [] ? '' : T extends readonly [infer FF] ? FF : `${F}${StrJoin<Tail<T>, T[0]>}`;
|
|
353
|
-
declare function prettyStrJoin<T extends string[]>(...s: T): StrJoin<T, T[0]>;
|
|
354
|
-
declare function isMacOS(): boolean;
|
|
330
|
+
declare function mixin<T extends AnyObject, const M extends InheritedCollectionsWithParamter<T>[]>(app: T, methods: M): T & MixinHelpWithParamater<M>;
|
|
355
331
|
declare function typedForIn<T extends NonNullable<object>>(obj: T, callback: (key: keyof T, value: T[keyof T]) => void): void;
|
|
356
332
|
declare function stackMatrixTransform(graph: S, e: number, f: number, scale: number): void;
|
|
357
333
|
declare function stackMatrixTransformWithGraphAndLayer(graphs: Display[], e: number, f: number, scale: number): void;
|
|
@@ -380,15 +356,19 @@ interface PluginContext {
|
|
|
380
356
|
interface OnModuleInitResult {
|
|
381
357
|
colorMappings?: ColorMappings;
|
|
382
358
|
}
|
|
359
|
+
interface OnLayoutCalculatedResult {
|
|
360
|
+
layoutNodes?: LayoutModule[];
|
|
361
|
+
}
|
|
383
362
|
interface PluginHooks {
|
|
384
363
|
onLoad?: (this: PluginContext, treemapContext: BasicTreemapInstance, domEvent: DOMEvent) => void | Record<string, Any>;
|
|
385
364
|
onModuleInit?: (this: PluginContext, modules: LayoutModule[]) => OnModuleInitResult | void;
|
|
386
365
|
onDOMEventTriggered?: <N extends DOMEventType>(this: PluginContext, name: N, event: DOMEventMetadata<N>, module: LayoutModule | null, domEvent: DOMEvent) => void;
|
|
366
|
+
onLayoutCalculated?: (this: PluginContext, layoutNodes: LayoutModule[], rect: Rect, viewport: Required<GraphicLayout>) => OnLayoutCalculatedResult | void;
|
|
387
367
|
onResize?: (this: PluginContext, domEvent: DOMEvent) => void;
|
|
388
368
|
onDispose?: (this: PluginContext) => void;
|
|
389
369
|
}
|
|
390
370
|
type BasicPluginHooks = Pick<PluginHooks, 'onLoad' | 'onDOMEventTriggered' | 'onResize' | 'onDispose'>;
|
|
391
|
-
type CascadedPluginHooks = Pick<PluginHooks, 'onModuleInit'>;
|
|
371
|
+
type CascadedPluginHooks = Pick<PluginHooks, 'onModuleInit' | 'onLayoutCalculated'>;
|
|
392
372
|
interface Plugin<T = string, M = Any> extends PluginHooks {
|
|
393
373
|
name: T;
|
|
394
374
|
meta?: M;
|
|
@@ -405,6 +385,12 @@ declare class PluginDriver<T extends Component> {
|
|
|
405
385
|
}
|
|
406
386
|
|
|
407
387
|
type ColorMappings = Record<string, ColorDecoratorResult>;
|
|
388
|
+
interface AABB {
|
|
389
|
+
x: number;
|
|
390
|
+
y: number;
|
|
391
|
+
width: number;
|
|
392
|
+
height: number;
|
|
393
|
+
}
|
|
408
394
|
declare class Component extends Schedule {
|
|
409
395
|
pluginDriver: PluginDriver<Component>;
|
|
410
396
|
data: NativeModule[];
|
|
@@ -415,6 +401,20 @@ declare class Component extends Schedule {
|
|
|
415
401
|
config: GraphicConfig;
|
|
416
402
|
caches: DefaultMap<string, number>;
|
|
417
403
|
constructor(config: GraphicConfig, ...args: ConstructorParameters<typeof Schedule>);
|
|
404
|
+
clearFontCacheInAABB(aabb: AABB): void;
|
|
405
|
+
private getModulesInAABB;
|
|
406
|
+
getViewportAABB(matrixE: number, matrixF: number, scale: number): AABB;
|
|
407
|
+
private getAABBUnion;
|
|
408
|
+
handleTransformCacheInvalidation(oldMatrix: {
|
|
409
|
+
e: number;
|
|
410
|
+
f: number;
|
|
411
|
+
a: number;
|
|
412
|
+
}, newMatrix: {
|
|
413
|
+
e: number;
|
|
414
|
+
f: number;
|
|
415
|
+
a: number;
|
|
416
|
+
}): void;
|
|
417
|
+
private isAABBIntersecting;
|
|
418
418
|
private drawBroundRect;
|
|
419
419
|
private drawText;
|
|
420
420
|
draw(flush?: boolean, update?: boolean): void;
|
|
@@ -435,22 +435,21 @@ interface PrimitiveEventMetadata<T extends keyof HTMLElementEventMap> {
|
|
|
435
435
|
}
|
|
436
436
|
type ExposedEventCallback<T extends DOMEventType> = (metadata: PrimitiveEventMetadata<T>) => void;
|
|
437
437
|
type ExposedEventDefinition = {
|
|
438
|
-
[K in DOMEventType]: BindThisParameter<ExposedEventCallback<K>,
|
|
438
|
+
[K in DOMEventType]: BindThisParameter<ExposedEventCallback<K>, AnyObject>;
|
|
439
439
|
};
|
|
440
|
-
interface ExposedEventMethods<C =
|
|
441
|
-
on<Evt extends keyof D>(evt: Evt, handler: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
440
|
+
interface ExposedEventMethods<C = AnyObject, D = ExposedEventDefinition> {
|
|
441
|
+
on<Evt extends keyof D | (string & {})>(evt: Evt, handler: BindThisParameter<Evt extends keyof D ? D[Evt] : Any, unknown extends C ? this : C>): void;
|
|
442
442
|
off<Evt extends keyof D>(evt: keyof D, handler?: BindThisParameter<D[Evt], unknown extends C ? this : C>): void;
|
|
443
443
|
}
|
|
444
|
-
type DOMEVEntDefinition
|
|
445
|
-
[K in DOMEventType]: BindThisParameter<DOMEventCallback<K>,
|
|
444
|
+
type DOMEVEntDefinition = {
|
|
445
|
+
[K in DOMEventType]: BindThisParameter<DOMEventCallback<K>, unknown>;
|
|
446
446
|
} & {
|
|
447
|
-
__exposed__: (type:
|
|
447
|
+
__exposed__: <D extends DOMEventType | (string & {})>(type: D, metadata: D extends DOMEventType ? PrimitiveEventMetadata<D> : Any) => void;
|
|
448
448
|
};
|
|
449
449
|
declare const STATE_TRANSITION: {
|
|
450
450
|
readonly IDLE: "IDLE";
|
|
451
451
|
readonly PRESSED: "PRESSED";
|
|
452
452
|
readonly DRAGGING: "DRAGGING";
|
|
453
|
-
readonly CLICK_POTENTIAL: "CLICK_POTENTIAL";
|
|
454
453
|
readonly ZOOMING: "ZOOMING";
|
|
455
454
|
readonly MOVE: "MOVE";
|
|
456
455
|
readonly SCALING: "SCALING";
|
|
@@ -511,11 +510,11 @@ declare function createTreemap<const P extends readonly Plugin[]>(options?: Crea
|
|
|
511
510
|
resize: () => void;
|
|
512
511
|
setOptions: (options: TreemapOptions) => void;
|
|
513
512
|
} & {
|
|
514
|
-
on: (
|
|
513
|
+
on: (evt: any, handler: (this: Event<DefaultEventDefinition>, ...args: any[]) => any, c?: any) => void;
|
|
515
514
|
} & {
|
|
516
|
-
off: (
|
|
515
|
+
off: (evt: string, handler?: ((this: unknown, ...args: any[]) => any) | undefined) => void;
|
|
517
516
|
} & Record<string, never>) & BasicTreemapInstance & ExposedEventMethods & PluginMixins<P>;
|
|
518
517
|
type TreemapInstance<P extends readonly Plugin[]> = BasicTreemapInstance & ExposedEventMethods & PluginMixins<P>;
|
|
519
518
|
|
|
520
|
-
export {
|
|
521
|
-
export type { BasicTreemapInstance as B, ColorMappings as C, DOMEventType as D, ExposedEventCallback as E, GraphicLayout as G, LayoutModule as L, Module as M, NativeModule as N,
|
|
519
|
+
export { noop as A, createRoundBlock as F, createTitleText as H, raf as I, createCanvasElement as J, applyCanvasTransform as K, mixin as Q, typedForIn as R, stackMatrixTransform as U, stackMatrixTransformWithGraphAndLayer as V, smoothFrame as W, isScrollWheelOrRightButtonOnMouseupAndDown as X, DefaultMap as Y, DOMEvent as b, createTreemap as d, c2m as f, findRelativeNode as g, findRelativeNodeById as h, flatten as i, getNodeDepth as j, definePlugin as m, isClickEvent as q, isContextMenuEvent as r, sortChildrenByKey as s, isMouseEvent as t, isWheelEvent as u, visit as v, hashCode as y, perferNumeric as z };
|
|
520
|
+
export type { BasicTreemapInstance as B, ColorMappings as C, DOMEventType as D, ExposedEventCallback as E, GraphicLayout as G, LayoutModule as L, Module as M, NativeModule as N, InheritedCollectionsWithParamter as O, PluginContext as P, Series as S, TreemapOptions as T, DOMEventMetadata as a, CreateTreemapOptions as c, TreemapInstance as e, Plugin as k, PluginHooks as l, ExposedEventDefinition as n, ExposedEventMethods as o, PrimitiveEventMetadata as p, GraphicFont as w, GraphicConfig as x };
|
package/dist/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType,
|
|
1
|
+
export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, Y as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, O as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, T as TreemapOptions, K as applyCanvasTransform, f as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, y as hashCode, q as isClickEvent, r as isContextMenuEvent, t as isMouseEvent, X as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, Q as mixin, A as noop, z as perferNumeric, I as raf, W as smoothFrame, s as sortChildrenByKey, U as stackMatrixTransform, V as stackMatrixTransformWithGraphAndLayer, R as typedForIn, v as visit } from './index-Bb8ZzMCD.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType,
|
|
1
|
+
export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, Y as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, O as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, T as TreemapOptions, K as applyCanvasTransform, f as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, y as hashCode, q as isClickEvent, r as isContextMenuEvent, t as isMouseEvent, X as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, Q as mixin, A as noop, z as perferNumeric, I as raf, W as smoothFrame, s as sortChildrenByKey, U as stackMatrixTransform, V as stackMatrixTransformWithGraphAndLayer, R as typedForIn, v as visit } from './index-Bb8ZzMCD.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var domEvent = require('./dom-event-
|
|
3
|
+
var domEvent = require('./dom-event-CxIxc4YC.js');
|
|
4
4
|
|
|
5
5
|
function createTreemap(// @ts-expect-error todo fix
|
|
6
6
|
options) {
|
|
@@ -13,9 +13,6 @@ options) {
|
|
|
13
13
|
if (!Array.isArray(plugins)) {
|
|
14
14
|
domEvent.logger.panic('Plugins should be an array');
|
|
15
15
|
}
|
|
16
|
-
const api = {
|
|
17
|
-
zoom: domEvent.noop
|
|
18
|
-
};
|
|
19
16
|
const ctx = {
|
|
20
17
|
init,
|
|
21
18
|
dispose,
|
|
@@ -73,7 +70,7 @@ options) {
|
|
|
73
70
|
const base = domEvent.mixin(ctx, [
|
|
74
71
|
{
|
|
75
72
|
name: 'on',
|
|
76
|
-
fn: ()=>exposedEvent.
|
|
73
|
+
fn: ()=>exposedEvent.on.bind(exposedEvent)
|
|
77
74
|
},
|
|
78
75
|
{
|
|
79
76
|
name: 'off',
|
|
@@ -97,15 +94,12 @@ exports.getNodeDepth = domEvent.getNodeDepth;
|
|
|
97
94
|
exports.hashCode = domEvent.hashCode;
|
|
98
95
|
exports.isClickEvent = domEvent.isClickEvent;
|
|
99
96
|
exports.isContextMenuEvent = domEvent.isContextMenuEvent;
|
|
100
|
-
exports.isMacOS = domEvent.isMacOS;
|
|
101
97
|
exports.isMouseEvent = domEvent.isMouseEvent;
|
|
102
98
|
exports.isScrollWheelOrRightButtonOnMouseupAndDown = domEvent.isScrollWheelOrRightButtonOnMouseupAndDown;
|
|
103
99
|
exports.isWheelEvent = domEvent.isWheelEvent;
|
|
104
100
|
exports.mixin = domEvent.mixin;
|
|
105
|
-
exports.mixinWithParams = domEvent.mixinWithParams;
|
|
106
101
|
exports.noop = domEvent.noop;
|
|
107
102
|
exports.perferNumeric = domEvent.perferNumeric;
|
|
108
|
-
exports.prettyStrJoin = domEvent.prettyStrJoin;
|
|
109
103
|
exports.raf = domEvent.raf;
|
|
110
104
|
exports.smoothFrame = domEvent.smoothFrame;
|
|
111
105
|
exports.sortChildrenByKey = domEvent.sortChildrenByKey;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as logger, m as mixin, E as Event,
|
|
2
|
-
export {
|
|
1
|
+
import { l as logger, m as mixin, E as Event, a as assertExists, b as bindParentForModule, C as Component, D as DOMEvent } from './dom-event-CKb3Ko4-.mjs';
|
|
2
|
+
export { G as DefaultMap, x as applyCanvasTransform, c as c2m, w as createCanvasElement, r as createRoundBlock, t as createTitleText, h as definePlugin, f as findRelativeNode, d as findRelativeNodeById, e as flattenModule, g as getNodeDepth, o as hashCode, i as isClickEvent, j as isContextMenuEvent, k as isMouseEvent, F as isScrollWheelOrRightButtonOnMouseupAndDown, n as isWheelEvent, q as noop, p as perferNumeric, u as raf, B as smoothFrame, s as sortChildrenByKey, z as stackMatrixTransform, A as stackMatrixTransformWithGraphAndLayer, y as typedForIn, v as visit } from './dom-event-CKb3Ko4-.mjs';
|
|
3
3
|
|
|
4
4
|
function createTreemap(// @ts-expect-error todo fix
|
|
5
5
|
options) {
|
|
@@ -12,9 +12,6 @@ options) {
|
|
|
12
12
|
if (!Array.isArray(plugins)) {
|
|
13
13
|
logger.panic('Plugins should be an array');
|
|
14
14
|
}
|
|
15
|
-
const api = {
|
|
16
|
-
zoom: noop
|
|
17
|
-
};
|
|
18
15
|
const ctx = {
|
|
19
16
|
init,
|
|
20
17
|
dispose,
|
|
@@ -72,7 +69,7 @@ options) {
|
|
|
72
69
|
const base = mixin(ctx, [
|
|
73
70
|
{
|
|
74
71
|
name: 'on',
|
|
75
|
-
fn: ()=>exposedEvent.
|
|
72
|
+
fn: ()=>exposedEvent.on.bind(exposedEvent)
|
|
76
73
|
},
|
|
77
74
|
{
|
|
78
75
|
name: 'off',
|
|
@@ -82,4 +79,4 @@ options) {
|
|
|
82
79
|
return base;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
export { createTreemap, mixin
|
|
82
|
+
export { createTreemap, mixin };
|
package/dist/plugin.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-
|
|
1
|
+
import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-Bb8ZzMCD.js';
|
|
2
2
|
|
|
3
3
|
declare const presetHighlightPlugin: {
|
|
4
4
|
name: "treemap:preset-highlight";
|