fix: cr, calc labelPosition
This commit is contained in:
parent
0df9abc056
commit
a21f5ec438
1 changed files with 19 additions and 22 deletions
|
|
@ -80,8 +80,9 @@ func place(obj *d2graph.Object) (float64, float64) {
|
||||||
w := br.X - tl.X
|
w := br.X - tl.X
|
||||||
h := br.Y - tl.Y
|
h := br.Y - tl.Y
|
||||||
|
|
||||||
|
nearKeyStr := d2graph.Key(obj.Attributes.NearKey)[0]
|
||||||
var x, y float64
|
var x, y float64
|
||||||
switch d2graph.Key(obj.Attributes.NearKey)[0] {
|
switch nearKeyStr {
|
||||||
case "top-left":
|
case "top-left":
|
||||||
x, y = tl.X-obj.Width-pad, tl.Y-obj.Height-pad
|
x, y = tl.X-obj.Width-pad, tl.Y-obj.Height-pad
|
||||||
break
|
break
|
||||||
|
|
@ -108,31 +109,27 @@ func place(obj *d2graph.Object) (float64, float64) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return calcLabelDimension(obj, x, y)
|
if !strings.Contains(*obj.LabelPosition, "INSIDE") && obj.LabelPosition != nil {
|
||||||
}
|
|
||||||
|
|
||||||
func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, float64) {
|
|
||||||
var position string
|
|
||||||
if obj.LabelPosition != nil {
|
|
||||||
if strings.Contains(*obj.LabelPosition, "_TOP_") {
|
if strings.Contains(*obj.LabelPosition, "_TOP_") {
|
||||||
position = "TOP"
|
// label is on the top, and container is placed on the bottom
|
||||||
|
if strings.Contains(nearKeyStr, "bottom") {
|
||||||
|
y += float64(*obj.LabelHeight)
|
||||||
|
}
|
||||||
} else if strings.Contains(*obj.LabelPosition, "_LEFT_") {
|
} else if strings.Contains(*obj.LabelPosition, "_LEFT_") {
|
||||||
position = "LEFT"
|
// label is on the left, and container is placed on the right
|
||||||
|
if strings.Contains(nearKeyStr, "bottom") {
|
||||||
|
x += float64(*obj.LabelWidth)
|
||||||
|
}
|
||||||
} else if strings.Contains(*obj.LabelPosition, "_RIGHT_") {
|
} else if strings.Contains(*obj.LabelPosition, "_RIGHT_") {
|
||||||
position = "RIGHT"
|
// label is on the right, and container is placed on the left
|
||||||
|
if strings.Contains(nearKeyStr, "bottom") {
|
||||||
|
x -= float64(*obj.LabelWidth)
|
||||||
|
}
|
||||||
} else if strings.Contains(*obj.LabelPosition, "_BOTTOM_") {
|
} else if strings.Contains(*obj.LabelPosition, "_BOTTOM_") {
|
||||||
position = "BOTTOM"
|
// label is on the bottom, and container is placed on the top
|
||||||
}
|
if strings.Contains(nearKeyStr, "top") {
|
||||||
|
y -= float64(*obj.LabelHeight)
|
||||||
switch position {
|
}
|
||||||
case "TOP":
|
|
||||||
return x, y - float64(*obj.LabelHeight)
|
|
||||||
case "BOTTOM":
|
|
||||||
return x, y + float64(*obj.LabelHeight)
|
|
||||||
case "LEFT":
|
|
||||||
return x - float64(*obj.LabelWidth), y
|
|
||||||
case "RIGHT":
|
|
||||||
return x + float64(*obj.LabelWidth), y
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue