Skip to content

Commit

Permalink
Merge pull request #1736 from gavin-ts/fix-cloud-innerbox
Browse files Browse the repository at this point in the history
Fix cloud innerbox
  • Loading branch information
gavin-ts authored Nov 21, 2023
2 parents 4a30bd2 + 84c7854 commit 14db474
Show file tree
Hide file tree
Showing 62 changed files with 3,714 additions and 2,499 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
- Fixes edge case where nested edge globs were creating excess shapes [#1713](https://github.com/terrastruct/d2/pull/1713)
- Fixes a panic with a connection to a grid cell that is a container in TALA [#1729](https://github.com/terrastruct/d2/pull/1729)
- Fixes incorrect grid cell positioning when the grid has a shape set and fixes content sometimes escaping circle shapes. [#1734](https://github.com/terrastruct/d2/pull/1734)
- Fixes content sometimes escaping cloud shapes. [#1736](https://github.com/terrastruct/d2/pull/1736)
4 changes: 4 additions & 0 deletions d2exporter/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func toShape(obj *d2graph.Object, theme *d2themes.Theme) d2target.Shape {
case d2target.ShapeSQLTable:
shape.SQLTable = *obj.SQLTable
shape.FontSize -= d2target.HeaderFontAdd
case d2target.ShapeCloud:
if obj.ContentAspectRatio != nil {
shape.ContentAspectRatio = go2.Pointer(*obj.ContentAspectRatio)
}
}
shape.Label = text.Text
shape.LabelWidth = text.Dimensions.Width
Expand Down
8 changes: 7 additions & 1 deletion d2graph/d2graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type Object struct {
LabelPosition *string `json:"labelPosition,omitempty"`
IconPosition *string `json:"iconPosition,omitempty"`

ContentAspectRatio *float64 `json:"contentAspectRatio,omitempty"`

Class *d2target.Class `json:"class,omitempty"`
SQLTable *d2target.SQLTable `json:"sql_table,omitempty"`

Expand Down Expand Up @@ -1068,13 +1070,17 @@ func (obj *Object) SizeToContent(contentWidth, contentHeight, paddingX, paddingY
obj.Width = sideLength
obj.Height = sideLength
} else if desiredHeight == 0 || desiredWidth == 0 {
switch s.GetType() {
switch shapeType {
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)
}
}
if shapeType == shape.CLOUD_TYPE {
innerBox := s.GetInnerBoxForContent(contentWidth, contentHeight)
obj.ContentAspectRatio = go2.Pointer(innerBox.Width / innerBox.Height)
}
}

func (obj *Object) OuterNearContainer() *Object {
Expand Down
6 changes: 5 additions & 1 deletion d2graph/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ func (obj *Object) ToShape() shape.Shape {
dslShape := strings.ToLower(obj.Shape.Value)
shapeType := d2target.DSL_SHAPE_TO_SHAPE_TYPE[dslShape]
contentBox := geo.NewBox(tl, obj.Width, obj.Height)
return shape.NewShape(shapeType, contentBox)
s := shape.NewShape(shapeType, contentBox)
if shapeType == shape.CLOUD_TYPE && obj.ContentAspectRatio != nil {
s.SetInnerBoxAspectRatio(*obj.ContentAspectRatio)
}
return s
}

func (obj *Object) GetLabelTopLeft() *geo.Point {
Expand Down
1 change: 0 additions & 1 deletion d2layouts/d2grid/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func Layout(ctx context.Context, g *d2graph.Graph) error {
// depending on the shape innerBox may be larger than totalWidth, totalHeight
// if this is the case, we want to center the cells within the larger innerBox
innerBox := s.GetInnerBox()

var resizeDx, resizeDy float64
if innerBox.Width > totalWidth {
resizeDx = (innerBox.Width - totalWidth) / 2
Expand Down
154 changes: 77 additions & 77 deletions d2renderers/d2sketch/testdata/all_shapes/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 77 additions & 77 deletions d2renderers/d2sketch/testdata/all_shapes_dark/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 77 additions & 77 deletions d2renderers/d2sketch/testdata/dots-all/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 77 additions & 77 deletions d2renderers/d2sketch/testdata/dots-multiple/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
shapeType := d2target.DSL_SHAPE_TO_SHAPE_TYPE[targetShape.Type]

s := shape.NewShape(shapeType, geo.NewBox(tl, width, height))
if shapeType == shape.CLOUD_TYPE && targetShape.ContentAspectRatio != nil {
s.SetInnerBoxAspectRatio(*targetShape.ContentAspectRatio)
}

var shadowAttr string
if targetShape.Shadow {
Expand Down
152 changes: 76 additions & 76 deletions d2renderers/d2svg/dark_theme/testdata/all_shapes/dark_theme.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions d2target/d2target.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ type Shape struct {
Class
SQLTable

ContentAspectRatio *float64 `json:"contentAspectRatio,omitempty"`

Text

LabelPosition string `json:"labelPosition,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ cf many required: {
loadFromFile(t, "grid_image_label_position"),
loadFromFile(t, "glob_dimensions"),
loadFromFile(t, "shaped_grid_positioning"),
loadFromFile(t, "cloud_shaped_grid"),
}

runa(t, tcs)
Expand Down
27 changes: 27 additions & 0 deletions e2etests/testdata/files/cloud_shaped_grid.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
vars: {
grid-container: {
label: ""
grid-gap: 10
grid-rows: 1
grid-columns: 4
a
b
c
d
}
}
cloud: {
shape: cloud
...${grid-container}
width: 395
height: 395
}

circle: {
shape: circle
...${grid-container}
width: 395
height: 395
}

direction: right
1 change: 1 addition & 0 deletions e2etests/testdata/patterns/all_shapes/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

156 changes: 78 additions & 78 deletions e2etests/testdata/patterns/all_shapes/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions e2etests/testdata/patterns/multiple/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

156 changes: 78 additions & 78 deletions e2etests/testdata/patterns/multiple/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions e2etests/testdata/patterns/paper/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

156 changes: 78 additions & 78 deletions e2etests/testdata/patterns/paper/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 14db474

Please sign in to comment.