Skip to content

Commit

Permalink
Merge pull request #189 from alixander/shape-stroke-dash
Browse files Browse the repository at this point in the history
render: Support stroke-dash on shapes
  • Loading branch information
alixander authored Nov 24, 2022
2 parents 1f2baff + bbf005c commit d084b8d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#### Features 🚀

- Arrowhead labels are now supported. [#182](https://github.com/terrastruct/d2/pull/182)
- `stroke-dash` on shapes is now supported. [#188](https://github.com/terrastruct/d2/issues/188)

#### Improvements 🔧

Expand Down
4 changes: 4 additions & 0 deletions d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,10 @@ func shapeStyle(shape d2target.Shape) string {
out += fmt.Sprintf(`stroke:%s;`, shape.Stroke)
out += fmt.Sprintf(`opacity:%f;`, shape.Opacity)
out += fmt.Sprintf(`stroke-width:%d;`, shape.StrokeWidth)
if shape.StrokeDash != 0 {
dashSize, gapSize := getStrokeDashAttributes(float64(shape.StrokeWidth), shape.StrokeDash)
out += fmt.Sprintf(`stroke-dasharray:%f,%f;`, dashSize, gapSize)
}

return out
}
Expand Down
1 change: 1 addition & 0 deletions e2etests/stable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ x: {
y: {
style: {
stroke-dash: 5
opacity: 0.6
fill: red
3d: true
Expand Down
2 changes: 1 addition & 1 deletion e2etests/testdata/stable/stylish/dagre/board.exp.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"height": 126,
"level": 1,
"opacity": 0.6,
"strokeDash": 0,
"strokeDash": 5,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "red",
Expand Down
2 changes: 1 addition & 1 deletion e2etests/testdata/stable/stylish/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.
2 changes: 1 addition & 1 deletion e2etests/testdata/stable/stylish/elk/board.exp.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"height": 126,
"level": 1,
"opacity": 0.6,
"strokeDash": 0,
"strokeDash": 5,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "red",
Expand Down
2 changes: 1 addition & 1 deletion e2etests/testdata/stable/stylish/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.

0 comments on commit d084b8d

Please sign in to comment.