update grid cell label/icon positioning

This commit is contained in:
Gavin Nishizawa 2023-10-16 16:04:12 -07:00
parent 69ad220acd
commit c647c6fb2e
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -156,16 +156,27 @@ func layoutGrid(g *d2graph.Graph, obj *d2graph.Object) (*gridDiagram, error) {
// position labels and icons // position labels and icons
for _, o := range gd.objects { for _, o := range gd.objects {
if o.Icon != nil { positionedLabel := false
// don't overwrite position if nested graph layout positioned label/icon if o.Icon != nil && o.IconPosition == nil {
if o.LabelPosition == nil { if len(o.ChildrenArray) > 0 {
o.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) o.IconPosition = go2.Pointer(string(label.OutsideTopLeft))
} // don't overwrite position if nested graph layout positioned label/icon
if o.IconPosition == nil { if o.LabelPosition == nil {
o.LabelPosition = go2.Pointer(string(label.OutsideTopRight))
positionedLabel = true
}
} else {
o.IconPosition = go2.Pointer(string(label.InsideMiddleCenter)) o.IconPosition = go2.Pointer(string(label.InsideMiddleCenter))
} }
} else { }
if o.LabelPosition == nil { if !positionedLabel && o.HasLabel() && o.LabelPosition == nil {
if len(o.ChildrenArray) > 0 {
o.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
} else if o.HasOutsideBottomLabel() {
o.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
} else if o.Icon != nil {
o.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
} else {
o.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) o.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
} }
} }