An open API service indexing awesome lists of open source software.

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.

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.

[tricontours](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].

[tricontours flower](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.

[iterable](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_.

[isobands](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.

[hexbin heatmap](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).

[geoContour](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.

[UK tricontour](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.