This commit is contained in:
Gavin Nishizawa 2022-12-28 15:58:00 -08:00
parent e45f78b50c
commit 73d1a666e1
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 19 additions and 27 deletions

View file

@ -2,12 +2,11 @@
- Tooltips can be set on shapes. See [https://d2lang.com/tour/tooltips](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548) - Tooltips can be set on shapes. See [https://d2lang.com/tour/tooltips](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548)
- Links can be set on shapes. See [https://d2lang.com/tour/tooltips](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548) - Links can be set on shapes. See [https://d2lang.com/tour/tooltips](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548)
- The `width` and `height` attributes are no longer restricted to images and can be applied to non-container shapes. [#498](https://github.com/terrastruct/d2/pull/498)
#### Improvements 🧹 #### Improvements 🧹
- Now the `width` and `height` attributes are no longer restricted to images and can be applied to non-container shapes. [#498](https://github.com/terrastruct/d2/pull/498)
#### Bugfixes ⛑️ #### Bugfixes ⛑️
- Restricts where `near` key constant values can be used, with good error messages, instead of erroring (e.g. setting `near: top-center` on a container would cause bad layouts or error). [#538](https://github.com/terrastruct/d2/pull/538) - Restricts where `near` key constant values can be used, with good error messages, instead of erroring (e.g. setting `near: top-center` on a container would cause bad layouts or error). [#538](https://github.com/terrastruct/d2/pull/538)
- Fixed rendering classes and tables with empty headers. [#498](https://github.com/terrastruct/d2/pull/498) - Fixes rendering classes and tables with empty headers. [#498](https://github.com/terrastruct/d2/pull/498)

View file

@ -899,13 +899,13 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
for _, obj := range g.Objects { for _, obj := range g.Objects {
obj.Box = &geo.Box{} obj.Box = &geo.Box{}
var setWidth int var desiredWidth int
var setHeight int var desiredHeight int
if obj.Attributes.Width != nil { if obj.Attributes.Width != nil {
setWidth, _ = strconv.Atoi(obj.Attributes.Width.Value) desiredWidth, _ = strconv.Atoi(obj.Attributes.Width.Value)
} }
if obj.Attributes.Height != nil { if obj.Attributes.Height != nil {
setHeight, _ = strconv.Atoi(obj.Attributes.Height.Value) desiredHeight, _ = strconv.Atoi(obj.Attributes.Height.Value)
} }
shapeType := strings.ToLower(obj.Attributes.Shape.Value) shapeType := strings.ToLower(obj.Attributes.Shape.Value)
@ -917,7 +917,7 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
d2target.ShapeText: d2target.ShapeText:
// edge cases for unnamed class, etc // edge cases for unnamed class, etc
default: default:
if obj.Attributes.Label.Value == "" && setWidth == 0 && setHeight == 0 { if obj.Attributes.Label.Value == "" && desiredWidth == 0 && desiredHeight == 0 {
obj.Width = 100 obj.Width = 100
obj.Height = 100 obj.Height = 100
continue continue
@ -980,38 +980,31 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
dims.Width += innerLabelPadding dims.Width += innerLabelPadding
dims.Height += innerLabelPadding dims.Height += innerLabelPadding
obj.LabelDimensions = *dims obj.LabelDimensions = *dims
obj.Width = float64(dims.Width) // the desired dimensions must be at least as large as the text
obj.Height = float64(dims.Height) obj.Width = float64(go2.Max(dims.Width, desiredWidth))
obj.Height = float64(go2.Max(dims.Height, desiredHeight))
// the set dimensions must be at least as large as the text
if float64(setWidth) > obj.Width {
obj.Width = float64(setWidth)
}
if float64(setHeight) > obj.Height {
obj.Height = float64(setHeight)
}
switch shapeType { switch shapeType {
default: default:
if setWidth == 0 { if desiredWidth == 0 {
obj.Width += 100 obj.Width += 100
} }
if setHeight == 0 { if desiredHeight == 0 {
obj.Height += 100 obj.Height += 100
} }
case d2target.ShapeImage: case d2target.ShapeImage:
if setWidth == 0 { if desiredWidth == 0 {
obj.Width = 128 obj.Width = 128
} }
if setHeight == 0 { if desiredHeight == 0 {
obj.Height = 128 obj.Height = 128
} }
case d2target.ShapeSquare, d2target.ShapeCircle: case d2target.ShapeSquare, d2target.ShapeCircle:
sideLength := go2.Max(obj.Width, obj.Height) sideLength := go2.Max(obj.Width, obj.Height)
padding := 0. padding := 0.
if setWidth == 0 && setHeight == 0 { if desiredWidth == 0 && desiredHeight == 0 {
padding = 100. padding = 100.
} }
obj.Width = sideLength + padding obj.Width = sideLength + padding
@ -1104,11 +1097,11 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
d2target.ShapeSQLTable, d2target.ShapeSQLTable,
d2target.ShapeCode, d2target.ShapeCode,
d2target.ShapeText: d2target.ShapeText:
if float64(setWidth) > obj.Width { if float64(desiredWidth) > obj.Width {
obj.Width = float64(setWidth) obj.Width = float64(desiredWidth)
} }
if float64(setHeight) > obj.Height { if float64(desiredHeight) > obj.Height {
obj.Height = float64(setHeight) obj.Height = float64(desiredHeight)
} }
} }