https://github.com/fil/d3-tricontour
Create contours from non-gridded data with meandering triangles.
https://github.com/fil/d3-tricontour
contours d3 d3-module delaunay triangulation
Last synced: 2 months ago
JSON representation
Create contours from non-gridded data with meandering triangles.
- Host: GitHub
- URL: https://github.com/fil/d3-tricontour
- Owner: Fil
- License: isc
- Created: 2019-08-25T12:17:44.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-18T20:26:27.000Z (almost 2 years ago)
- Last Synced: 2024-04-18T13:23:25.006Z (about 1 year ago)
- Topics: contours, d3, d3-module, delaunay, triangulation
- Language: JavaScript
- Size: 438 KB
- Stars: 36
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# d3-tricontour
This library computes contour polygons by applying [meandering triangles](https://blog.bruce-hill.com/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](https://github.com/d3/d3-contour) instead. To compute contours on geographic data, see [d3.geoContour](https://github.com/Fil/d3-geo-voronoi/blob/main/README.md#contours).
For examples, see the [tricontours collection](https://observablehq.com/collection/@fil/tricontours) on Observable.
## Installing
If you use npm, `npm install d3-tricontour`. You can also download the [latest release on GitHub](https://github.com/d3/d3-tricontour/releases/latest). For vanilla HTML in modern browsers, import d3-tricontour from Skypack:
```html
import {tricontour} from "https://cdn.skypack.dev/d3-tricontour@1";
```
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} … ]
```
## API Reference
The API of tricontour is similar to that of [d3-contour](https://github.com/d3/d3-contour):
# d3.tricontour() · [Source](https://github.com/Fil/d3-tricontour/blob/main/src/tricontour.js), [Examples](https://observablehq.com/collection/@fil/tricontours)
Constructs a new tricontour generator with the default settings.
[
](https://observablehq.com/@fil/tricontours)
# _tricontour_(_data_) · [Examples](https://observablehq.com/@fil/tricontours)
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].
[
](https://observablehq.com/@fil/tricontour-flower)
# _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.
[
](https://observablehq.com/@fil/tricontour-iterator)
# _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_.
[
](https://observablehq.com/@fil/tricontour-isobands)
# _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.
[
](https://observablehq.com/@fil/d3-hexbin-tricontours-heatmap)
# _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](https://github.com/Fil/d3-geo-voronoi/blob/main/README.md#contours).
[
](https://observablehq.com/@fil/spherical-contours)
# _tricontour_.triangulate([_triangulate_])
Sets the *triangulate* function. Defaults to d3.Delaunay.from. See [Reusing a tricontour triangulation](https://observablehq.com/@fil/reusing-a-tricontour-triangulation) and [UK tricontour](https://observablehq.com/@fil/tricontours-with-a-personalized-triangulation) for detailed examples.
[
](https://observablehq.com/@fil/tricontours-with-a-personalized-triangulation)
# _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.