@dagrejs/dagre 1.1.3 → 1.1.5
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 +1 -1
- package/dist/dagre.js +97 -60
- package/dist/dagre.min.js +32 -32
- package/index.d.ts +4 -4
- package/lib/acyclic.js +2 -2
- package/lib/add-border-segments.js +1 -1
- package/lib/coordinate-system.js +2 -2
- package/lib/layout.js +6 -6
- package/lib/nesting-graph.js +2 -1
- package/lib/order/build-layer-graph.js +1 -1
- package/lib/order/init-order.js +2 -1
- package/lib/order/sort-subgraph.js +2 -2
- package/lib/order/sort.js +1 -1
- package/lib/position/bk.js +7 -7
- package/lib/rank/index.js +6 -0
- package/lib/rank/network-simplex.js +1 -1
- package/lib/rank/util.js +7 -3
- package/lib/util.js +36 -11
- package/lib/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# dagre - Graph layout for JavaScript
|
|
2
2
|
|
|
3
3
|
[](https://github.com/dagrejs/dagre/actions?query=workflow%3A%22Build+Status%22)
|
|
4
|
-
[](https://www.npmjs.com/package/dagre)
|
|
4
|
+
[](https://www.npmjs.com/package/@dagrejs/dagre)
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Dagre is a JavaScript library that makes it easy to lay out directed graphs on the client-side.
|
package/dist/dagre.js
CHANGED
|
@@ -69,13 +69,13 @@ function dfsFAS(g) {
|
|
|
69
69
|
let visited = {};
|
|
70
70
|
|
|
71
71
|
function dfs(v) {
|
|
72
|
-
if (
|
|
72
|
+
if (Object.hasOwn(visited, v)) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
visited[v] = true;
|
|
76
76
|
stack[v] = true;
|
|
77
77
|
g.outEdges(v).forEach(e => {
|
|
78
|
-
if (
|
|
78
|
+
if (Object.hasOwn(stack, e.w)) {
|
|
79
79
|
fas.push(e);
|
|
80
80
|
} else {
|
|
81
81
|
dfs(e.w);
|
|
@@ -115,7 +115,7 @@ function addBorderSegments(g) {
|
|
|
115
115
|
children.forEach(dfs);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
if (
|
|
118
|
+
if (Object.hasOwn(node, "minRank")) {
|
|
119
119
|
node.borderLeft = [];
|
|
120
120
|
node.borderRight = [];
|
|
121
121
|
for (let rank = node.minRank, maxRank = node.maxRank + 1;
|
|
@@ -185,7 +185,7 @@ function reverseY(g) {
|
|
|
185
185
|
g.edges().forEach(e => {
|
|
186
186
|
let edge = g.edge(e);
|
|
187
187
|
edge.points.forEach(reverseYOne);
|
|
188
|
-
if (
|
|
188
|
+
if (Object.hasOwn(edge, "y")) {
|
|
189
189
|
reverseYOne(edge);
|
|
190
190
|
}
|
|
191
191
|
});
|
|
@@ -201,7 +201,7 @@ function swapXY(g) {
|
|
|
201
201
|
g.edges().forEach(e => {
|
|
202
202
|
let edge = g.edge(e);
|
|
203
203
|
edge.points.forEach(swapXYOne);
|
|
204
|
-
if (
|
|
204
|
+
if (Object.hasOwn(edge, "x")) {
|
|
205
205
|
swapXYOne(edge);
|
|
206
206
|
}
|
|
207
207
|
});
|
|
@@ -519,7 +519,7 @@ function updateInputGraph(inputGraph, layoutGraph) {
|
|
|
519
519
|
let layoutLabel = layoutGraph.edge(e);
|
|
520
520
|
|
|
521
521
|
inputLabel.points = layoutLabel.points;
|
|
522
|
-
if (
|
|
522
|
+
if (Object.hasOwn(layoutLabel, "x")) {
|
|
523
523
|
inputLabel.x = layoutLabel.x;
|
|
524
524
|
inputLabel.y = layoutLabel.y;
|
|
525
525
|
}
|
|
@@ -532,7 +532,7 @@ function updateInputGraph(inputGraph, layoutGraph) {
|
|
|
532
532
|
let graphNumAttrs = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"];
|
|
533
533
|
let graphDefaults = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "tb" };
|
|
534
534
|
let graphAttrs = ["acyclicer", "ranker", "rankdir", "align"];
|
|
535
|
-
let nodeNumAttrs = ["width", "height"];
|
|
535
|
+
let nodeNumAttrs = ["width", "height", "rank"];
|
|
536
536
|
let nodeDefaults = { width: 0, height: 0 };
|
|
537
537
|
let edgeNumAttrs = ["minlen", "weight", "width", "height", "labeloffset"];
|
|
538
538
|
let edgeDefaults = {
|
|
@@ -668,7 +668,7 @@ function translateGraph(g) {
|
|
|
668
668
|
g.nodes().forEach(v => getExtremes(g.node(v)));
|
|
669
669
|
g.edges().forEach(e => {
|
|
670
670
|
let edge = g.edge(e);
|
|
671
|
-
if (
|
|
671
|
+
if (Object.hasOwn(edge, "x")) {
|
|
672
672
|
getExtremes(edge);
|
|
673
673
|
}
|
|
674
674
|
});
|
|
@@ -688,8 +688,8 @@ function translateGraph(g) {
|
|
|
688
688
|
p.x -= minX;
|
|
689
689
|
p.y -= minY;
|
|
690
690
|
});
|
|
691
|
-
if (
|
|
692
|
-
if (
|
|
691
|
+
if (Object.hasOwn(edge, "x")) { edge.x -= minX; }
|
|
692
|
+
if (Object.hasOwn(edge, "y")) { edge.y -= minY; }
|
|
693
693
|
});
|
|
694
694
|
|
|
695
695
|
graphLabel.width = maxX - minX + marginX;
|
|
@@ -718,7 +718,7 @@ function assignNodeIntersects(g) {
|
|
|
718
718
|
function fixupEdgeLabelCoords(g) {
|
|
719
719
|
g.edges().forEach(e => {
|
|
720
720
|
let edge = g.edge(e);
|
|
721
|
-
if (
|
|
721
|
+
if (Object.hasOwn(edge, "x")) {
|
|
722
722
|
if (edge.labelpos === "l" || edge.labelpos === "r") {
|
|
723
723
|
edge.width -= edge.labeloffset;
|
|
724
724
|
}
|
|
@@ -873,7 +873,8 @@ module.exports = {
|
|
|
873
873
|
function run(g) {
|
|
874
874
|
let root = util.addDummyNode(g, "root", {}, "_root");
|
|
875
875
|
let depths = treeDepths(g);
|
|
876
|
-
let
|
|
876
|
+
let depthsArr = Object.values(depths);
|
|
877
|
+
let height = util.applyWithChunking(Math.max, depthsArr) - 1; // Note: depths is an Object not an array
|
|
877
878
|
let nodeSep = 2 * height + 1;
|
|
878
879
|
|
|
879
880
|
g.graph().nestingRoot = root;
|
|
@@ -1195,7 +1196,7 @@ function buildLayerGraph(g, rank, relationship) {
|
|
|
1195
1196
|
result.setEdge(u, v, { weight: g.edge(e).weight + weight });
|
|
1196
1197
|
});
|
|
1197
1198
|
|
|
1198
|
-
if (
|
|
1199
|
+
if (Object.hasOwn(node, "minRank")) {
|
|
1199
1200
|
result.setNode(v, {
|
|
1200
1201
|
borderLeft: node.borderLeft[rank],
|
|
1201
1202
|
borderRight: node.borderRight[rank]
|
|
@@ -1385,7 +1386,8 @@ module.exports = initOrder;
|
|
|
1385
1386
|
function initOrder(g) {
|
|
1386
1387
|
let visited = {};
|
|
1387
1388
|
let simpleNodes = g.nodes().filter(v => !g.children(v).length);
|
|
1388
|
-
let
|
|
1389
|
+
let simpleNodesRanks = simpleNodes.map(v => g.node(v).rank);
|
|
1390
|
+
let maxRank = util.applyWithChunking(Math.max, simpleNodesRanks);
|
|
1389
1391
|
let layers = util.range(maxRank + 1).map(() => []);
|
|
1390
1392
|
|
|
1391
1393
|
function dfs(v) {
|
|
@@ -1545,7 +1547,7 @@ function sortSubgraph(g, v, cg, biasRight) {
|
|
|
1545
1547
|
if (g.children(entry.v).length) {
|
|
1546
1548
|
let subgraphResult = sortSubgraph(g, entry.v, cg, biasRight);
|
|
1547
1549
|
subgraphs[entry.v] = subgraphResult;
|
|
1548
|
-
if (
|
|
1550
|
+
if (Object.hasOwn(subgraphResult, "barycenter")) {
|
|
1549
1551
|
mergeBarycenters(entry, subgraphResult);
|
|
1550
1552
|
}
|
|
1551
1553
|
}
|
|
@@ -1561,7 +1563,7 @@ function sortSubgraph(g, v, cg, biasRight) {
|
|
|
1561
1563
|
if (g.predecessors(bl).length) {
|
|
1562
1564
|
let blPred = g.node(g.predecessors(bl)[0]),
|
|
1563
1565
|
brPred = g.node(g.predecessors(br)[0]);
|
|
1564
|
-
if (!
|
|
1566
|
+
if (!Object.hasOwn(result, "barycenter")) {
|
|
1565
1567
|
result.barycenter = 0;
|
|
1566
1568
|
result.weight = 0;
|
|
1567
1569
|
}
|
|
@@ -1604,7 +1606,7 @@ module.exports = sort;
|
|
|
1604
1606
|
|
|
1605
1607
|
function sort(entries, biasRight) {
|
|
1606
1608
|
let parts = util.partition(entries, entry => {
|
|
1607
|
-
return
|
|
1609
|
+
return Object.hasOwn(entry, "barycenter");
|
|
1608
1610
|
});
|
|
1609
1611
|
let sortable = parts.lhs,
|
|
1610
1612
|
unsortable = parts.rhs.sort((a, b) => b.i - a.i),
|
|
@@ -1896,7 +1898,7 @@ function hasConflict(conflicts, v, w) {
|
|
|
1896
1898
|
v = w;
|
|
1897
1899
|
w = tmp;
|
|
1898
1900
|
}
|
|
1899
|
-
return !!conflicts[v] && conflicts[v]
|
|
1901
|
+
return !!conflicts[v] && Object.hasOwn(conflicts[v], w);
|
|
1900
1902
|
}
|
|
1901
1903
|
|
|
1902
1904
|
/*
|
|
@@ -2057,8 +2059,8 @@ function findSmallestWidthAlignment(g, xss) {
|
|
|
2057
2059
|
*/
|
|
2058
2060
|
function alignCoordinates(xss, alignTo) {
|
|
2059
2061
|
let alignToVals = Object.values(alignTo),
|
|
2060
|
-
alignToMin = Math.min
|
|
2061
|
-
alignToMax = Math.max
|
|
2062
|
+
alignToMin = util.applyWithChunking(Math.min, alignToVals),
|
|
2063
|
+
alignToMax = util.applyWithChunking(Math.max, alignToVals);
|
|
2062
2064
|
|
|
2063
2065
|
["u", "d"].forEach(vert => {
|
|
2064
2066
|
["l", "r"].forEach(horiz => {
|
|
@@ -2068,9 +2070,9 @@ function alignCoordinates(xss, alignTo) {
|
|
|
2068
2070
|
if (xs === alignTo) return;
|
|
2069
2071
|
|
|
2070
2072
|
let xsVals = Object.values(xs);
|
|
2071
|
-
let delta = alignToMin - Math.min
|
|
2073
|
+
let delta = alignToMin - util.applyWithChunking(Math.min, xsVals);
|
|
2072
2074
|
if (horiz !== "l") {
|
|
2073
|
-
delta = alignToMax - Math.max
|
|
2075
|
+
delta = alignToMax - util.applyWithChunking(Math.max,xsVals);
|
|
2074
2076
|
}
|
|
2075
2077
|
|
|
2076
2078
|
if (delta) {
|
|
@@ -2133,7 +2135,7 @@ function sep(nodeSep, edgeSep, reverseSep) {
|
|
|
2133
2135
|
let delta;
|
|
2134
2136
|
|
|
2135
2137
|
sum += vLabel.width / 2;
|
|
2136
|
-
if (
|
|
2138
|
+
if (Object.hasOwn(vLabel, "labelpos")) {
|
|
2137
2139
|
switch (vLabel.labelpos.toLowerCase()) {
|
|
2138
2140
|
case "l": delta = -vLabel.width / 2; break;
|
|
2139
2141
|
case "r": delta = vLabel.width / 2; break;
|
|
@@ -2148,7 +2150,7 @@ function sep(nodeSep, edgeSep, reverseSep) {
|
|
|
2148
2150
|
sum += (wLabel.dummy ? edgeSep : nodeSep) / 2;
|
|
2149
2151
|
|
|
2150
2152
|
sum += wLabel.width / 2;
|
|
2151
|
-
if (
|
|
2153
|
+
if (Object.hasOwn(wLabel, "labelpos")) {
|
|
2152
2154
|
switch (wLabel.labelpos.toLowerCase()) {
|
|
2153
2155
|
case "l": delta = wLabel.width / 2; break;
|
|
2154
2156
|
case "r": delta = -wLabel.width / 2; break;
|
|
@@ -2328,10 +2330,16 @@ module.exports = rank;
|
|
|
2328
2330
|
* fix them up later.
|
|
2329
2331
|
*/
|
|
2330
2332
|
function rank(g) {
|
|
2333
|
+
var ranker = g.graph().ranker;
|
|
2334
|
+
if (ranker instanceof Function) {
|
|
2335
|
+
return ranker(g);
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2331
2338
|
switch(g.graph().ranker) {
|
|
2332
2339
|
case "network-simplex": networkSimplexRanker(g); break;
|
|
2333
2340
|
case "tight-tree": tightTreeRanker(g); break;
|
|
2334
2341
|
case "longest-path": longestPathRanker(g); break;
|
|
2342
|
+
case "none": break;
|
|
2335
2343
|
default: networkSimplexRanker(g);
|
|
2336
2344
|
}
|
|
2337
2345
|
}
|
|
@@ -2483,7 +2491,7 @@ function dfsAssignLowLim(tree, visited, nextLim, v, parent) {
|
|
|
2483
2491
|
|
|
2484
2492
|
visited[v] = true;
|
|
2485
2493
|
tree.neighbors(v).forEach(w => {
|
|
2486
|
-
if (!
|
|
2494
|
+
if (!Object.hasOwn(visited, w)) {
|
|
2487
2495
|
nextLim = dfsAssignLowLim(tree, visited, nextLim, w, v);
|
|
2488
2496
|
}
|
|
2489
2497
|
});
|
|
@@ -2588,6 +2596,8 @@ function isDescendant(tree, vLabel, rootLabel) {
|
|
|
2588
2596
|
},{"../util":27,"./feasible-tree":23,"./util":26,"@dagrejs/graphlib":29}],26:[function(require,module,exports){
|
|
2589
2597
|
"use strict";
|
|
2590
2598
|
|
|
2599
|
+
const { applyWithChunking } = require("../util");
|
|
2600
|
+
|
|
2591
2601
|
module.exports = {
|
|
2592
2602
|
longestPath: longestPath,
|
|
2593
2603
|
slack: slack
|
|
@@ -2619,18 +2629,20 @@ function longestPath(g) {
|
|
|
2619
2629
|
|
|
2620
2630
|
function dfs(v) {
|
|
2621
2631
|
var label = g.node(v);
|
|
2622
|
-
if (
|
|
2632
|
+
if (Object.hasOwn(visited, v)) {
|
|
2623
2633
|
return label.rank;
|
|
2624
2634
|
}
|
|
2625
2635
|
visited[v] = true;
|
|
2626
2636
|
|
|
2627
|
-
|
|
2637
|
+
let outEdgesMinLens = g.outEdges(v).map(e => {
|
|
2628
2638
|
if (e == null) {
|
|
2629
2639
|
return Number.POSITIVE_INFINITY;
|
|
2630
2640
|
}
|
|
2631
2641
|
|
|
2632
2642
|
return dfs(e.w) - g.edge(e).minlen;
|
|
2633
|
-
})
|
|
2643
|
+
});
|
|
2644
|
+
|
|
2645
|
+
var rank = applyWithChunking(Math.min, outEdgesMinLens);
|
|
2634
2646
|
|
|
2635
2647
|
if (rank === Number.POSITIVE_INFINITY) {
|
|
2636
2648
|
rank = 0;
|
|
@@ -2650,7 +2662,7 @@ function slack(g, e) {
|
|
|
2650
2662
|
return g.node(e.w).rank - g.node(e.v).rank - g.edge(e).minlen;
|
|
2651
2663
|
}
|
|
2652
2664
|
|
|
2653
|
-
},{}],27:[function(require,module,exports){
|
|
2665
|
+
},{"../util":27}],27:[function(require,module,exports){
|
|
2654
2666
|
/* eslint "no-console": off */
|
|
2655
2667
|
|
|
2656
2668
|
"use strict";
|
|
@@ -2660,6 +2672,7 @@ let Graph = require("@dagrejs/graphlib").Graph;
|
|
|
2660
2672
|
module.exports = {
|
|
2661
2673
|
addBorderNode,
|
|
2662
2674
|
addDummyNode,
|
|
2675
|
+
applyWithChunking,
|
|
2663
2676
|
asNonCompoundGraph,
|
|
2664
2677
|
buildLayerMatrix,
|
|
2665
2678
|
intersectRect,
|
|
@@ -2683,10 +2696,10 @@ module.exports = {
|
|
|
2683
2696
|
* Adds a dummy node to the graph and return v.
|
|
2684
2697
|
*/
|
|
2685
2698
|
function addDummyNode(g, type, attrs, name) {
|
|
2686
|
-
|
|
2687
|
-
|
|
2699
|
+
var v = name;
|
|
2700
|
+
while (g.hasNode(v)) {
|
|
2688
2701
|
v = uniqueId(name);
|
|
2689
|
-
}
|
|
2702
|
+
}
|
|
2690
2703
|
|
|
2691
2704
|
attrs.dummy = type;
|
|
2692
2705
|
g.setNode(v, attrs);
|
|
@@ -2806,17 +2819,18 @@ function buildLayerMatrix(g) {
|
|
|
2806
2819
|
* rank(v) >= 0 and at least one node w has rank(w) = 0.
|
|
2807
2820
|
*/
|
|
2808
2821
|
function normalizeRanks(g) {
|
|
2809
|
-
let
|
|
2822
|
+
let nodeRanks = g.nodes().map(v => {
|
|
2810
2823
|
let rank = g.node(v).rank;
|
|
2811
2824
|
if (rank === undefined) {
|
|
2812
2825
|
return Number.MAX_VALUE;
|
|
2813
2826
|
}
|
|
2814
2827
|
|
|
2815
2828
|
return rank;
|
|
2816
|
-
})
|
|
2829
|
+
});
|
|
2830
|
+
let min = applyWithChunking(Math.min, nodeRanks);
|
|
2817
2831
|
g.nodes().forEach(v => {
|
|
2818
2832
|
let node = g.node(v);
|
|
2819
|
-
if (
|
|
2833
|
+
if (Object.hasOwn(node, "rank")) {
|
|
2820
2834
|
node.rank -= min;
|
|
2821
2835
|
}
|
|
2822
2836
|
});
|
|
@@ -2824,7 +2838,8 @@ function normalizeRanks(g) {
|
|
|
2824
2838
|
|
|
2825
2839
|
function removeEmptyRanks(g) {
|
|
2826
2840
|
// Ranks may not start at 0, so we need to offset them
|
|
2827
|
-
let
|
|
2841
|
+
let nodeRanks = g.nodes().map(v => g.node(v).rank);
|
|
2842
|
+
let offset = applyWithChunking(Math.min, nodeRanks);
|
|
2828
2843
|
|
|
2829
2844
|
let layers = [];
|
|
2830
2845
|
g.nodes().forEach(v => {
|
|
@@ -2858,15 +2873,37 @@ function addBorderNode(g, prefix, rank, order) {
|
|
|
2858
2873
|
return addDummyNode(g, "border", node, prefix);
|
|
2859
2874
|
}
|
|
2860
2875
|
|
|
2876
|
+
function splitToChunks(array, chunkSize = CHUNKING_THRESHOLD) {
|
|
2877
|
+
const chunks = [];
|
|
2878
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
2879
|
+
const chunk = array.slice(i, i + chunkSize);
|
|
2880
|
+
chunks.push(chunk);
|
|
2881
|
+
}
|
|
2882
|
+
return chunks;
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
const CHUNKING_THRESHOLD = 65535;
|
|
2886
|
+
|
|
2887
|
+
function applyWithChunking(fn, argsArray) {
|
|
2888
|
+
if(argsArray.length > CHUNKING_THRESHOLD) {
|
|
2889
|
+
const chunks = splitToChunks(argsArray);
|
|
2890
|
+
return fn.apply(null, chunks.map(chunk => fn.apply(null, chunk)));
|
|
2891
|
+
} else {
|
|
2892
|
+
return fn.apply(null, argsArray);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2861
2896
|
function maxRank(g) {
|
|
2862
|
-
|
|
2897
|
+
const nodes = g.nodes();
|
|
2898
|
+
const nodeRanks = nodes.map(v => {
|
|
2863
2899
|
let rank = g.node(v).rank;
|
|
2864
2900
|
if (rank === undefined) {
|
|
2865
2901
|
return Number.MIN_VALUE;
|
|
2866
2902
|
}
|
|
2867
|
-
|
|
2868
2903
|
return rank;
|
|
2869
|
-
})
|
|
2904
|
+
});
|
|
2905
|
+
|
|
2906
|
+
return applyWithChunking(Math.max, nodeRanks);
|
|
2870
2907
|
}
|
|
2871
2908
|
|
|
2872
2909
|
/*
|
|
@@ -2906,7 +2943,7 @@ function notime(name, fn) {
|
|
|
2906
2943
|
let idCounter = 0;
|
|
2907
2944
|
function uniqueId(prefix) {
|
|
2908
2945
|
var id = ++idCounter;
|
|
2909
|
-
return
|
|
2946
|
+
return prefix + ("" + id);
|
|
2910
2947
|
}
|
|
2911
2948
|
|
|
2912
2949
|
function range(start, limit, step = 1) {
|
|
@@ -2959,7 +2996,7 @@ function zipObject(props, values) {
|
|
|
2959
2996
|
}
|
|
2960
2997
|
|
|
2961
2998
|
},{"@dagrejs/graphlib":29}],28:[function(require,module,exports){
|
|
2962
|
-
module.exports = "1.1.
|
|
2999
|
+
module.exports = "1.1.5";
|
|
2963
3000
|
|
|
2964
3001
|
},{}],29:[function(require,module,exports){
|
|
2965
3002
|
/**
|
|
@@ -3010,7 +3047,7 @@ function components(g) {
|
|
|
3010
3047
|
var cmpt;
|
|
3011
3048
|
|
|
3012
3049
|
function dfs(v) {
|
|
3013
|
-
if (
|
|
3050
|
+
if (Object.hasOwn(visited, v)) return;
|
|
3014
3051
|
visited[v] = true;
|
|
3015
3052
|
cmpt.push(v);
|
|
3016
3053
|
g.successors(v).forEach(dfs);
|
|
@@ -3067,7 +3104,7 @@ function postOrderDfs(v, navigation, visited, acc) {
|
|
|
3067
3104
|
if (curr[1]) {
|
|
3068
3105
|
acc.push(curr[0]);
|
|
3069
3106
|
} else {
|
|
3070
|
-
if (!
|
|
3107
|
+
if (!Object.hasOwn(visited, curr[0])) {
|
|
3071
3108
|
visited[curr[0]] = true;
|
|
3072
3109
|
stack.push([curr[0], true]);
|
|
3073
3110
|
forEachRight(navigation(curr[0]), w => stack.push([w, false]));
|
|
@@ -3080,7 +3117,7 @@ function preOrderDfs(v, navigation, visited, acc) {
|
|
|
3080
3117
|
var stack = [v];
|
|
3081
3118
|
while (stack.length > 0) {
|
|
3082
3119
|
var curr = stack.pop();
|
|
3083
|
-
if (!
|
|
3120
|
+
if (!Object.hasOwn(visited, curr)) {
|
|
3084
3121
|
visited[curr] = true;
|
|
3085
3122
|
acc.push(curr);
|
|
3086
3123
|
forEachRight(navigation(curr), w => stack.push(w));
|
|
@@ -3314,7 +3351,7 @@ function prim(g, weightFunc) {
|
|
|
3314
3351
|
var init = false;
|
|
3315
3352
|
while (pq.size() > 0) {
|
|
3316
3353
|
v = pq.removeMin();
|
|
3317
|
-
if (
|
|
3354
|
+
if (Object.hasOwn(parents, v)) {
|
|
3318
3355
|
result.setEdge(v, parents[v]);
|
|
3319
3356
|
} else if (init) {
|
|
3320
3357
|
throw new Error("Input graph is not connected: " + g);
|
|
@@ -3346,7 +3383,7 @@ function tarjan(g) {
|
|
|
3346
3383
|
stack.push(v);
|
|
3347
3384
|
|
|
3348
3385
|
g.successors(v).forEach(function(w) {
|
|
3349
|
-
if (!
|
|
3386
|
+
if (!Object.hasOwn(visited, w)) {
|
|
3350
3387
|
dfs(w);
|
|
3351
3388
|
entry.lowlink = Math.min(entry.lowlink, visited[w].lowlink);
|
|
3352
3389
|
} else if (visited[w].onStack) {
|
|
@@ -3367,7 +3404,7 @@ function tarjan(g) {
|
|
|
3367
3404
|
}
|
|
3368
3405
|
|
|
3369
3406
|
g.nodes().forEach(function(v) {
|
|
3370
|
-
if (!
|
|
3407
|
+
if (!Object.hasOwn(visited, v)) {
|
|
3371
3408
|
dfs(v);
|
|
3372
3409
|
}
|
|
3373
3410
|
});
|
|
@@ -3382,11 +3419,11 @@ function topsort(g) {
|
|
|
3382
3419
|
var results = [];
|
|
3383
3420
|
|
|
3384
3421
|
function visit(node) {
|
|
3385
|
-
if (
|
|
3422
|
+
if (Object.hasOwn(stack, node)) {
|
|
3386
3423
|
throw new CycleException();
|
|
3387
3424
|
}
|
|
3388
3425
|
|
|
3389
|
-
if (!
|
|
3426
|
+
if (!Object.hasOwn(visited, node)) {
|
|
3390
3427
|
stack[node] = true;
|
|
3391
3428
|
visited[node] = true;
|
|
3392
3429
|
g.predecessors(node).forEach(visit);
|
|
@@ -3443,7 +3480,7 @@ class PriorityQueue {
|
|
|
3443
3480
|
* Returns `true` if **key** is in the queue and `false` if not.
|
|
3444
3481
|
*/
|
|
3445
3482
|
has(key) {
|
|
3446
|
-
return this._keyIndices
|
|
3483
|
+
return Object.hasOwn(this._keyIndices, key);
|
|
3447
3484
|
}
|
|
3448
3485
|
|
|
3449
3486
|
/**
|
|
@@ -3481,7 +3518,7 @@ class PriorityQueue {
|
|
|
3481
3518
|
add(key, priority) {
|
|
3482
3519
|
var keyIndices = this._keyIndices;
|
|
3483
3520
|
key = String(key);
|
|
3484
|
-
if (!
|
|
3521
|
+
if (!Object.hasOwn(keyIndices, key)) {
|
|
3485
3522
|
var arr = this._arr;
|
|
3486
3523
|
var index = arr.length;
|
|
3487
3524
|
keyIndices[key] = index;
|
|
@@ -3629,9 +3666,9 @@ class Graph {
|
|
|
3629
3666
|
|
|
3630
3667
|
constructor(opts) {
|
|
3631
3668
|
if (opts) {
|
|
3632
|
-
this._isDirected =
|
|
3633
|
-
this._isMultigraph =
|
|
3634
|
-
this._isCompound =
|
|
3669
|
+
this._isDirected = Object.hasOwn(opts, "directed") ? opts.directed : true;
|
|
3670
|
+
this._isMultigraph = Object.hasOwn(opts, "multigraph") ? opts.multigraph : false;
|
|
3671
|
+
this._isCompound = Object.hasOwn(opts, "compound") ? opts.compound : false;
|
|
3635
3672
|
}
|
|
3636
3673
|
|
|
3637
3674
|
if (this._isCompound) {
|
|
@@ -3760,7 +3797,7 @@ class Graph {
|
|
|
3760
3797
|
* Complexity: O(1).
|
|
3761
3798
|
*/
|
|
3762
3799
|
setNode(v, value) {
|
|
3763
|
-
if (this._nodes
|
|
3800
|
+
if (Object.hasOwn(this._nodes, v)) {
|
|
3764
3801
|
if (arguments.length > 1) {
|
|
3765
3802
|
this._nodes[v] = value;
|
|
3766
3803
|
}
|
|
@@ -3793,7 +3830,7 @@ class Graph {
|
|
|
3793
3830
|
* Detects whether graph has a node with specified name or not.
|
|
3794
3831
|
*/
|
|
3795
3832
|
hasNode(v) {
|
|
3796
|
-
return this._nodes
|
|
3833
|
+
return Object.hasOwn(this._nodes, v);
|
|
3797
3834
|
}
|
|
3798
3835
|
|
|
3799
3836
|
/**
|
|
@@ -3804,7 +3841,7 @@ class Graph {
|
|
|
3804
3841
|
*/
|
|
3805
3842
|
removeNode(v) {
|
|
3806
3843
|
var self = this;
|
|
3807
|
-
if (this._nodes
|
|
3844
|
+
if (Object.hasOwn(this._nodes, v)) {
|
|
3808
3845
|
var removeEdge = e => self.removeEdge(self._edgeObjs[e]);
|
|
3809
3846
|
delete this._nodes[v];
|
|
3810
3847
|
if (this._isCompound) {
|
|
@@ -4082,7 +4119,7 @@ class Graph {
|
|
|
4082
4119
|
}
|
|
4083
4120
|
|
|
4084
4121
|
var e = edgeArgsToId(this._isDirected, v, w, name);
|
|
4085
|
-
if (this._edgeLabels
|
|
4122
|
+
if (Object.hasOwn(this._edgeLabels, e)) {
|
|
4086
4123
|
if (valueSpecified) {
|
|
4087
4124
|
this._edgeLabels[e] = value;
|
|
4088
4125
|
}
|
|
@@ -4147,7 +4184,7 @@ class Graph {
|
|
|
4147
4184
|
var e = (arguments.length === 1
|
|
4148
4185
|
? edgeObjToId(this._isDirected, arguments[0])
|
|
4149
4186
|
: edgeArgsToId(this._isDirected, v, w, name));
|
|
4150
|
-
return this._edgeLabels
|
|
4187
|
+
return Object.hasOwn(this._edgeLabels, e);
|
|
4151
4188
|
}
|
|
4152
4189
|
|
|
4153
4190
|
/**
|
|
@@ -4353,7 +4390,7 @@ function read(json) {
|
|
|
4353
4390
|
}
|
|
4354
4391
|
|
|
4355
4392
|
},{"./graph":44}],47:[function(require,module,exports){
|
|
4356
|
-
module.exports = '2.2.
|
|
4393
|
+
module.exports = '2.2.4';
|
|
4357
4394
|
|
|
4358
4395
|
},{}]},{},[1])(1)
|
|
4359
4396
|
});
|