/voronoijs

Voronoi.js is a Voronoi treemap generator in JavaScript.

Primary LanguageLiveScriptMIT LicenseMIT

Voronoi.js

Voronoi Treemap Example

Voronoi.js is a Voronoi treemap generator in JavaScript. Demonstration

Usage

Include voronoi.min.js:

<script type="text/javascript" src="voronoi.min.js"></script>

then, prepare your data:

var data = {
  children: [
    {value: 100},
    {value: 200},
    {value: 300}
  ],
};

and initialize a voronoi treemap instance:

var width = 800, height = 600;
var treemap = new Voronoi.Treemap(data, Polygon.create(width, height, 100), width, height);

compute and render your treemap as your wish:

setInterval(function() {
  treemap.compute();
  render();
}, 100);

function render() {
  var polygons = treemap.getPolygons(); /* Polygons for treemap */
  var sites = treemap.getSites(); /* correspond to every data node */
}

here we have polygons as point array, for example, a triangle:

[{x: 0, y: 0}, {x: 100, y: 100}, {x: 200, y: 100}]

and coordinates in data nodes:

{value: 100, x: 23.4849230, y: 123: 12671238, lv: 0}, ...

You can use lv to determine depth of the node.

License

MIT License.