grid: don't overwrite nested graph label positions

This commit is contained in:
Gavin Nishizawa 2023-05-26 16:38:20 -07:00
parent 962f3445f5
commit 297819dc35
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -139,7 +139,9 @@ func withoutGridDiagrams(ctx context.Context, g *d2graph.Graph, layout d2graph.L
} }
} }
if obj.LabelPosition == nil {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
}
gridDiagrams[obj.AbsID()] = gd gridDiagrams[obj.AbsID()] = gd
for _, o := range gd.objects { for _, o := range gd.objects {
@ -191,12 +193,19 @@ 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 { if o.Icon != nil {
// don't overwrite position if nested graph layout positioned label/icon
if o.LabelPosition == nil {
o.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) o.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
}
if o.IconPosition == nil {
o.IconPosition = go2.Pointer(string(label.InsideMiddleCenter)) o.IconPosition = go2.Pointer(string(label.InsideMiddleCenter))
}
} else { } else {
if o.LabelPosition == nil {
o.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) o.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
} }
} }
}
return gd, nil return gd, nil
} }