Create contours from non-gridded data with meandering triangles.
npm install d3-tricontourThis library computes contour polygons by applying meandering triangles to an array of points with arbitrary 2D coordinates (_x_, _y_) holding numeric values _z_. To compute contours on gridded coordinates, see d3-contour instead. To compute contours on geographic data, see d3.geoContour.
For examples, see the tricontours collection on Observable.
If you use npm, npm install d3-tricontour. You can also download the latest release on GitHub. For vanilla HTML in modern browsers, import d3-tricontour from Skypack:
``html`
For legacy environments, you can load d3-tricontour’s UMD bundle from an npm-based CDN such as jsDelivr; a d3 global is exported:
`html
const tric = d3.tricontour();
const contours = tric([[0, 0, 1], [1, 1, 0], [2, 0, 1]]);
> Array(11) [ {type: "MultiPolygon", coordinates: Array(1), value: 0} … ]
`
The API of tricontour is similar to that of d3-contour:
# d3.tricontour() · Source, Examples
Constructs a new tricontour generator with the default settings.
# _tricontour_(_data_) · Examples
Returns an array of contours, one for each threshold. The contours are MultiPolygons in GeoJSON format, that contain all the points with a value larger than the threshold. The value is indicated as _geometry_.value.
The _data_ is passed as an array of points, by default with the format [x, y, value].
# _tricontour_.contour(_data_[, _threshold_])
Returns a contour, as a MultiPolygon in GeoJSON format, containing all points with a value larger or equal to _threshold_. The threshold is indicated as _geometry_.value
# _tricontour_.contours(_data_)
Returns an iterable over the contours.
# _tricontour_.isobands(_data_)
Returns an iterable over the isobands: contours between pairs of consecutive threshold values _v0_ (inclusive) and _v1_ (exclusive). _geometry_.value is equal to _v0_, _geometry_.valueMax to _v1_.
# _tricontour_.x([_x_])
Sets the x accessor. Defaults to \d => d[0]\. If _x_ is not given, returns the current x accessor.
# _tricontour_.y([_y_])
Sets the y accessor. Defaults to \d => d[1]\. If _y_ is not given, returns the current y accessor.
# _tricontour_.value([_value_])
Sets the value accessor. Defaults to \d => d[2]\`. Values must be defined and finite. If _value_ is not given, returns the current value accessor.
# _tricontour_.thresholds([_thresholds_])
Sets the thresholds, either explicitly as an array of values, or as a count that will be passed to d3.ticks. If empty, returns the current thresholds.
_The following are experimental_
These methods are used in d3-geo-voronoi’s geoContour.
# _tricontour_.triangulate([_triangulate_])
Sets the triangulate function. Defaults to d3.Delaunay.from. For detailed examples, see Reusing a tricontour triangulation, UK tricontour, and Multipolygon tricontour.
# _tricontour_.pointInterpolate(_[pointInterpolate]_)
Sets the pointInterpolate function. Arguments: i, j, 0≤a<1. Defaults to linear interpolation between the coordinates of points i and j.
# _tricontour_.ringsort(_[ringsort]_)
Sets the ringsort function.