Wiki ▸ [[API Reference]] ▸ [[Geometry]] ▸ Voronoi Geom
Voronoi layouts are particularly useful for invisible interactive regions, as demonstrated in Nate Vack’s Voronoi picking example. See Tovi Grossman’s paper on bubble cursors for a related concept.
# d3.geom.voronoi()
Creates a Voronoi layout with default accessors.
# voronoi(data)
Returns an array of polygons, one for each input vertex in the specified data array. Each polygon is an array of points, and each point is a two-element array of x and y positions.
If any vertices are coincident or have NaN
positions, the behavior of this method is undefined: most likely, invalid polygons will be returned! You should filter invalid vertices, and consolidate coincident vertices, before calling this function.
# voronoi.x([x])
If x is specified, sets the x-coordinate accessor. If x is not specified, returns the current x-coordinate accessor, which defaults to:
function(d) { return d[0]; }
# voronoi.y([y])
If y is specified, sets the y-coordinate accessor. If y is not specified, returns the current y-coordinate accessor, which defaults to:
function(d) { return d[1]; }
# voronoi.clipExtent([extent])
If extent is specified, sets the clip extent of the Voronoi layout to the specified bounds and returns the layout. The extent bounds are specified as an array [[x0, y0], [x1, y1]], where x0 is the left side of the extent, y0 is the top, x1 is the right and y1 is the bottom. If extent is null
, no clipping is performed. If extent is not specified, returns the current clip extent which defaults to null
.
See this example. Use of a clip extent is strongly recommended, as unclipped polygons may have large coordinates which do not display correctly.
Alternatively, you can also employ custom clipping without specifying a size, either in SVG or by post-processing with polygon.clip.
# voronoi.links(data)
Returns the Delaunay triangulation of the specified data array as an array of links. Each link has the following attributes:
- source - the source node (an element in data).
- target - the target node (an element in data).
The Force-Directed States of America uses an array of such links to create a force-directed graph.
# voronoi.triangles(data)
Returns the Delaunay triangulation of the specified data array as an array of triangles. Each triangle is a three-element array containing elements from data.