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
}
}
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
if obj.LabelPosition == nil {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
}
gridDiagrams[obj.AbsID()] = gd
for _, o := range gd.objects {
@ -191,10 +193,17 @@ func layoutGrid(g *d2graph.Graph, obj *d2graph.Object) (*gridDiagram, error) {
// position labels and icons
for _, o := range gd.objects {
if o.Icon != nil {
o.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
o.IconPosition = go2.Pointer(string(label.InsideMiddleCenter))
// don't overwrite position if nested graph layout positioned label/icon
if o.LabelPosition == nil {
o.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
}
if o.IconPosition == nil {
o.IconPosition = go2.Pointer(string(label.InsideMiddleCenter))
}
} else {
o.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
if o.LabelPosition == nil {
o.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
}
}
}