File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -181,13 +181,10 @@ func (g *graph) setSubgraphs(textSubgraphs []*textSubgraph) {
181181}
182182
183183func (g * graph ) createMapping () {
184- // Set mapping coord for every node in the graph
185- highestPositionPerLevel := []int {}
186- // Init array with 0 values
187- // TODO: I'm sure there's a better way of doing this
188- for i := 0 ; i < 100 ; i ++ {
189- highestPositionPerLevel = append (highestPositionPerLevel , 0 )
190- }
184+ // Set mapping coord for every node in the graph.
185+ // Keyed by level so it grows with the graph instead of assuming a fixed
186+ // number of levels; a missing key reads as the zero value.
187+ highestPositionPerLevel := map [int ]int {}
191188
192189 // TODO: should the mapping be bottom-to-top instead of top-to-bottom?
193190 // Set root nodes to level 0
Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "fmt"
45 "strings"
56 "testing"
67
78 "github.com/AlexanderGrooff/mermaid-ascii/pkg/diagram"
89 "github.com/mattn/go-runewidth"
910)
1011
12+ func TestRenderGraphHandlesLongChainWithoutPanic (t * testing.T ) {
13+ config := diagram .NewTestConfig (true , "cli" )
14+
15+ var b strings.Builder
16+ b .WriteString ("graph TD\n " )
17+ for i := 1 ; i < 30 ; i ++ {
18+ fmt .Fprintf (& b , "N%d --> N%d\n " , i , i + 1 )
19+ }
20+
21+ output , err := RenderDiagram (b .String (), config )
22+ if err != nil {
23+ t .Fatalf ("RenderDiagram() error = %v" , err )
24+ }
25+
26+ if ! strings .Contains (output , "N30" ) {
27+ t .Fatalf ("expected output to contain the last node\n output:\n %s" , output )
28+ }
29+ }
30+
1131func TestRenderGraphKeepsDisplayWidthForWideNodeLabels (t * testing.T ) {
1232 config := diagram .NewTestConfig (true , "cli" )
1333 output , err := RenderDiagram ("graph LR\n A[\" 中A\" ] --> B" , config )
You can’t perform that action at this time.
0 commit comments