Skip to content

Commit

Permalink
Merge pull request #2250 from alixander/shape-animate
Browse files Browse the repository at this point in the history
allow animated: true for shape
  • Loading branch information
alixander authored Dec 15, 2024
2 parents 0dbd981 + e6cedef commit f3d2120
Show file tree
Hide file tree
Showing 1,219 changed files with 81,948 additions and 71,056 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Features 🚀

- Animations: `style.animated: true` is supported on shapes [#2250](https://github.com/terrastruct/d2/pull/2250)
- Connections now support `link` [#1955](https://github.com/terrastruct/d2/pull/1955)
- Vars: vars in markdown blocks are substituted [#2218](https://github.com/terrastruct/d2/pull/2218)
- Markdown: Github-flavored tables work in `md` blocks [#2221](https://github.com/terrastruct/d2/pull/2221)
Expand Down
3 changes: 0 additions & 3 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,6 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
return
}
c.compileStyle(&obj.Attributes, f.Map())
if obj.Style.Animated != nil {
c.errorf(obj.Style.Animated.MapKey, `key "animated" can only be applied to edges`)
}
return
}

Expand Down
1 change: 0 additions & 1 deletion d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,6 @@ x: {
style.animated: true
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/shape_edge_style.d2:3:2: key "animated" can only be applied to edges`,
},
{
name: "edge_invalid_style",
Expand Down
3 changes: 3 additions & 0 deletions d2exporter/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape {
if obj.Tooltip != nil {
shape.Tooltip = obj.Tooltip.Value
}
if obj.Style.Animated != nil {
shape.Animated, _ = strconv.ParseBool(obj.Style.Animated.Value)
}
if obj.Link != nil {
shape.Link = obj.Link.Value
shape.PrettyLink = toPrettyLink(g, obj.Link.Value)
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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/animated/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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/animated_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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/arrowheads/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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/arrowheads_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/basic/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/basic_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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/child_to_child/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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/child_to_child_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/class/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
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/class_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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/connection-style-fill/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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/connection_label/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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/connection_label_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/crows_feet/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/crows_feet_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-3d/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.
166 changes: 83 additions & 83 deletions d2renderers/d2sketch/testdata/dots-real/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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/double-border/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/elk_corners/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.
160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/long_arrowhead_label/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.
568 changes: 284 additions & 284 deletions d2renderers/d2sketch/testdata/opacity/sketch.exp.svg

Large diffs are not rendered by default.

568 changes: 284 additions & 284 deletions d2renderers/d2sketch/testdata/opacity_dark/sketch.exp.svg

Large diffs are not rendered by default.

154 changes: 77 additions & 77 deletions d2renderers/d2sketch/testdata/overlay/sketch.exp.svg

Large diffs are not rendered by default.

166 changes: 83 additions & 83 deletions d2renderers/d2sketch/testdata/paper-real/sketch.exp.svg

Large diffs are not rendered by default.

562 changes: 281 additions & 281 deletions d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg

Large diffs are not rendered by default.

154 changes: 77 additions & 77 deletions d2renderers/d2sketch/testdata/sql_tables/sketch.exp.svg

Large diffs are not rendered by default.

154 changes: 77 additions & 77 deletions d2renderers/d2sketch/testdata/sql_tables_dark/sketch.exp.svg

Large diffs are not rendered by default.

166 changes: 83 additions & 83 deletions d2renderers/d2sketch/testdata/terminal/sketch.exp.svg

Large diffs are not rendered by default.

568 changes: 284 additions & 284 deletions d2renderers/d2sketch/testdata/twitter/sketch.exp.svg

Large diffs are not rendered by default.

568 changes: 284 additions & 284 deletions d2renderers/d2sketch/testdata/twitter_dark/sketch.exp.svg

Large diffs are not rendered by default.

160 changes: 80 additions & 80 deletions d2renderers/d2sketch/testdata/unfilled_triangle/sketch.exp.svg

Large diffs are not rendered by default.

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/appendix/testdata/internal-links/sketch.exp.svg

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/appendix/testdata/links/sketch.exp.svg

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/appendix/testdata/links_dark/sketch.exp.svg

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/appendix/testdata/tooltip_fill/sketch.exp.svg

Large diffs are not rendered by default.

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,10 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
fmt.Fprint(writer, clipPathForBorderRadius(diagramHash, targetShape))
}
classStr := ""
if targetShape.Animated {
// the animated class applies to the whole svg group to include the label, unlike connections
targetShape.Classes = append(targetShape.Classes, "animated-shape")
}
if len(targetShape.Classes) > 0 {
classStr = fmt.Sprintf(` class="%s"`, strings.Join(targetShape.Classes, " "))
}
Expand Down Expand Up @@ -1633,6 +1637,23 @@ func EmbedFonts(buf *bytes.Buffer, diagramHash, source string, fontFamily *d2fon
`,
)

appendOnTrigger(
buf,
source,
[]string{
`animated-shape`,
},
`
@keyframes shapeappear {
0%, 100% { transform: translateY(0); filter: drop-shadow(0px 0px 0px rgba(0,0,0,0)); }
50% { transform: translateY(-4px); filter: drop-shadow(0px 12.6px 25.2px rgba(50,50,93,0.25)) drop-shadow(0px 7.56px 15.12px rgba(0,0,0,0.1)); }
}
.animated-shape {
animation: shapeappear 1s linear infinite;
}
`,
)

appendOnTrigger(
buf,
source,
Expand Down
152 changes: 76 additions & 76 deletions d2renderers/d2svg/dark_theme/testdata/all_shapes/dark_theme.exp.svg

Large diffs are not rendered by default.

158 changes: 79 additions & 79 deletions d2renderers/d2svg/dark_theme/testdata/animated/dark_theme.exp.svg

Large diffs are not rendered by default.

158 changes: 79 additions & 79 deletions d2renderers/d2svg/dark_theme/testdata/arrowheads/dark_theme.exp.svg

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/dark_theme/testdata/basic/dark_theme.exp.svg

Large diffs are not rendered by default.

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/dark_theme/testdata/class/dark_theme.exp.svg

Large diffs are not rendered by default.

568 changes: 284 additions & 284 deletions d2renderers/d2svg/dark_theme/testdata/code/dark_theme.exp.svg

Large diffs are not rendered by default.

Large diffs are not rendered by default.

568 changes: 284 additions & 284 deletions d2renderers/d2svg/dark_theme/testdata/opacity/dark_theme.exp.svg

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/dark_theme/testdata/overlay/dark_theme.exp.svg

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions d2renderers/d2svg/dark_theme/testdata/sql_tables/dark_theme.exp.svg

Large diffs are not rendered by default.

568 changes: 284 additions & 284 deletions d2renderers/d2svg/dark_theme/testdata/twitter/dark_theme.exp.svg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions d2target/d2target.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ type Shape struct {
FillPattern string `json:"fillPattern,omitempty"`
Stroke string `json:"stroke"`

Animated bool `json:"animated"`
Shadow bool `json:"shadow"`
ThreeDee bool `json:"3d"`
Multiple bool `json:"multiple"`
Expand Down
152 changes: 76 additions & 76 deletions e2etests-cli/testdata/TestCLI_E2E/abspath.exp.svg

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions e2etests-cli/testdata/TestCLI_E2E/board_import/hello-world-x-y.exp.svg
Loading

0 comments on commit f3d2120

Please sign in to comment.