Create contours from non-gridded data with meandering triangles.
npm install tricontoursThis 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.
For examples, see the contours collection on Observable.
If you use NPM, npm install tricontours. Otherwise, download the latest release. You can also load directly as a standalone library. ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a tricontours global is exported:
``html
const tri = tricontours.tricontours();
const contours = tri([[0, 0, 1], [1, 1, 0], [2, 0, 1]]);
`
The API of tricontours is similar to that of d3-contour:
# tricontours() · Source, Examples
Constructs a new tricontours generator with the default settings.
`js`
const tri = tricontours();
# _tricontours_(_data_)
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].
# _tricontours_.contour(_data_[, _value_])
Returns a contour, as a MultiPolygon in GeoJSON format, containing all points with a value larger or equal to _value_. The value is indicated as _geometry_.value
# _tricontours_.contours(_data_)
Returns an iterable over the contours.
# _tricontours_.isobands(_data_)
Returns an iterable over the isobands (contours between pairs of consecutive threshold values). _geometry_.value is equal to [value0, value1].
# _tricontours_.x([_x_])
Sets the x accessor. Defaults to \d => d[0]\. If _x_ is not given, returns the current x accessor.
# _tricontours_.y([_y_])
Sets the y accessor. Defaults to \d => d[1]\. If _y_ is not given, returns the current y accessor.
# _tricontours_.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.
# _tricontours_.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 still experimental_
# _tricontours_.triangulate([_triangulate_])
Sets the triangulate function. Defaults to d3.Delaunay.from. See UK tricontours for a detailed example.
# _tricontours_.pointInterpolate(_[pointInterpolate]_)
Sets the pointInterpolate function. Arguments: i, j, 0≤a<1. Defaults to linear interpolation between the coordinates of points i and j. See Spherical tricontours for a detailed example.