vasturiano / force-graph

Force-directed graph rendered on HTML5 canvas
https://vasturiano.github.io/force-graph/example/directional-links-particles/
MIT License
1.59k stars 248 forks source link

Catch exception on acyclic data #84

Open ravik3592 opened 4 years ago

ravik3592 commented 4 years ago

I need to catch the exception and do few operations when exception occurs, but usual try catch not working in forced graph init. I need to render dag mode tree, if cyclic error occurs i need to redirect to dag mode off Is there any way to achieve this.

vasturiano commented 4 years ago

@ravik3592 the interpretation of the node/link topology data is performed at every animation frame, in an asynchronous method separate from the main thread. That's why you can't handle those errors with a try/catch block. The best is if you detect those cycles before feeding the data to the library. If you need some help with that, you can look at the internal source code that performs that graph traversal algorithm: https://github.com/vasturiano/force-graph/blob/master/src/dagDepths.js