@rkmodules/rules 0.0.101 → 0.0.103
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.cjs.js +74 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +73 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/DataTree/index.d.ts +12 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -269,6 +269,74 @@ function getItem(tree, path, index) {
|
|
|
269
269
|
return branch[index];
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* gets number of dimensions (max depth of the tree) and their sizes (group sizes at each level)
|
|
274
|
+
* @param tree
|
|
275
|
+
* @returns
|
|
276
|
+
*/
|
|
277
|
+
function treeStats(tree) {
|
|
278
|
+
var paths = getPaths(tree);
|
|
279
|
+
var dimensions = 0;
|
|
280
|
+
var branchSizes = {};
|
|
281
|
+
paths.forEach(function (path) {
|
|
282
|
+
var _a;
|
|
283
|
+
var segments = path.split(";").map(function (seg) { return parseInt(seg, 10); });
|
|
284
|
+
// find max depth, which is the number of dimensions
|
|
285
|
+
dimensions = Math.max(dimensions, segments.length);
|
|
286
|
+
segments.forEach(function (seg, index) {
|
|
287
|
+
if (!index)
|
|
288
|
+
return;
|
|
289
|
+
var prefix = segments.slice(0, index).join(";");
|
|
290
|
+
if (!branchSizes[prefix]) {
|
|
291
|
+
branchSizes[prefix] = 1;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
branchSizes[prefix] += 1;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
branchSizes[path] = ((_a = getBranch(tree, path)) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
298
|
+
});
|
|
299
|
+
return { dimensions: dimensions, branchSizes: branchSizes };
|
|
300
|
+
}
|
|
301
|
+
function normalizePaths(tree) {
|
|
302
|
+
var paths = getPaths(tree);
|
|
303
|
+
var spaths = paths.map(function (p) { return p.split(";").map(function (seg) { return parseInt(seg, 10); }); });
|
|
304
|
+
var maxLength = Math.max.apply(Math, __spreadArray([], __read(spaths.map(function (p) { return p.length; })), false));
|
|
305
|
+
var lastSPath;
|
|
306
|
+
var lastNPath;
|
|
307
|
+
var npaths = [];
|
|
308
|
+
spaths.forEach(function (p, index) {
|
|
309
|
+
if (index === 0) {
|
|
310
|
+
// start with a full zero path
|
|
311
|
+
lastNPath = Array(maxLength).fill(0);
|
|
312
|
+
npaths.push(lastNPath.join(";"));
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
// start with all zeros
|
|
316
|
+
var n = Array(maxLength).fill(0);
|
|
317
|
+
for (var i = 0; i < maxLength; i++) {
|
|
318
|
+
if (p[i] > lastSPath[i]) {
|
|
319
|
+
// increment the segment, all the rest are zeros, so we can stop
|
|
320
|
+
n[i] = lastNPath[i] + 1;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
// same segment, copy over
|
|
325
|
+
n[i] = lastNPath[i];
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
lastNPath = n;
|
|
329
|
+
npaths.push(lastNPath.join(";"));
|
|
330
|
+
}
|
|
331
|
+
lastSPath = p;
|
|
332
|
+
});
|
|
333
|
+
var normalized = {};
|
|
334
|
+
paths.forEach(function (path, index) {
|
|
335
|
+
var branch = getBranch(tree, path);
|
|
336
|
+
normalized[npaths[index]] = branch || [];
|
|
337
|
+
});
|
|
338
|
+
return normalized;
|
|
339
|
+
}
|
|
272
340
|
function forEachBranch(tree, fn) {
|
|
273
341
|
var paths = getPaths(tree);
|
|
274
342
|
paths.forEach(function (path, i) {
|
|
@@ -2299,11 +2367,13 @@ var Engine = /** @class */ (function () {
|
|
|
2299
2367
|
return newFn;
|
|
2300
2368
|
}
|
|
2301
2369
|
if (!fn) {
|
|
2302
|
-
|
|
2370
|
+
console.warn("Function ".concat(to === null || to === void 0 ? void 0 : to.name, " not found in index, which is unexpected as you are deleting an edge to it."));
|
|
2371
|
+
return newFn;
|
|
2303
2372
|
}
|
|
2304
2373
|
if (to.inputs && to.inputs[toField] === "<".concat(fromNode, ".").concat(fromField, ">")) {
|
|
2305
|
-
//
|
|
2374
|
+
// delete the incoming edge
|
|
2306
2375
|
delete to.inputs[toField];
|
|
2376
|
+
// revert to default value if exists
|
|
2307
2377
|
if ((_a = fn.inputs) === null || _a === void 0 ? void 0 : _a[toField]) {
|
|
2308
2378
|
var normDef = normalizeVarDef(fn.inputs[toField]);
|
|
2309
2379
|
if (normDef.default !== undefined) {
|
|
@@ -7301,6 +7371,7 @@ exports.mapTree = mapTree;
|
|
|
7301
7371
|
exports.mapTreeBranch = mapTreeBranch;
|
|
7302
7372
|
exports.nAryOnTree = nAryOnTree;
|
|
7303
7373
|
exports.nAryOnTreeBranch = nAryOnTreeBranch;
|
|
7374
|
+
exports.normalizePaths = normalizePaths;
|
|
7304
7375
|
exports.normalizeVarDef = normalizeVarDef;
|
|
7305
7376
|
exports.parseReference = parseReference;
|
|
7306
7377
|
exports.primitives = primitives;
|
|
@@ -7310,6 +7381,7 @@ exports.simplifyTree = simplifyTree$1;
|
|
|
7310
7381
|
exports.toArray = toArray;
|
|
7311
7382
|
exports.topSort = topSort;
|
|
7312
7383
|
exports.treeSize = treeSize;
|
|
7384
|
+
exports.treeStats = treeStats;
|
|
7313
7385
|
exports.trimTree = trimTree;
|
|
7314
7386
|
exports.uid = uid$1;
|
|
7315
7387
|
exports.useDraggableNode = useDraggableNode;
|