0.0.5 • Published 5 years ago

tricontours v0.0.5

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
5 years ago

tricontours

This 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.

Installing

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:

<script src="https://unpkg.com/d3-scale@3"></script>
<script src="https://unpkg.com/d3-delaunay@5"></script>
<script src="https://unpkg.com/tricontours@0.0.5"></script>
<script>

const tri = tricontours.tricontours();
const contours = tri([[0, 0, 1], [1, 1, 0], [2, 0, 1]]);

</script>

API Reference

The API of tricontours is similar to that of d3-contour:

# tricontours() · Source, Examples

Constructs a new tricontours generator with the default settings.

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 => d0`. If x is not given, returns the current x accessor.

# tricontours.y(y)

Sets the y accessor. Defaults to `d => d1`. If y is not given, returns the current y accessor.

# tricontours.value(value)

Sets the value accessor. Defaults to `d => d2`. 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.

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago