From 8cf812fcb9111ddf8909cd7c156adae0d4a3c4ba Mon Sep 17 00:00:00 2001 From: Rohit Paul <113459757+RohitPaul0007@users.noreply.github.com> Date: Sun, 10 Sep 2023 22:12:45 +0530 Subject: [PATCH] Update util.js --- lib/util.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/util.js b/lib/util.js index 5196d4fa..0fee6b1d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -2,7 +2,7 @@ "use strict"; -var Graph = require("@dagrejs/graphlib").Graph; +let Graph = require("@dagrejs/graphlib").Graph; module.exports = { addBorderNode, @@ -30,7 +30,7 @@ module.exports = { * Adds a dummy node to the graph and return v. */ function addDummyNode(g, type, attrs, name) { - var v; + let v; do { v = uniqueId(name); } while (g.hasNode(v)); @@ -45,11 +45,11 @@ function addDummyNode(g, type, attrs, name) { * associated with multi-edges. */ function simplify(g) { - var simplified = new Graph().setGraph(g.graph()); + let simplified = new Graph().setGraph(g.graph()); g.nodes().forEach(v => simplified.setNode(v, g.node(v))); g.edges().forEach(e => { - var simpleLabel = simplified.edge(e.v, e.w) || { weight: 0, minlen: 1 }; - var label = g.edge(e); + let simpleLabel = simplified.edge(e.v, e.w) || { weight: 0, minlen: 1 }; + let label = g.edge(e); simplified.setEdge(e.v, e.w, { weight: simpleLabel.weight + label.weight, minlen: Math.max(simpleLabel.minlen, label.minlen) @@ -59,7 +59,7 @@ function simplify(g) { } function asNonCompoundGraph(g) { - var simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(g.graph()); + let simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(g.graph()); g.nodes().forEach(v => { if (!g.children(v).length) { simplified.setNode(v, g.node(v)); @@ -72,8 +72,8 @@ function asNonCompoundGraph(g) { } function successorWeights(g) { - var weightMap = g.nodes().map(v => { - var sucs = {}; + let weightMap = g.nodes().map(v => { + let sucs = {}; g.outEdges(v).forEach(e => { sucs[e.w] = (sucs[e.w] || 0) + g.edge(e).weight; }); @@ -83,8 +83,8 @@ function successorWeights(g) { } function predecessorWeights(g) { - var weightMap = g.nodes().map(v => { - var preds = {}; + let weightMap = g.nodes().map(v => { + let preds = {}; g.inEdges(v).forEach(e => { preds[e.v] = (preds[e.v] || 0) + g.edge(e).weight; }); @@ -98,21 +98,21 @@ function predecessorWeights(g) { * ({x, y, width, height}) if it were pointing at the rectangle's center. */ function intersectRect(rect, point) { - var x = rect.x; - var y = rect.y; + let x = rect.x; + let y = rect.y; // Rectangle intersection algorithm from: // http://math.stackexchange.com/questions/108113/find-edge-between-two-boxes - var dx = point.x - x; - var dy = point.y - y; - var w = rect.width / 2; - var h = rect.height / 2; + let dx = point.x - x; + let dy = point.y - y; + let w = rect.width / 2; + let h = rect.height / 2; if (!dx && !dy) { throw new Error("Not possible to find intersection inside of the rectangle"); } - var sx, sy; + let sx, sy; if (Math.abs(dy) * w > Math.abs(dx) * h) { // Intersection is top or bottom of rect. if (dy < 0) { @@ -137,10 +137,10 @@ function intersectRect(rect, point) { * function will produce a matrix with the ids of each node. */ function buildLayerMatrix(g) { - var layering = range(maxRank(g) + 1).map(() => []); + let layering = range(maxRank(g) + 1).map(() => []); g.nodes().forEach(v => { - var node = g.node(v); - var rank = node.rank; + let node = g.node(v); + let rank = node.rank; if (rank !== undefined) { layering[rank][node.order] = v; } @@ -153,8 +153,8 @@ function buildLayerMatrix(g) { * rank(v) >= 0 and at least one node w has rank(w) = 0. */ function normalizeRanks(g) { - var min = Math.min(...g.nodes().map(v => { - var rank = g.node(v).rank; + let min = Math.min(...g.nodes().map(v => { + let rank = g.node(v).rank; if (rank === undefined) { return Number.MAX_VALUE; } @@ -162,7 +162,7 @@ function normalizeRanks(g) { return rank; })); g.nodes().forEach(v => { - var node = g.node(v); + let node = g.node(v); if (node.hasOwnProperty("rank")) { node.rank -= min; }