From 6f26167beb865a32ffb5f8b3b4701b0ae16f34b9 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Mon, 23 Jan 2023 17:19:38 -0800 Subject: [PATCH] fix class dimensions --- d2graph/d2graph.go | 9 ++++----- d2target/class.go | 3 +++ lib/shape/shape_class.go | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 65f60cdb9..d92f90233 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -750,7 +750,7 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R return nil, fmt.Errorf("dimensions for class field %#v not found", f.Text()) } lineWidth := fdims.Width - if maxWidth < lineWidth { + if lineWidth > maxWidth { maxWidth = lineWidth } } @@ -760,11 +760,11 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R return nil, fmt.Errorf("dimensions for class method %#v not found", m.Text()) } lineWidth := mdims.Width - if maxWidth < lineWidth { + if lineWidth > maxWidth { maxWidth = lineWidth } } - dims.Width = maxWidth + dims.Width = d2target.PrefixPadding + d2target.PrefixWidth + maxWidth + d2target.CenterPadding + d2target.TypePadding // All rows should be the same height var anyRowText *d2target.MText @@ -774,8 +774,7 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R anyRowText = obj.Class.Methods[0].Text() } if anyRowText != nil { - // 10px of padding top and bottom so text doesn't look squished - rowHeight := GetTextDimensions(mtexts, ruler, anyRowText, go2.Pointer(d2fonts.SourceCodePro)).Height + 20 + rowHeight := GetTextDimensions(mtexts, ruler, anyRowText, go2.Pointer(d2fonts.SourceCodePro)).Height + d2target.VerticalPadding dims.Height = rowHeight * (len(obj.Class.Fields) + len(obj.Class.Methods) + 2) } else { dims.Height = go2.Max(12, labelDims.Height) diff --git a/d2target/class.go b/d2target/class.go index f62a3ea43..3cc39921e 100644 --- a/d2target/class.go +++ b/d2target/class.go @@ -9,6 +9,9 @@ import ( const ( PrefixPadding = 10 PrefixWidth = 20 + CenterPadding = 50 + // 10px of padding top and bottom so text doesn't look squished + VerticalPadding = 20 ) type Class struct { diff --git a/lib/shape/shape_class.go b/lib/shape/shape_class.go index 4b9bafc19..3f7f67a12 100644 --- a/lib/shape/shape_class.go +++ b/lib/shape/shape_class.go @@ -21,6 +21,5 @@ func NewClass(box *geo.Box) Shape { } func (s shapeClass) GetDefaultPadding() (paddingX, paddingY float64) { - // TODO fix class row width measurements (see SQL table) - return 100, 0 + return 0, 0 }