Compact graph columns and branch spacing and simplify Home hints

This commit is contained in:
2026-10-10 02:00:39 +01:00
parent c05789d8a6
commit d73a021cd4
11 changed files with 146 additions and 37 deletions
+25 -11
View File
@@ -146,29 +146,43 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin
}
}
gaps, xs := make([]int, maxColumn+2), make([]int, maxColumn+1)
widths := make([]int, maxColumn+1)
for i := 0; i < len(graph.Stages); i++ {
node := r.nodes[i]
widths[columns[node.key]] = max(widths[columns[node.key]], node.width)
}
x := 0
for column := 0; column <= maxColumn; column++ {
gaps[column] = x
x += 2*(outCount[column]+inCount[column]) + 3
x += outCount[column] + inCount[column] + 3
xs[column] = x
x += r.nodeWidth
x += widths[column]
}
gaps[maxColumn+1] = x
x += 2*outCount[maxColumn+1] + 3
x += outCount[maxColumn+1] + 3
r.width = x
maxHeight := 0
columnCounts := make([]int, maxColumn+1)
for _, stage := range graph.Stages {
columnCounts[columns[stage.Key]]++
}
for i := 0; i < len(graph.Stages); i++ {
node := &r.nodes[i]
node.height = incoming[node.key] + outgoing[node.key] + 4
if incoming[node.key] > 0 {
node.height++
}
maxHeight = max(maxHeight, node.height)
// Only stacked branches set lane spacing; a tall trunk/merge must not
// inflate the spacing between every leaf in the graph.
if columnCounts[columns[node.key]] > 1 {
maxHeight = max(maxHeight, node.height)
}
}
stride := maxHeight + 4
stride := maxHeight + 2
for i := 0; i < len(graph.Stages); i++ {
node := &r.nodes[i]
node.x = xs[columns[node.key]]
node.width = widths[columns[node.key]]
node.y = arcs + ticks[node.key]*stride/2
}
// Irregular cross-branch merges can otherwise share a lane with an unrelated
@@ -182,10 +196,10 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin
}
}
sort.SliceStable(ids, func(i, j int) bool { return r.nodes[ids[i]].y < r.nodes[ids[j]].y })
lastBottom := -4
lastBottom := -2
for _, id := range ids {
node := &r.nodes[id]
node.y = max(node.y, lastBottom+4)
node.y = max(node.y, lastBottom+2)
lastBottom = node.y + node.height
bottom = max(bottom, lastBottom)
}
@@ -241,7 +255,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin
edge := &r.edges[i]
source := nodes[edge.source]
gap := columns[edge.source] + 1
edge.x = gaps[gap] + 1 + 2*usedOut[gap]
edge.x = gaps[gap] + 1 + usedOut[gap]
usedOut[gap]++
if protocol.IsTerminal(edge.target) {
continue
@@ -253,7 +267,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin
edge.path = append(edge.path, graphPoint{edge.x, edge.to}, graphPoint{target.x, edge.to})
} else {
gap := columns[edge.target]
track := gaps[gap] + 1 + 2*(outCount[gap]+usedIn[gap])
track := gaps[gap] + 1 + outCount[gap] + usedIn[gap]
usedIn[gap]++
edge.path = append(edge.path, graphPoint{edge.x, arc}, graphPoint{track, arc}, graphPoint{track, edge.to}, graphPoint{target.x, edge.to})
edge.lane = arc
@@ -318,7 +332,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin
}
lanes[lane] = append(lanes[lane], interval)
edge.lane = lane
row := bottom + 2 + lane
row := bottom + 1 + lane
source := nodes[edge.source]
edge.path = []graphPoint{{source.x + source.width - 1, edge.from}, {edge.x, edge.from}, {edge.x, row}, {destination, row}}
if edge.bottomExit {
@@ -327,7 +341,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin
edge.path = []graphPoint{{center, exit}, {center, exit + 1}, {edge.x, exit + 1}, {edge.x, row}, {destination, row}}
}
}
endY := bottom + len(lanes) + 3
endY := bottom + len(lanes) + 2
for i := len(graph.Stages); i < len(r.nodes); i++ {
node := terminal[r.nodes[i].key]
node.y = endY