position around grid label

This commit is contained in:
Gavin Nishizawa 2023-11-08 15:07:20 -08:00
parent 107b556c20
commit a363584245
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -77,10 +77,28 @@ func Layout(ctx context.Context, g *d2graph.Graph) error {
} }
} }
if occupiedHeight > float64(verticalPadding) { if obj.LabelPosition != nil {
// if the label doesn't fit within the padding, we need to add more labelPosition := label.FromString(*obj.LabelPosition)
dy = occupiedHeight - float64(verticalPadding) if !labelPosition.IsOutside() {
obj.Height += dy labelOverflowY := occupiedHeight - float64(verticalPadding)
// if the label doesn't fit within the padding, we need to add more
if labelOverflowY > 0 {
obj.Height += labelOverflowY
// if label is top, need to shift contents down
switch labelPosition {
case label.InsideTopLeft, label.InsideTopCenter, label.InsideTopRight:
dy = labelOverflowY
}
}
labelOverflowX := occupiedWidth - float64(horizontalPadding)
if labelOverflowX > 0 {
obj.Width += labelOverflowX
if labelPosition == label.InsideMiddleLeft {
dx = labelOverflowX
}
}
}
} }
// we need to center children if we have to expand to fit the container label // we need to center children if we have to expand to fit the container label