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
+13 -9
View File
@@ -18,12 +18,13 @@ func layoutGraph(graph protocol.Graph) graphLayout {
}
func layoutSingleRowGraph(graph protocol.Graph) graphLayout {
r := graphLayout{edges: graphEdges(graph), nodeWidth: 16, positions: map[string]int{}}
r := graphLayout{edges: graphEdges(graph), positions: map[string]int{}}
count := len(graph.Stages)
index, incoming, outgoing := map[string]int{}, map[string][]int{}, map[string][]int{}
widths := map[string]int{}
for i, s := range graph.Stages {
index[s.Key] = i
r.nodeWidth = max(r.nodeWidth, len(s.Key)+6)
widths[s.Key] = max(14, len(s.Key)+4)
}
gapCount := make([]int, count+1)
arcs := 0
@@ -34,7 +35,10 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout {
if !r.edges[i].bottomExit {
gapCount[index[e.source]+1]++
}
r.nodeWidth = max(r.nodeWidth, len(fmt.Sprintf("%s [%d]", e.label, e.id))+4)
widths[e.source] = max(widths[e.source], len(fmt.Sprintf("%s [%d]", e.label, e.id))+4)
if !protocol.IsTerminal(e.target) {
widths[e.target] = max(widths[e.target], len(fmt.Sprintf("in [%d]", e.id))+4)
}
if !protocol.IsTerminal(e.target) && index[e.target] != index[e.source]+1 {
arcs++
gapCount[index[e.target]]++
@@ -44,18 +48,18 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout {
x, mainY, height := 0, arcs, 4
for i, s := range graph.Stages {
gapStarts[i] = x
x += gapCount[i]*2 + 3
x += gapCount[i] + 3
h := len(incoming[s.Key]) + len(outgoing[s.Key]) + 4
if len(incoming[s.Key]) > 0 {
h++
}
height = max(height, h)
r.nodes = append(r.nodes, graphNode{key: s.Key, x: x, y: mainY, width: r.nodeWidth, height: h})
r.nodes = append(r.nodes, graphNode{key: s.Key, x: x, y: mainY, width: widths[s.Key], height: h})
r.positions[s.Key] = mainY
x += r.nodeWidth
x += widths[s.Key]
}
gapStarts[count] = x
x += gapCount[count]*2 + 3
x += gapCount[count] + 3
r.width = x
for i := range r.nodes {
r.nodes[i].height = height
@@ -112,7 +116,7 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout {
}
}
usedOut, usedIn := make([]int, count+1), make([]int, count+1)
sourceTrack := func(gap int) int { value := gapStarts[gap] + 1 + usedOut[gap]*2; usedOut[gap]++; return value }
sourceTrack := func(gap int) int { value := gapStarts[gap] + 1 + usedOut[gap]; usedOut[gap]++; return value }
targetTrack := func(gap int) int {
outCount := 0
if gap > 0 {
@@ -122,7 +126,7 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout {
}
}
}
value := gapStarts[gap] + 1 + (outCount+usedIn[gap])*2
value := gapStarts[gap] + 1 + outCount + usedIn[gap]
usedIn[gap]++
return value
}