This commit is contained in:
Gavin Nishizawa 2023-05-30 11:18:32 -07:00
parent 6a837fa038
commit ad44eff47a
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -123,31 +123,33 @@ func withoutGridDiagrams(ctx context.Context, g *d2graph.Graph, layout d2graph.L
if obj.LabelDimensions.Height != 0 { if obj.LabelDimensions.Height != 0 {
labelHeight := float64(obj.LabelDimensions.Height) + 2*label.PADDING labelHeight := float64(obj.LabelDimensions.Height) + 2*label.PADDING
{ // also check for grid cells with outside top labels
// also check for grid cells with outside top labels // the first grid object is at the top (and always exists)
topY := gd.objects[0].TopLeft.Y topY := gd.objects[0].TopLeft.Y
highestLabel := topY highestLabel := topY
for _, o := range gd.objects { for _, o := range gd.objects {
if o.TopLeft.Y > topY { // we only want to compute label positions for objects at the top of the grid
if gd.rowDirected { if o.TopLeft.Y > topY {
break if gd.rowDirected {
} else { // if the grid is rowDirected (row1, row2, etc) we can stop after finishing the first row
continue break
} } else {
// otherwise we continue until the next column
continue
} }
if o.LabelPosition != nil { }
labelPosition := label.Position(*o.LabelPosition) if o.LabelPosition != nil {
if labelPosition.IsOutside() { labelPosition := label.Position(*o.LabelPosition)
labelTL := o.GetLabelTopLeft() if labelPosition.IsOutside() {
if labelTL.Y < highestLabel { labelTL := o.GetLabelTopLeft()
highestLabel = labelTL.Y if labelTL.Y < highestLabel {
} highestLabel = labelTL.Y
} }
} }
} }
if highestLabel < topY { }
labelHeight += topY - highestLabel + 2*label.PADDING if highestLabel < topY {
} labelHeight += topY - highestLabel + 2*label.PADDING
} }
if labelHeight > float64(verticalPadding) { if labelHeight > float64(verticalPadding) {