Skip to content

Commit

Permalink
Merge pull request #1494 from alixander/label-pad
Browse files Browse the repository at this point in the history
fix icon pad
  • Loading branch information
alixander authored Jul 24, 2023
2 parents 419e4d8 + 2998b7f commit 0402934
Show file tree
Hide file tree
Showing 7 changed files with 611 additions and 5 deletions.
4 changes: 2 additions & 2 deletions d2target/d2target.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point) {
if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_TOP") {
y1 = go2.Min(y1, targetShape.Pos.Y-label.PADDING-size)
} else if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_BOTTOM") {
y2 = go2.Max(y2, targetShape.Pos.Y+label.PADDING+size)
y2 = go2.Max(y2, targetShape.Pos.Y+targetShape.Height+label.PADDING+size)
} else if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_LEFT") {
x1 = go2.Min(x1, targetShape.Pos.X-label.PADDING-size)
} else if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_RIGHT") {
x2 = go2.Max(x2, targetShape.Pos.X+label.PADDING+size)
x2 = go2.Max(x2, targetShape.Pos.X+targetShape.Width+label.PADDING+size)
}
}

Expand Down
19 changes: 19 additions & 0 deletions e2etests/stable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,25 @@ scenarios: {
thunder
}
}`,
},
{
name: "label-near",
script: `
direction: right
x -> y
x: worker {
label.near: top-center
icon: https://icons.terrastruct.com/essentials%2F005-programmer.svg
icon.near: outside-top-right
}
y: profits {
label.near: bottom-right
icon: https://icons.terrastruct.com/essentials%2Fprofits.svg
icon.near: outside-bottom-center
}
`,
},
loadFromFile(t, "arrowhead_scaling"),
loadFromFile(t, "teleport_grid"),
Expand Down
6 changes: 3 additions & 3 deletions e2etests/testdata/stable/icon_positions/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.
202 changes: 202 additions & 0 deletions e2etests/testdata/stable/label-near/dagre/board.exp.json

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

96 changes: 96 additions & 0 deletions e2etests/testdata/stable/label-near/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 0402934

Please sign in to comment.