Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce crossings of connection lines
Browse files Browse the repository at this point in the history
beru committed Dec 15, 2024
1 parent 982ff60 commit f63710d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions source/dagre.js
Original file line number Diff line number Diff line change
@@ -1367,11 +1367,27 @@ dagre.layout = (nodes, edges, layout, state) => {
const calcDir = (idx0, idx1) => (idx0 < idx1) ? 1 : 2;
for (let i = 4; i < best.length; i += 2) {
const layer = best[i];
const upperLayer = best[i - 1];
for (let j = 0; j < layer.length; ++j) {
const node = g.nodes.get(layer[j]);
if (node.in && node.in.length === 2) {
let n0 = node.in[0].vNode.in[0].vNode;
let n1 = node.in[1].vNode.in[0].vNode;
if (!node.in || node.in.length < 2) {
continue;
}
const i2s = [];
for (let i2 = 0; i2 < node.in.length - 2; ++i2) {
i2s.push(i2);
}
for (let i2 = node.in.length - 2; i2 >= 0; --i2) {
i2s.push(i2);
}
const inputIndexes = [];
for (let i2 = 0; i2 < node.in.length; ++i2) {
inputIndexes.push(upperLayer.indexOf(node.in[i2].v));
}
inputIndexes.sort((a, b) => a - b);
for (const i2 of i2s) {
let n0 = g.node(upperLayer[inputIndexes[i2 + 0]]).in[0].vNode;
let n1 = g.node(upperLayer[inputIndexes[i2 + 1]]).in[0].vNode;
const indexes = [];
let dirTotal = 0;
for (let k = i - 2; k >= 0; k -= 2) {
@@ -1388,6 +1404,11 @@ dagre.layout = (nodes, edges, layout, state) => {
|| n1.out.length !== 1
) {
if (dirTotal === 3) {
{
const idx1 = inputIndexes[i2 + 0];
const idx0 = inputIndexes[i2 + 1];
[upperLayer[idx0], upperLayer[idx1]] = [upperLayer[idx1], upperLayer[idx0]];
}
const topDir = dir;
let l = k + 2;
while (indexes.length !== 0) {

0 comments on commit f63710d

Please sign in to comment.