Skip to content

Commit

Permalink
Merge pull request #763 from alixander/fix-padding
Browse files Browse the repository at this point in the history
Fix padding
  • Loading branch information
alixander authored Feb 5, 2023
2 parents c546cf0 + a6086ba commit 0da4e15
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 37 deletions.
20 changes: 14 additions & 6 deletions d2graph/d2graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,17 +1241,25 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
s := shape.NewShape(shapeType, contentBox)

paddingX, paddingY := s.GetDefaultPadding()
if desiredWidth != 0 || desiredHeight != 0 {
if desiredWidth != 0 {
paddingX = 0.
}
if desiredHeight != 0 {
paddingY = 0.
} else {
// give shapes with icons extra padding to fit their label
if obj.Attributes.Icon != nil {
labelHeight := float64(labelDims.Height + INNER_LABEL_PADDING)
// Evenly pad enough to fit label above icon
}

// give shapes with icons extra padding to fit their label
if obj.Attributes.Icon != nil {
labelHeight := float64(labelDims.Height + INNER_LABEL_PADDING)
// Evenly pad enough to fit label above icon
if desiredWidth == 0 {
paddingX += labelHeight
}
if desiredHeight == 0 {
paddingY += labelHeight
}
}
if desiredWidth == 0 {
switch shapeType {
case shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE, shape.IMAGE_TYPE:
default:
Expand Down
8 changes: 8 additions & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ class2: class without rows {
}
},
},
{
name: "just-width",
script: `x: "teamwork: having someone to blame" {
width: 100
}
`,
},
}

runa(t, tcs)
Expand Down
48 changes: 48 additions & 0 deletions e2etests/testdata/regression/just-width/dagre/board.exp.json

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

52 changes: 52 additions & 0 deletions e2etests/testdata/regression/just-width/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.
48 changes: 48 additions & 0 deletions e2etests/testdata/regression/just-width/elk/board.exp.json

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

52 changes: 52 additions & 0 deletions e2etests/testdata/regression/just-width/elk/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.
32 changes: 16 additions & 16 deletions e2etests/testdata/stable/people/dagre/board.exp.json

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

6 changes: 3 additions & 3 deletions e2etests/testdata/stable/people/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.
18 changes: 9 additions & 9 deletions e2etests/testdata/stable/people/elk/board.exp.json

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

Loading

0 comments on commit 0da4e15

Please sign in to comment.