Pause traversing of tree hierarchy

I am trying to visualize post-order traversal on a tree.

What I want is to wait for the user to press a key, lets say the ‘up-arrow-key’ before continuing to the next step in the eachAfter iteration. Is there a way to do this?

root.copy().eachAfter((currentNode) => {
           //Code that colors the current node here.
           // Wait until the user press up arrow key before moving to the next iteration.
})

here’s an example that might help: https://observablehq.com/d/070bd7cbff491236

This was exactly what I needed! Thanks :slight_smile:

1 Like