diff --git a/d2renderers/d2sketch/sketch.go b/d2renderers/d2sketch/sketch.go
index 4c4913a2b..ea9b7035b 100644
--- a/d2renderers/d2sketch/sketch.go
+++ b/d2renderers/d2sketch/sketch.go
@@ -163,20 +163,6 @@ func Paths(r *Runner, shape d2target.Shape, paths []string) (string, error) {
return output, nil
}
-func connectionStyle(connection d2target.Connection) string {
- out := ""
-
- out += fmt.Sprintf(`stroke:%s;`, connection.Stroke)
- out += fmt.Sprintf(`opacity:%f;`, connection.Opacity)
- out += fmt.Sprintf(`stroke-width:%d;`, connection.StrokeWidth)
- if connection.StrokeDash != 0 {
- dashSize, gapSize := svg.GetStrokeDashAttributes(float64(connection.StrokeWidth), connection.StrokeDash)
- out += fmt.Sprintf(`stroke-dasharray:%f,%f;`, dashSize, gapSize)
- }
-
- return out
-}
-
func Connection(r *Runner, connection d2target.Connection, path, attrs string) (string, error) {
roughness := 1.0
js := fmt.Sprintf(`node = rc.path("%s", {roughness: %f, seed: 1});`, path, roughness)
@@ -185,10 +171,14 @@ func Connection(r *Runner, connection d2target.Connection, path, attrs string) (
return "", err
}
output := ""
+ animatedClass := ""
+ if connection.Animated {
+ animatedClass = " animated-connection"
+ }
for _, p := range paths {
output += fmt.Sprintf(
- ``,
- p, connectionStyle(connection), attrs,
+ ``,
+ animatedClass, p, connection.CSSStyle(), attrs,
)
}
return output, nil
diff --git a/d2renderers/d2sketch/sketch_test.go b/d2renderers/d2sketch/sketch_test.go
index c2b8dadea..f35eb1be7 100644
--- a/d2renderers/d2sketch/sketch_test.go
+++ b/d2renderers/d2sketch/sketch_test.go
@@ -39,6 +39,11 @@ func TestSketch(t *testing.T) {
script: `winter.snow -> summer.sun
`,
},
+ {
+ name: "animated",
+ script: `winter.snow -> summer.sun -> trees -> winter.snow: { style.animated: true }
+ `,
+ },
{
name: "connection label",
script: `a -> b: hello
diff --git a/d2renderers/d2sketch/testdata/animated/sketch.exp.svg b/d2renderers/d2sketch/testdata/animated/sketch.exp.svg
new file mode 100644
index 000000000..25a6c8c99
--- /dev/null
+++ b/d2renderers/d2sketch/testdata/animated/sketch.exp.svg
@@ -0,0 +1,77 @@
+
+
\ No newline at end of file
diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go
index b4b352b67..0f28eccb2 100644
--- a/d2renderers/d2svg/d2svg.go
+++ b/d2renderers/d2svg/d2svg.go
@@ -466,7 +466,7 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co
animatedClass = " animated-connection"
}
fmt.Fprintf(writer, ``,
- path, animatedClass, connectionStyle(connection), attrs)
+ path, animatedClass, connection.CSSStyle(), attrs)
}
if connection.Label != "" {
@@ -966,32 +966,6 @@ func shapeStyle(shape d2target.Shape) string {
return out
}
-func connectionStyle(connection d2target.Connection) string {
- out := ""
-
- out += fmt.Sprintf(`stroke:%s;`, connection.Stroke)
- out += fmt.Sprintf(`opacity:%f;`, connection.Opacity)
- out += fmt.Sprintf(`stroke-width:%d;`, connection.StrokeWidth)
- strokeDash := connection.StrokeDash
- if strokeDash == 0 && connection.Animated {
- strokeDash = 5
- }
- if strokeDash != 0 {
- dashSize, gapSize := svg.GetStrokeDashAttributes(float64(connection.StrokeWidth), strokeDash)
- out += fmt.Sprintf(`stroke-dasharray:%f,%f;`, dashSize, gapSize)
-
- if connection.Animated {
- dashOffset := -10
- if connection.SrcArrow != d2target.NoArrowhead && connection.DstArrow == d2target.NoArrowhead {
- dashOffset = 10
- }
- out += fmt.Sprintf(`stroke-dashoffset:%f;`, float64(dashOffset)*(dashSize+gapSize))
- out += fmt.Sprintf(`animation: dashdraw %fs linear infinite;`, gapSize*0.5)
- }
- }
- return out
-}
-
func embedFonts(buf *bytes.Buffer, fontFamily *d2fonts.FontFamily) {
content := buf.String()
buf.WriteString(`