skyork
skyork

Reputation: 7391

Consistent graph drawing

Is there a Javascript library that produces consistent graph drawings (e.g. graph theory style graphs) in browsers?

By consistent, I mean that it produces an unique graph (same orientation and same positions of nodes) given a set of inputs (i.e. configurations of the nodes and edges).

Upvotes: 1

Views: 512

Answers (1)

Tamás
Tamás

Reputation: 48071

Most graph layout algorithms (except the completely deterministic ones like grid layout or the Reingold-Tilford tree layout) use some kind of random initialization. Since there is no way to set the seed of the random number generator explicitly in Javascript, it is very hard to coerce graph layout algorithms into being completely deterministic. Your best bet is probably to take an existing library in Javascript that can draw graphs (such as d3.js) and replace the calls to Math.random and similar to a pure Javascript-based random number generator for which you can set the seed explicitly. Setting the seed to the same value should then ensure that the same layout is generated for the same graph every time you run the algorithm.

Implementations of Javascript random number generators can be found here, here or here.

Upvotes: 4

Related Questions