improve label placement for shapes with icons

This commit is contained in:
Gavin Nishizawa 2022-12-19 20:48:01 -08:00
parent d78a460b64
commit e2b510a1c8
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 4 additions and 4 deletions

View file

@ -93,7 +93,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
height := obj.Height height := obj.Height
if obj.LabelWidth != nil && obj.LabelHeight != nil { if obj.LabelWidth != nil && obj.LabelHeight != nil {
if obj.Attributes.Shape.Value == d2target.ShapeImage { if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
height += float64(*obj.LabelHeight) + label.PADDING height += float64(*obj.LabelHeight) + label.PADDING
} }
} }
@ -163,7 +163,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
// remove the extra height we added to the node when passing to dagre // remove the extra height we added to the node when passing to dagre
obj.Height -= float64(*obj.LabelHeight) + label.PADDING obj.Height -= float64(*obj.LabelHeight) + label.PADDING
} else if obj.Attributes.Icon != nil { } else if obj.Attributes.Icon != nil {
obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
} else { } else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
} }

View file

@ -143,7 +143,7 @@ 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 height := obj.Height
if obj.Attributes.Shape.Value == d2target.ShapeImage { if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
height += float64(*obj.LabelHeight) + label.PADDING height += float64(*obj.LabelHeight) + label.PADDING
} }
@ -259,7 +259,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter)) obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
obj.Height -= float64(*obj.LabelHeight) + label.PADDING obj.Height -= float64(*obj.LabelHeight) + label.PADDING
} else if obj.Attributes.Icon != nil { } else if obj.Attributes.Icon != nil {
obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
} else { } else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
} }