This commit is contained in:
Gavin Nishizawa 2023-01-31 16:19:22 -08:00
parent 57fa903fe6
commit 491b4b7066
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -749,20 +749,14 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
if fdims == nil { if fdims == nil {
return nil, fmt.Errorf("dimensions for class field %#v not found", f.Text()) return nil, fmt.Errorf("dimensions for class field %#v not found", f.Text())
} }
lineWidth := fdims.Width maxWidth = go2.Max(maxWidth, fdims.Width)
if lineWidth > maxWidth {
maxWidth = lineWidth
}
} }
for _, m := range obj.Class.Methods { for _, m := range obj.Class.Methods {
mdims := GetTextDimensions(mtexts, ruler, m.Text(), go2.Pointer(d2fonts.SourceCodePro)) mdims := GetTextDimensions(mtexts, ruler, m.Text(), go2.Pointer(d2fonts.SourceCodePro))
if mdims == nil { if mdims == nil {
return nil, fmt.Errorf("dimensions for class method %#v not found", m.Text()) return nil, fmt.Errorf("dimensions for class method %#v not found", m.Text())
} }
lineWidth := mdims.Width maxWidth = go2.Max(maxWidth, mdims.Width)
if lineWidth > maxWidth {
maxWidth = lineWidth
}
} }
// ┌─PrefixWidth ┌─CenterPadding // ┌─PrefixWidth ┌─CenterPadding
// ┌─┬─┬───────┬──────┬───┬──┐ // ┌─┬─┬───────┬──────┬───┬──┐
@ -802,9 +796,7 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
} }
c.Name.LabelWidth = nameDims.Width c.Name.LabelWidth = nameDims.Width
c.Name.LabelHeight = nameDims.Height c.Name.LabelHeight = nameDims.Height
if maxNameWidth < nameDims.Width { maxNameWidth = go2.Max(maxNameWidth, nameDims.Width)
maxNameWidth = nameDims.Width
}
typeDims := GetTextDimensions(mtexts, ruler, ctexts[1], fontFamily) typeDims := GetTextDimensions(mtexts, ruler, ctexts[1], fontFamily)
if typeDims == nil { if typeDims == nil {
@ -815,6 +807,7 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
if maxTypeWidth < typeDims.Width { if maxTypeWidth < typeDims.Width {
maxTypeWidth = typeDims.Width maxTypeWidth = typeDims.Width
} }
maxTypeWidth = go2.Max(maxTypeWidth, typeDims.Width)
if c.Constraint != "" { if c.Constraint != "" {
// covers UNQ constraint with padding // covers UNQ constraint with padding
@ -1103,7 +1096,7 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
if dslShape == d2target.ShapeCircle || dslShape == d2target.ShapeSquare { if dslShape == d2target.ShapeCircle || dslShape == d2target.ShapeSquare {
sideLength := DEFAULT_SHAPE_SIZE sideLength := DEFAULT_SHAPE_SIZE
if desiredWidth != 0 || desiredHeight != 0 { if desiredWidth != 0 || desiredHeight != 0 {
sideLength = math.Max(float64(desiredWidth), float64(desiredHeight)) sideLength = float64(go2.Max(desiredWidth, desiredHeight))
} }
obj.Width = sideLength obj.Width = sideLength
obj.Height = sideLength obj.Height = sideLength