From 339bd6241fefc1ca5e6db392ac5c8cd370e56222 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 1 Apr 2023 16:45:28 -0700 Subject: [PATCH 1/3] namespace transitions --- d2renderers/d2animate/d2animate.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/d2renderers/d2animate/d2animate.go b/d2renderers/d2animate/d2animate.go index b2f1b3074..7fca92dd7 100644 --- a/d2renderers/d2animate/d2animate.go +++ b/d2renderers/d2animate/d2animate.go @@ -14,23 +14,23 @@ import ( var transitionDurationMS = 1 -func makeKeyframe(delayMS, durationMS, totalMS, identifier int) string { +func makeKeyframe(delayMS, durationMS, totalMS, identifier int, diagramHash string) string { percentageBefore := (math.Max(0, float64(delayMS-transitionDurationMS)) / float64(totalMS)) * 100. percentageStart := (float64(delayMS) / float64(totalMS)) * 100. percentageEnd := (float64(delayMS+durationMS-transitionDurationMS) / float64(totalMS)) * 100. if int(math.Ceil(percentageEnd)) == 100 { - return fmt.Sprintf(`@keyframes d2Transition-%d { + return fmt.Sprintf(`@keyframes d2Transition-%s-%d { 0%%, %f%% { opacity: 0; } %f%%, %f%% { opacity: 1; } -}`, identifier, percentageBefore, percentageStart, math.Ceil(percentageEnd)) +}`, diagramHash, identifier, percentageBefore, percentageStart, math.Ceil(percentageEnd)) } percentageAfter := (float64(delayMS+durationMS) / float64(totalMS)) * 100. - return fmt.Sprintf(`@keyframes d2Transition-%d { + return fmt.Sprintf(`@keyframes d2Transition-%s-%d { 0%%, %f%% { opacity: 0; } @@ -40,7 +40,7 @@ func makeKeyframe(delayMS, durationMS, totalMS, identifier int) string { %f%%, 100%% { opacity: 0; } -}`, identifier, percentageBefore, percentageStart, percentageEnd, percentageAfter) +}`, diagramHash, identifier, percentageBefore, percentageStart, percentageEnd, percentageAfter) } func Wrap(rootDiagram *d2target.Diagram, svgs [][]byte, renderOpts d2svg.RenderOpts, intervalMS int) ([]byte, error) { @@ -99,13 +99,13 @@ func Wrap(rootDiagram *d2target.Diagram, svgs [][]byte, renderOpts d2svg.RenderO fmt.Fprint(buf, ``) for i, svg := range svgs { str := string(svg) - str = strings.Replace(str, " Date: Sat, 1 Apr 2023 16:46:28 -0700 Subject: [PATCH 2/3] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index b043fe110..a5a68a05c 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -9,3 +9,4 @@ - Fix a bug in 32bit builds [#1115](https://github.com/terrastruct/d2/issues/1115) - Fix a bug in ID parsing [#322](https://github.com/terrastruct/d2/issues/322) - Fix a bug in watch mode parsing SVG [#1119](https://github.com/terrastruct/d2/issues/1119) +- Namespace transitions so that multiple animated D2 diagrams can exist on the same page [#1123](https://github.com/terrastruct/d2/issues/1123) From 94d61f7be9610da4ba8096606d306ecaf99e1393 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 1 Apr 2023 20:19:12 -0700 Subject: [PATCH 3/3] regen --- .../testdata/TestCLI_E2E/animation.exp.svg | 16 ++++++++-------- .../TestCLI_E2E/internal_linked_pdf.exp.pdf | Bin 79806 -> 79806 bytes 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg index faaabdb28..c5a1b5b2c 100644 --- a/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg +++ b/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg @@ -838,7 +838,7 @@ .md .contains-task-list:dir(rtl) .task-list-item-checkbox { margin: 0 -1.6em 0.25em 0.2em; } -Chicken's plan +}]]>Chicken's plan -Approach roadChicken's plan +Approach roadChicken's plan -Approach roadCross roadChicken's plan +Approach roadCross roadChicken's plan -Approach roadCross roadMake you wonder whyChicken's plan +Approach roadCross roadMake you wonder whyChicken's plan \ No newline at end of file diff --git a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf index 64ceca2ea4d3658c4e4cb54690b4af536e5b0cfc..463c4cc7a850319782fab64d0a0a7e65fab8a7a9 100644 GIT binary patch delta 70 zcmdn@o@L*AmWC~iUB=UQ8#5YA?=WUGoc`LF@v^FkfuWIsp}DD%CYQc%eu_(CNveW| TiZu?^s#@kE)Y_=9M delta 70 zcmdn@o@L*AmWC~iUB=V*7&Gcm?=WUGn*Q3D@v^G1v4N3+v4yFnCYQc%eu_(CNveW| TiZu?^s#@kE)Zr2t`