Skip to content

Commit ad44eff

Browse files
committed
cleanup
1 parent 6a837fa commit ad44eff

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

d2layouts/d2grid/layout.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,33 @@ func withoutGridDiagrams(ctx context.Context, g *d2graph.Graph, layout d2graph.L
123123
if obj.LabelDimensions.Height != 0 {
124124
labelHeight := float64(obj.LabelDimensions.Height) + 2*label.PADDING
125125

126-
{
127-
// also check for grid cells with outside top labels
128-
topY := gd.objects[0].TopLeft.Y
129-
highestLabel := topY
130-
for _, o := range gd.objects {
131-
if o.TopLeft.Y > topY {
132-
if gd.rowDirected {
133-
break
134-
} else {
135-
continue
136-
}
126+
// also check for grid cells with outside top labels
127+
// the first grid object is at the top (and always exists)
128+
topY := gd.objects[0].TopLeft.Y
129+
highestLabel := topY
130+
for _, o := range gd.objects {
131+
// we only want to compute label positions for objects at the top of the grid
132+
if o.TopLeft.Y > topY {
133+
if gd.rowDirected {
134+
// if the grid is rowDirected (row1, row2, etc) we can stop after finishing the first row
135+
break
136+
} else {
137+
// otherwise we continue until the next column
138+
continue
137139
}
138-
if o.LabelPosition != nil {
139-
labelPosition := label.Position(*o.LabelPosition)
140-
if labelPosition.IsOutside() {
141-
labelTL := o.GetLabelTopLeft()
142-
if labelTL.Y < highestLabel {
143-
highestLabel = labelTL.Y
144-
}
140+
}
141+
if o.LabelPosition != nil {
142+
labelPosition := label.Position(*o.LabelPosition)
143+
if labelPosition.IsOutside() {
144+
labelTL := o.GetLabelTopLeft()
145+
if labelTL.Y < highestLabel {
146+
highestLabel = labelTL.Y
145147
}
146148
}
147149
}
148-
if highestLabel < topY {
149-
labelHeight += topY - highestLabel + 2*label.PADDING
150-
}
150+
}
151+
if highestLabel < topY {
152+
labelHeight += topY - highestLabel + 2*label.PADDING
151153
}
152154

153155
if labelHeight > float64(verticalPadding) {

0 commit comments

Comments
 (0)