Giter VIP home page Giter VIP logo

d3-tricontour's Introduction

d3-tricontour

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. To compute contours on geographic data, see d3.geoContour.

For examples, see the tricontours collection on Observable.

Installing

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:

<script type="module">
import {tricontour} from "https://cdn.skypack.dev/d3-tricontour@1";
</script>

For legacy environments, you can load d3-tricontour’s UMD bundle from an npm-based CDN such as jsDelivr; a d3 global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3-scale@4"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-delaunay@6"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-tricontour@1"></script>
<script>

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}  ]
  
</script>

API Reference

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

# d3.tricontour() · Source, Examples

Constructs a new tricontour generator with the default settings.

tricontours

# 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].

tricontours 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

# 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

# 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

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

geoContour

# tricontour.triangulate([triangulate])

Sets the triangulate function. Defaults to d3.Delaunay.from. See Reusing a tricontour triangulation and UK tricontour for detailed examples.

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

d3-tricontour's People

Contributors

dependabot[bot] avatar fil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

d3-tricontour's Issues

extent ?

Ease the creation of tricontours that extend beyond the hull, by adding "fake" points along a path. Maybe this should be just a few examples, with:

  • four corners
  • many points along a rectangle
  • many points along a circle.

packaging improvements?

@Fil I remember you asking in the d3 slack about JavaScript module packaging. Are you happy with the current state of d3-tricontour's packaging?

Would you like to me work on some specific improvements that you have in mind?

Or perhaps, would you like me to take a quick look, and suggest some packaging improvements?

Edge Polygons Misaligned by a Small Margin

I've been using the d3-contour library, and want to switch back to the d3-tricontour library. I notice that the the polygons around the edge are not quite as well aligned in d3-tricontour as they are in d3-contour. Is this possible/easy to fix?

d3-contour polygon edges

image

dr-tricontour polygon edges

image

Does this support constrained delaunay triangulation?

I've had a quick look into your library, which looks impressive.

I'm wondering about whether it's possible to "constrain" certain vertices so that contours may not cross those lines. This is important when you want to generate contours for real world terrain and ensure that contours don't accidentally cross over a ridgeline or valley.

Is it true that this library uses d3-delaunay for the triangulation? Perhaps if that library doesn't support it, I wonder if cdt-js might be able to swapped in as a replacement triangulation library.

Has anyone had any experience with this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.