Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nesting-graph.js #424

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/nesting-graph.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var util = require("./util");
let util = require("./util");

module.exports = {
run,
Expand Down Expand Up @@ -29,18 +29,18 @@ module.exports = {
* Graphs."
*/
function run(g) {
var root = util.addDummyNode(g, "root", {}, "_root");
var depths = treeDepths(g);
var height = Math.max(...Object.values(depths)) - 1; // Note: depths is an Object not an array
var nodeSep = 2 * height + 1;
let root = util.addDummyNode(g, "root", {}, "_root");
let depths = treeDepths(g);
let height = Math.max(...Object.values(depths)) - 1; // Note: depths is an Object not an array
let nodeSep = 2 * height + 1;

g.graph().nestingRoot = root;

// Multiply minlen by nodeSep to align nodes on non-border ranks.
g.edges().forEach(e => g.edge(e).minlen *= nodeSep);

// Calculate a weight that is sufficient to keep subgraphs vertically compact
var weight = sumWeights(g) + 1;
let weight = sumWeights(g) + 1;

// Create border nodes and link them up
g.children().forEach(child => dfs(g, root, nodeSep, weight, height, depths, child));
Expand All @@ -51,17 +51,17 @@ function run(g) {
}

function dfs(g, root, nodeSep, weight, height, depths, v) {
var children = g.children(v);
let children = g.children(v);
if (!children.length) {
if (v !== root) {
g.setEdge(root, v, { weight: 0, minlen: nodeSep });
}
return;
}

var top = util.addBorderNode(g, "_bt");
var bottom = util.addBorderNode(g, "_bb");
var label = g.node(v);
let top = util.addBorderNode(g, "_bt");
let bottom = util.addBorderNode(g, "_bb");
let label = g.node(v);

g.setParent(top, v);
label.borderTop = top;
Expand All @@ -71,11 +71,11 @@ function dfs(g, root, nodeSep, weight, height, depths, v) {
children.forEach(child => {
dfs(g, root, nodeSep, weight, height, depths, child);

var childNode = g.node(child);
var childTop = childNode.borderTop ? childNode.borderTop : child;
var childBottom = childNode.borderBottom ? childNode.borderBottom : child;
var thisWeight = childNode.borderTop ? weight : 2 * weight;
var minlen = childTop !== childBottom ? 1 : height - depths[v] + 1;
let childNode = g.node(child);
let childTop = childNode.borderTop ? childNode.borderTop : child;
let childBottom = childNode.borderBottom ? childNode.borderBottom : child;
let thisWeight = childNode.borderTop ? weight : 2 * weight;
let minlen = childTop !== childBottom ? 1 : height - depths[v] + 1;

g.setEdge(top, childTop, {
weight: thisWeight,
Expand Down
Loading