update images for elk

This commit is contained in:
Gavin Nishizawa 2022-12-19 20:15:35 -08:00
parent f7d6f418ee
commit 45162a5f6e
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -142,10 +142,15 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
} }
walk(g.Root, nil, func(obj, parent *d2graph.Object) { walk(g.Root, nil, func(obj, parent *d2graph.Object) {
height := obj.Height
if obj.Attributes.Shape.Value == d2target.ShapeImage {
height += float64(*obj.LabelHeight) + label.PADDING
}
n := &ELKNode{ n := &ELKNode{
ID: obj.AbsID(), ID: obj.AbsID(),
Width: obj.Width, Width: obj.Width,
Height: obj.Height, Height: height,
} }
if len(obj.ChildrenArray) > 0 { if len(obj.ChildrenArray) > 0 {
@ -250,7 +255,10 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
if obj.LabelWidth != nil && obj.LabelHeight != nil { if obj.LabelWidth != nil && obj.LabelHeight != nil {
if len(obj.ChildrenArray) > 0 { if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
} else if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil { } else if obj.Attributes.Shape.Value == d2target.ShapeImage {
obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
obj.Height -= float64(*obj.LabelHeight) + label.PADDING
} else if obj.Attributes.Icon != nil {
obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
} else { } else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))