feat: honor delay field on graph nodes and edges for staggered animations#87
Merged
Merged
Conversation
…ions
The backend has historically populated a 'delay' field on nodes and links
returned by graph visualizations, but the frontend D3 renderer in
StandardGraphSvgReact.js was painting all colors statically and discarding
the delay entirely. This made it impossible for any backend visualization
to express step-by-step or layered animations - the field was effectively
dead data on round-trip.
This change makes the renderer honor the delay field via D3 transitions:
- parseInt-based getDelayMs() helper safely parses the backend's string
delay into a positive number of milliseconds; 0 / missing / non-numeric
values mean 'render at final color immediately, no animation' so existing
visualizations are unaffected
- Nodes with delay > 0 start at the default Background color and transition
to their final d.color after the delay
- Links with delay > 0 start at the default Edges color and transition
similarly
- Arrowhead markers on directed edges follow their parent link's animation
so heads stay in sync
- All transitions use a 500 ms fade-in for smoothness
Backwards compatible: visualizations that do not set delay (or set it to 0)
render exactly as before. Visualizations that DO set delay - including
DirectedHamiltonian, ShortestPath, and the Topological Sort rank-based
animation in the companion backend PR - now produce visible staggered
animations that previously did nothing.
Companion PR: ReduxISU/Redux#194
5 tasks
Collaborator
Author
|
Companion backend PR: ReduxISU/Redux#194 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: honor
delayfield on graph nodes and edges for staggered animationsContext
This PR is the frontend half of a two-PR change that addresses review feedback on a backend contribution.
Backend PR: ReduxISU/Redux#194 — fix: address review feedback on Topological Sort (PR #178)
The reviewer (@Andrija-Sevaljevic) on the original Topological Sort merge (Redux#178) flagged the visualization as not making logical sense for the problem and suggested either removing it or implementing a new template on the front-end:
This frontend PR enables a meaningful animated visualization for Topological Sort (and any other graph problem that wants stepped animation) by making the existing D3 renderer honor the backend's
delayfield instead of discarding it. This unblocks the rank-based animation implemented in the backend PR.Problem
The C# backend has, for a long time, populated a
delayfield on nodes and links returned by graph-style visualizations:{ "name": "2", "color": "Solution", "delay": "1250", ... }But the frontend D3 renderer in
StandardGraphSvgReact.jspainted every color statically with.attr("fill", ...)/.style("stroke", ...)and never read thedelayfield. A repository-wide search fordelay,transition,setTimeout, oranimateincomponents/andpages/returned zero matches.The effect: every backend visualization that set
delay(DirectedHamiltonian, ShortestPath, Topological Sort, etc.) was producing dead round-trip data. Solutions appeared instantly with no temporal cue, even when the algorithm being visualized is fundamentally about ordering or progression.Fix
Updated
StandardGraphSvgReact.jsso the D3 renderer honorsdelayvia transitions:getDelayMs(d)helper — safely parses the backend's stringdelayinto a positive number of ms. Returns0for missing, empty, non-numeric, or non-positive values, which the rest of the code treats as "render at final color immediately, no animation."Links — if
delay > 0, start at the defaultEdgescolor, then.transition().delay(delayMs).duration(500).style("stroke", finalColor).Arrowhead markers on directed links — same animation as their parent link, so heads stay color-synced with the line.
Nodes — if
delay > 0, start atBackground, then transition tod.colorafter the delay.Constant
FADE_DURATION_MS = 500controls the smoothness of the fade-in for all transitioning elements.Backwards compatibility
delay(or set it to0/""/ non-numeric) render exactly as before — same colors, same timing.delaynow animate. This includesDirectedHamiltonianandShortestPath, which were already setting delays that the frontend silently discarded — they get the upgrade for free.problemDatashape is unchanged.Verification
Tested locally with the backend PR #194 against several instances:
({1,2,3,4,5,6},{(1,2),(1,3),(2,4),(3,4),(4,5),(3,6)})({1,2,3},{(1,2),(2,3),(3,1)}){}; visualize returns un-highlighted graph; no animation triggered (correct)delayTest plan
delayare visually unchangedTeam