MCPcopy Create free account
hub / github.com/breck7/scroll / contour

Function contour

external/.d3.js:6423–6450  ·  view source on GitHub ↗
(values, value)

Source from the content-addressed store, hash-verified

6421 // Accumulate, smooth contour rings, assign holes to exterior rings.
6422 // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
6423 function contour(values, value) {
6424 const v = value == null ? NaN : +value;
6425 if (isNaN(v)) throw new Error(`invalid value: ${value}`);
6426
6427 var polygons = [],
6428 holes = [];
6429
6430 isorings(values, v, function(ring) {
6431 smooth(ring, values, v);
6432 if (area$3(ring) > 0) polygons.push([ring]);
6433 else holes.push(ring);
6434 });
6435
6436 holes.forEach(function(hole) {
6437 for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
6438 if (contains$2((polygon = polygons[i])[0], hole) !== -1) {
6439 polygon.push(hole);
6440 return;
6441 }
6442 }
6443 });
6444
6445 return {
6446 type: "MultiPolygon",
6447 value: value,
6448 coordinates: polygons
6449 };
6450 }
6451
6452 // Marching squares with isolines stitched into rings.
6453 // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js

Callers 1

contoursFunction · 0.85

Calls 5

isoringsFunction · 0.85
area$3Function · 0.85
contains$2Function · 0.85
forEachMethod · 0.80
transformFunction · 0.70

Tested by

no test coverage detected