move person labels to outside bottom
This commit is contained in:
parent
e2c1f313ce
commit
609b3e5eb3
5 changed files with 25 additions and 9 deletions
|
|
@ -447,6 +447,18 @@ func (obj *Object) IsContainer() bool {
|
||||||
return len(obj.Children) > 0
|
return len(obj.Children) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (obj *Object) HasOutsideBottomLabel() bool {
|
||||||
|
if obj == nil || obj.Attributes == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch obj.Attributes.Shape.Value {
|
||||||
|
case d2target.ShapeImage, d2target.ShapePerson:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (obj *Object) AbsID() string {
|
func (obj *Object) AbsID() string {
|
||||||
if obj.Parent != nil && obj.Parent.ID != "" {
|
if obj.Parent != nil && obj.Parent.ID != "" {
|
||||||
return obj.Parent.AbsID() + "." + obj.ID
|
return obj.Parent.AbsID() + "." + obj.ID
|
||||||
|
|
@ -1326,7 +1338,13 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fitWidth, fitHeight := s.GetDimensionsToFit(contentBox.Width, contentBox.Height, paddingX, paddingY)
|
var fitWidth, fitHeight float64
|
||||||
|
if shapeType == shape.PERSON_TYPE {
|
||||||
|
fitWidth = contentBox.Width + paddingX
|
||||||
|
fitHeight = contentBox.Height + paddingY
|
||||||
|
} else {
|
||||||
|
fitWidth, fitHeight = s.GetDimensionsToFit(contentBox.Width, contentBox.Height, paddingX, paddingY)
|
||||||
|
}
|
||||||
obj.Width = math.Max(float64(desiredWidth), fitWidth)
|
obj.Width = math.Max(float64(desiredWidth), fitWidth)
|
||||||
obj.Height = math.Max(float64(desiredHeight), fitHeight)
|
obj.Height = math.Max(float64(desiredHeight), fitHeight)
|
||||||
if s.AspectRatio1() {
|
if s.AspectRatio1() {
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
|
|
||||||
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 || obj.Attributes.Icon != nil {
|
if obj.HasOutsideBottomLabel() || obj.Attributes.Icon != nil {
|
||||||
height += float64(*obj.LabelHeight) + label.PADDING
|
height += float64(*obj.LabelHeight) + label.PADDING
|
||||||
}
|
}
|
||||||
if len(obj.ChildrenArray) > 0 {
|
if len(obj.ChildrenArray) > 0 {
|
||||||
|
|
@ -217,7 +217,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
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.OutsideTopCenter))
|
obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
|
||||||
} else if obj.Attributes.Shape.Value == d2target.ShapeImage {
|
} else if obj.HasOutsideBottomLabel() {
|
||||||
obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
|
obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
|
||||||
// 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
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
height := obj.Height
|
height := obj.Height
|
||||||
width := obj.Width
|
width := obj.Width
|
||||||
if obj.LabelWidth != nil && obj.LabelHeight != nil {
|
if obj.LabelWidth != nil && obj.LabelHeight != nil {
|
||||||
if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
|
if obj.HasOutsideBottomLabel() || obj.Attributes.Icon != nil {
|
||||||
height += float64(*obj.LabelHeight) + label.PADDING
|
height += float64(*obj.LabelHeight) + label.PADDING
|
||||||
}
|
}
|
||||||
width = go2.Max(width, float64(*obj.LabelWidth))
|
width = go2.Max(width, float64(*obj.LabelWidth))
|
||||||
|
|
@ -332,7 +332,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
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 {
|
} else if obj.HasOutsideBottomLabel() {
|
||||||
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 {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2graph"
|
"oss.terrastruct.com/d2/d2graph"
|
||||||
"oss.terrastruct.com/d2/d2target"
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/label"
|
"oss.terrastruct.com/d2/lib/label"
|
||||||
"oss.terrastruct.com/util-go/go2"
|
"oss.terrastruct.com/util-go/go2"
|
||||||
|
|
@ -43,7 +42,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
|
||||||
|
|
||||||
// These shapes skipped core layout, which means they also skipped label placements
|
// These shapes skipped core layout, which means they also skipped label placements
|
||||||
for _, obj := range constantNears {
|
for _, obj := range constantNears {
|
||||||
if obj.Attributes.Shape.Value == d2target.ShapeImage {
|
if obj.HasOutsideBottomLabel() {
|
||||||
obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
|
obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
|
||||||
} else if obj.Attributes.Icon != nil {
|
} else if obj.Attributes.Icon != nil {
|
||||||
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
|
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
|
||||||
|
|
|
||||||
|
|
@ -335,9 +335,8 @@ func (sd *sequenceDiagram) adjustGroupLabel(group *d2graph.Object) {
|
||||||
func (sd *sequenceDiagram) placeActors() {
|
func (sd *sequenceDiagram) placeActors() {
|
||||||
centerX := sd.actors[0].Width / 2.
|
centerX := sd.actors[0].Width / 2.
|
||||||
for rank, actor := range sd.actors {
|
for rank, actor := range sd.actors {
|
||||||
shape := actor.Attributes.Shape.Value
|
|
||||||
var yOffset float64
|
var yOffset float64
|
||||||
if shape == d2target.ShapeImage || shape == d2target.ShapePerson {
|
if actor.HasOutsideBottomLabel() {
|
||||||
actor.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
|
actor.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter))
|
||||||
yOffset = sd.maxActorHeight - actor.Height
|
yOffset = sd.maxActorHeight - actor.Height
|
||||||
if actor.LabelHeight != nil {
|
if actor.LabelHeight != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue