limit oval shape aspect ratio
This commit is contained in:
parent
c1313c7480
commit
4de1f76751
3 changed files with 12 additions and 3 deletions
|
|
@ -1296,8 +1296,11 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
|
|||
obj.Width = sideLength
|
||||
obj.Height = sideLength
|
||||
} else if desiredHeight == 0 || desiredWidth == 0 {
|
||||
if s.GetType() == shape.PERSON_TYPE {
|
||||
switch s.GetType() {
|
||||
case shape.PERSON_TYPE:
|
||||
obj.Width, obj.Height = shape.LimitAR(obj.Width, obj.Height, shape.PERSON_AR_LIMIT)
|
||||
case shape.OVAL_TYPE:
|
||||
obj.Width, obj.Height = shape.LimitAR(obj.Width, obj.Height, shape.OVAL_AR_LIMIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func newSequenceDiagram(objects []*d2graph.Object, messages []*d2graph.Edge) *se
|
|||
if actor.Width < MIN_ACTOR_WIDTH {
|
||||
dslShape := strings.ToLower(actor.Attributes.Shape.Value)
|
||||
switch dslShape {
|
||||
case d2target.ShapePerson, d2target.ShapeSquare, d2target.ShapeCircle:
|
||||
case d2target.ShapePerson, d2target.ShapeOval, d2target.ShapeSquare, d2target.ShapeCircle:
|
||||
// scale shape up to min width uniformly
|
||||
actor.Height *= MIN_ACTOR_WIDTH / actor.Width
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"oss.terrastruct.com/util-go/go2"
|
||||
)
|
||||
|
||||
const OVAL_AR_LIMIT = 3.
|
||||
|
||||
type shapeOval struct {
|
||||
*baseShape
|
||||
}
|
||||
|
|
@ -38,7 +40,11 @@ func (s shapeOval) GetDimensionsToFit(width, height, paddingX, paddingY float64)
|
|||
paddedWidth := width + paddingX*math.Cos(theta)
|
||||
paddedHeight := height + paddingY*math.Sin(theta)
|
||||
// see https://stackoverflow.com/questions/433371/ellipse-bounding-a-rectangle
|
||||
return math.Ceil(math.Sqrt2 * paddedWidth), math.Ceil(math.Sqrt2 * paddedHeight)
|
||||
totalWidth, totalHeight := math.Ceil(math.Sqrt2*paddedWidth), math.Ceil(math.Sqrt2*paddedHeight)
|
||||
|
||||
// prevent oval from becoming too flat
|
||||
totalWidth, totalHeight = LimitAR(totalWidth, totalHeight, OVAL_AR_LIMIT)
|
||||
return totalWidth, totalHeight
|
||||
}
|
||||
|
||||
func (s shapeOval) GetInsidePlacement(width, height, paddingX, paddingY float64) geo.Point {
|
||||
|
|
|
|||
Loading…
Reference in a new issue