fix multiple class attributes with animate

This commit is contained in:
Alexander Wang 2025-02-04 10:23:26 -07:00
parent 6eb792329d
commit 20d4165428
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927

View file

@ -554,11 +554,11 @@ func drawConnection(writer io.Writer, diagramHash string, connection d2target.Co
opacityStyle = fmt.Sprintf(" style='opacity:%f'", connection.Opacity) opacityStyle = fmt.Sprintf(" style='opacity:%f'", connection.Opacity)
} }
classStr := "" classes := []string{base64.URLEncoding.EncodeToString([]byte(svg.EscapeText(connection.ID)))}
if len(connection.Classes) > 0 { classes = append(classes, connection.Classes...)
classStr = fmt.Sprintf(` class="%s"`, strings.Join(connection.Classes, " ")) classStr := fmt.Sprintf(` class="%s"`, strings.Join(classes, " "))
}
fmt.Fprintf(writer, `<g class="%s"%s%s>`, base64.URLEncoding.EncodeToString([]byte(svg.EscapeText(connection.ID))), opacityStyle, classStr) fmt.Fprintf(writer, `<g%s%s>`, opacityStyle, classStr)
var markerStart string var markerStart string
if connection.SrcArrow != d2target.NoArrowhead { if connection.SrcArrow != d2target.NoArrowhead {
id := arrowheadMarkerID(diagramHash, false, connection) id := arrowheadMarkerID(diagramHash, false, connection)
@ -1026,15 +1026,13 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
if targetShape.BorderRadius != 0 && (targetShape.Type == d2target.ShapeClass || targetShape.Type == d2target.ShapeSQLTable) { if targetShape.BorderRadius != 0 && (targetShape.Type == d2target.ShapeClass || targetShape.Type == d2target.ShapeSQLTable) {
fmt.Fprint(writer, clipPathForBorderRadius(diagramHash, targetShape)) fmt.Fprint(writer, clipPathForBorderRadius(diagramHash, targetShape))
} }
classStr := "" classes := []string{base64.URLEncoding.EncodeToString([]byte(svg.EscapeText(targetShape.ID)))}
if targetShape.Animated { if targetShape.Animated {
// the animated class applies to the whole svg group to include the label, unlike connections classes = append(classes, "animated-shape")
targetShape.Classes = append(targetShape.Classes, "animated-shape")
} }
if len(targetShape.Classes) > 0 { classes = append(classes, targetShape.Classes...)
classStr = fmt.Sprintf(` class="%s"`, strings.Join(targetShape.Classes, " ")) classStr := fmt.Sprintf(` class="%s"`, strings.Join(classes, " "))
} fmt.Fprintf(writer, `<g%s%s>`, opacityStyle, classStr)
fmt.Fprintf(writer, `<g class="%s"%s%s>`, base64.URLEncoding.EncodeToString([]byte(svg.EscapeText(targetShape.ID))), opacityStyle, classStr)
tl := geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y)) tl := geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y))
width := float64(targetShape.Width) width := float64(targetShape.Width)
height := float64(targetShape.Height) height := float64(targetShape.Height)