improve label placement for shapes with icons
This commit is contained in:
parent
d78a460b64
commit
e2b510a1c8
2 changed files with 4 additions and 4 deletions
|
|
@ -93,7 +93,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
|||
|
||||
height := obj.Height
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
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.InsideTopCenter))
|
||||
} else {
|
||||
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
|||
|
||||
walk(g.Root, nil, func(obj, parent *d2graph.Object) {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -259,7 +259,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
|||
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.InsideTopCenter))
|
||||
} else {
|
||||
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue