I think the key element of this implementation is a library I used to handle graph data: https://github.com/dagrejs/graphlib
With the same library I made this other type of labyrinthic, somehow typographic sketches.
http://gallery.bananabanana.me/p5js/lillian-pattern/dist/index.html
I also made a tiny game out of those sketches where you are a dot that need to get to the bottom of the screen without bumping on the other dot.
http://bananabanana.me/labirinto.html
I'm also experimenting with a larger labyrinth and partial view:
http://bananabanana.me/labirinto3.html
Both are playable with keyboard and swipe gestures.