Socket
Socket
Sign inDemoInstall

d3-contour

Package Overview
Dependencies
2
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

33

dist/d3-contour.js

@@ -1,7 +0,7 @@

// https://d3js.org/d3-contour/ v2.0.0 Copyright 2020 Mike Bostock
// https://d3js.org/d3-contour/ v3.0.0 Copyright 2021 Mike Bostock
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-array'], factory) :
(global = global || self, factory(global.d3 = global.d3 || {}, global.d3));
}(this, function (exports, d3Array) { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3));
}(this, (function (exports, d3Array) { 'use strict';

@@ -84,5 +84,4 @@ var array = Array.prototype;

if (!Array.isArray(tz)) {
var domain = d3Array.extent(values), start = domain[0], stop = domain[1];
tz = d3Array.tickStep(start, stop, tz);
tz = d3Array.range(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
const e = d3Array.extent(values), ts = d3Array.tickStep(e[0], e[1], tz);
tz = d3Array.ticks(Math.floor(e[0] / ts) * ts, Math.floor(e[1] / ts - 1) * ts, tz);
} else {

@@ -92,5 +91,3 @@ tz = tz.slice().sort(ascending);

return tz.map(function(value) {
return contour(values, value);
});
return tz.map(value => contour(values, value));
}

@@ -323,10 +320,18 @@

var values0 = new Float32Array(n * m),
values1 = new Float32Array(n * m);
values1 = new Float32Array(n * m),
pow2k = Math.pow(2, -k);
data.forEach(function(d, i, data) {
var xi = (+x(d, i, data) + o) >> k,
yi = (+y(d, i, data) + o) >> k,
var xi = (x(d, i, data) + o) * pow2k,
yi = (y(d, i, data) + o) * pow2k,
wi = +weight(d, i, data);
if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
values0[xi + yi * n] += wi;
var x0 = Math.floor(xi),
y0 = Math.floor(yi),
xt = xi - x0 - 0.5,
yt = yi - y0 - 0.5;
values0[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
values0[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
values0[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
values0[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
}

@@ -430,2 +435,2 @@ });

}));
})));

@@ -1,2 +0,2 @@

// https://d3js.org/d3-contour/ v2.0.0 Copyright 2020 Mike Bostock
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-array"],r):r((t=t||self).d3=t.d3||{},t.d3)}(this,function(t,r){"use strict";var n=Array.prototype.slice;function e(t,r){return t-r}var i=t=>()=>t;function a(t,r){for(var n,e=-1,i=r.length;++e<i;)if(n=o(t,r[e]))return n;return 0}function o(t,r){for(var n=r[0],e=r[1],i=-1,a=0,o=t.length,f=o-1;a<o;f=a++){var u=t[a],c=u[0],d=u[1],l=t[f],s=l[0],g=l[1];if(h(u,l,r))return 0;d>e!=g>e&&n<(s-c)*(e-d)/(g-d)+c&&(i=-i)}return i}function h(t,r,n){var e,i,a,o;return function(t,r,n){return(r[0]-t[0])*(n[1]-t[1])==(n[0]-t[0])*(r[1]-t[1])}(t,r,n)&&(i=t[e=+(t[0]===r[0])],a=n[e],o=r[e],i<=a&&a<=o||o<=a&&a<=i)}function f(){}var u=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function c(){var t=1,o=1,h=r.thresholdSturges,c=g;function d(t){var n=h(t);if(Array.isArray(n))n=n.slice().sort(e);else{var i=r.extent(t),a=i[0],o=i[1];n=r.tickStep(a,o,n),n=r.range(Math.floor(a/n)*n,Math.floor(o/n)*n,n)}return n.map(function(r){return l(t,r)})}function l(r,n){var e=[],i=[];return function(r,n,e){var i,a,h,f,c,d,l=new Array,g=new Array;i=a=-1,f=r[0]>=n,u[f<<1].forEach(v);for(;++i<t-1;)h=f,f=r[i+1]>=n,u[h|f<<1].forEach(v);u[f<<0].forEach(v);for(;++a<o-1;){for(i=-1,f=r[a*t+t]>=n,c=r[a*t]>=n,u[f<<1|c<<2].forEach(v);++i<t-1;)h=f,f=r[a*t+t+i+1]>=n,d=c,c=r[a*t+i+1]>=n,u[h|f<<1|c<<2|d<<3].forEach(v);u[f|c<<3].forEach(v)}i=-1,c=r[a*t]>=n,u[c<<2].forEach(v);for(;++i<t-1;)d=c,c=r[a*t+i+1]>=n,u[c<<2|d<<3].forEach(v);function v(t){var r,n,o=[t[0][0]+i,t[0][1]+a],h=[t[1][0]+i,t[1][1]+a],f=s(o),u=s(h);(r=g[f])?(n=l[u])?(delete g[r.end],delete l[n.start],r===n?(r.ring.push(h),e(r.ring)):l[r.start]=g[n.end]={start:r.start,end:n.end,ring:r.ring.concat(n.ring)}):(delete g[r.end],r.ring.push(h),g[r.end=u]=r):(r=l[u])?(n=g[f])?(delete l[r.start],delete g[n.end],r===n?(r.ring.push(h),e(r.ring)):l[n.start]=g[r.end]={start:n.start,end:r.end,ring:n.ring.concat(r.ring)}):(delete l[r.start],r.ring.unshift(o),l[r.start=f]=r):l[f]=g[u]={start:f,end:u,ring:[o,h]}}u[c<<3].forEach(v)}(r,n,function(t){c(t,r,n),function(t){for(var r=0,n=t.length,e=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++r<n;)e+=t[r-1][1]*t[r][0]-t[r-1][0]*t[r][1];return e}(t)>0?e.push([t]):i.push(t)}),i.forEach(function(t){for(var r,n=0,i=e.length;n<i;++n)if(-1!==a((r=e[n])[0],t))return void r.push(t)}),{type:"MultiPolygon",value:n,coordinates:e}}function s(r){return 2*r[0]+r[1]*(t+1)*4}function g(r,n,e){r.forEach(function(r){var i,a=r[0],h=r[1],f=0|a,u=0|h,c=n[u*t+f];a>0&&a<t&&f===a&&(i=n[u*t+f-1],r[0]=a+(e-i)/(c-i)-.5),h>0&&h<o&&u===h&&(i=n[(u-1)*t+f],r[1]=h+(e-i)/(c-i)-.5)})}return d.contour=l,d.size=function(r){if(!arguments.length)return[t,o];var n=Math.floor(r[0]),e=Math.floor(r[1]);if(!(n>=0&&e>=0))throw new Error("invalid size");return t=n,o=e,d},d.thresholds=function(t){return arguments.length?(h="function"==typeof t?t:Array.isArray(t)?i(n.call(t)):i(t),d):h},d.smooth=function(t){return arguments.length?(c=t?g:f,d):c===g},d}function d(t,r,n){for(var e=t.width,i=t.height,a=1+(n<<1),o=0;o<i;++o)for(var h=0,f=0;h<e+n;++h)h<e&&(f+=t.data[h+o*e]),h>=n&&(h>=a&&(f-=t.data[h-a+o*e]),r.data[h-n+o*e]=f/Math.min(h+1,e-1+a-h,a))}function l(t,r,n){for(var e=t.width,i=t.height,a=1+(n<<1),o=0;o<e;++o)for(var h=0,f=0;h<i+n;++h)h<i&&(f+=t.data[o+h*e]),h>=n&&(h>=a&&(f-=t.data[o+(h-a)*e]),r.data[o+(h-n)*e]=f/Math.min(h+1,i-1+a-h,a))}function s(t){return t[0]}function g(t){return t[1]}function v(){return 1}t.contourDensity=function(){var t=s,e=g,a=v,o=960,h=500,f=20,u=2,w=3*f,y=o+2*w>>u,p=h+2*w>>u,E=i(20);function M(n){var i=new Float32Array(y*p),o=new Float32Array(y*p);n.forEach(function(r,n,o){var h=+t(r,n,o)+w>>u,f=+e(r,n,o)+w>>u,c=+a(r,n,o);h>=0&&h<y&&f>=0&&f<p&&(i[h+f*y]+=c)}),d({width:y,height:p,data:i},{width:y,height:p,data:o},f>>u),l({width:y,height:p,data:o},{width:y,height:p,data:i},f>>u),d({width:y,height:p,data:i},{width:y,height:p,data:o},f>>u),l({width:y,height:p,data:o},{width:y,height:p,data:i},f>>u),d({width:y,height:p,data:i},{width:y,height:p,data:o},f>>u),l({width:y,height:p,data:o},{width:y,height:p,data:i},f>>u);var h=E(i);if(!Array.isArray(h)){var s=r.max(i);h=r.tickStep(0,s,h),(h=r.range(0,Math.floor(s/h)*h,h)).shift()}return c().thresholds(h).size([y,p])(i).map(A)}function A(t){return t.value*=Math.pow(2,-2*u),t.coordinates.forEach(m),t}function m(t){t.forEach(z)}function z(t){t.forEach(x)}function x(t){t[0]=t[0]*Math.pow(2,u)-w,t[1]=t[1]*Math.pow(2,u)-w}function b(){return y=o+2*(w=3*f)>>u,p=h+2*w>>u,M}return M.x=function(r){return arguments.length?(t="function"==typeof r?r:i(+r),M):t},M.y=function(t){return arguments.length?(e="function"==typeof t?t:i(+t),M):e},M.weight=function(t){return arguments.length?(a="function"==typeof t?t:i(+t),M):a},M.size=function(t){if(!arguments.length)return[o,h];var r=+t[0],n=+t[1];if(!(r>=0&&n>=0))throw new Error("invalid size");return o=r,h=n,b()},M.cellSize=function(t){if(!arguments.length)return 1<<u;if(!((t=+t)>=1))throw new Error("invalid cell size");return u=Math.floor(Math.log(t)/Math.LN2),b()},M.thresholds=function(t){return arguments.length?(E="function"==typeof t?t:Array.isArray(t)?i(n.call(t)):i(t),M):E},M.bandwidth=function(t){if(!arguments.length)return Math.sqrt(f*(f+1));if(!((t=+t)>=0))throw new Error("invalid bandwidth");return f=Math.round((Math.sqrt(4*t*t+1)-1)/2),b()},M},t.contours=c,Object.defineProperty(t,"__esModule",{value:!0})});
// https://d3js.org/d3-contour/ v3.0.0 Copyright 2021 Mike Bostock
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-array"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{},t.d3)}(this,(function(t,r){"use strict";var n=Array.prototype.slice;function e(t,r){return t-r}var i=t=>()=>t;function o(t,r){for(var n,e=-1,i=r.length;++e<i;)if(n=a(t,r[e]))return n;return 0}function a(t,r){for(var n=r[0],e=r[1],i=-1,o=0,a=t.length,f=a-1;o<a;f=o++){var u=t[o],c=u[0],d=u[1],l=t[f],s=l[0],g=l[1];if(h(u,l,r))return 0;d>e!=g>e&&n<(s-c)*(e-d)/(g-d)+c&&(i=-i)}return i}function h(t,r,n){var e,i,o,a;return function(t,r,n){return(r[0]-t[0])*(n[1]-t[1])==(n[0]-t[0])*(r[1]-t[1])}(t,r,n)&&(i=t[e=+(t[0]===r[0])],o=n[e],a=r[e],i<=o&&o<=a||a<=o&&o<=i)}function f(){}var u=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function c(){var t=1,a=1,h=r.thresholdSturges,c=g;function d(t){var n=h(t);if(Array.isArray(n))n=n.slice().sort(e);else{const e=r.extent(t),i=r.tickStep(e[0],e[1],n);n=r.ticks(Math.floor(e[0]/i)*i,Math.floor(e[1]/i-1)*i,n)}return n.map((r=>l(t,r)))}function l(r,n){var e=[],i=[];return function(r,n,e){var i,o,h,f,c,d,l=new Array,g=new Array;i=o=-1,f=r[0]>=n,u[f<<1].forEach(v);for(;++i<t-1;)h=f,f=r[i+1]>=n,u[h|f<<1].forEach(v);u[f<<0].forEach(v);for(;++o<a-1;){for(i=-1,f=r[o*t+t]>=n,c=r[o*t]>=n,u[f<<1|c<<2].forEach(v);++i<t-1;)h=f,f=r[o*t+t+i+1]>=n,d=c,c=r[o*t+i+1]>=n,u[h|f<<1|c<<2|d<<3].forEach(v);u[f|c<<3].forEach(v)}i=-1,c=r[o*t]>=n,u[c<<2].forEach(v);for(;++i<t-1;)d=c,c=r[o*t+i+1]>=n,u[c<<2|d<<3].forEach(v);function v(t){var r,n,a=[t[0][0]+i,t[0][1]+o],h=[t[1][0]+i,t[1][1]+o],f=s(a),u=s(h);(r=g[f])?(n=l[u])?(delete g[r.end],delete l[n.start],r===n?(r.ring.push(h),e(r.ring)):l[r.start]=g[n.end]={start:r.start,end:n.end,ring:r.ring.concat(n.ring)}):(delete g[r.end],r.ring.push(h),g[r.end=u]=r):(r=l[u])?(n=g[f])?(delete l[r.start],delete g[n.end],r===n?(r.ring.push(h),e(r.ring)):l[n.start]=g[r.end]={start:n.start,end:r.end,ring:n.ring.concat(r.ring)}):(delete l[r.start],r.ring.unshift(a),l[r.start=f]=r):l[f]=g[u]={start:f,end:u,ring:[a,h]}}u[c<<3].forEach(v)}(r,n,(function(t){c(t,r,n),function(t){for(var r=0,n=t.length,e=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++r<n;)e+=t[r-1][1]*t[r][0]-t[r-1][0]*t[r][1];return e}(t)>0?e.push([t]):i.push(t)})),i.forEach((function(t){for(var r,n=0,i=e.length;n<i;++n)if(-1!==o((r=e[n])[0],t))return void r.push(t)})),{type:"MultiPolygon",value:n,coordinates:e}}function s(r){return 2*r[0]+r[1]*(t+1)*4}function g(r,n,e){r.forEach((function(r){var i,o=r[0],h=r[1],f=0|o,u=0|h,c=n[u*t+f];o>0&&o<t&&f===o&&(i=n[u*t+f-1],r[0]=o+(e-i)/(c-i)-.5),h>0&&h<a&&u===h&&(i=n[(u-1)*t+f],r[1]=h+(e-i)/(c-i)-.5)}))}return d.contour=l,d.size=function(r){if(!arguments.length)return[t,a];var n=Math.floor(r[0]),e=Math.floor(r[1]);if(!(n>=0&&e>=0))throw new Error("invalid size");return t=n,a=e,d},d.thresholds=function(t){return arguments.length?(h="function"==typeof t?t:Array.isArray(t)?i(n.call(t)):i(t),d):h},d.smooth=function(t){return arguments.length?(c=t?g:f,d):c===g},d}function d(t,r,n){for(var e=t.width,i=t.height,o=1+(n<<1),a=0;a<i;++a)for(var h=0,f=0;h<e+n;++h)h<e&&(f+=t.data[h+a*e]),h>=n&&(h>=o&&(f-=t.data[h-o+a*e]),r.data[h-n+a*e]=f/Math.min(h+1,e-1+o-h,o))}function l(t,r,n){for(var e=t.width,i=t.height,o=1+(n<<1),a=0;a<e;++a)for(var h=0,f=0;h<i+n;++h)h<i&&(f+=t.data[a+h*e]),h>=n&&(h>=o&&(f-=t.data[a+(h-o)*e]),r.data[a+(h-n)*e]=f/Math.min(h+1,i-1+o-h,o))}function s(t){return t[0]}function g(t){return t[1]}function v(){return 1}t.contourDensity=function(){var t=s,e=g,o=v,a=960,h=500,f=20,u=2,w=3*f,p=a+2*w>>u,y=h+2*w>>u,M=i(20);function E(n){var i=new Float32Array(p*y),a=new Float32Array(p*y),h=Math.pow(2,-u);n.forEach((function(r,n,a){var f=(t(r,n,a)+w)*h,u=(e(r,n,a)+w)*h,c=+o(r,n,a);if(f>=0&&f<p&&u>=0&&u<y){var d=Math.floor(f),l=Math.floor(u),s=f-d-.5,g=u-l-.5;i[d+l*p]+=(1-s)*(1-g)*c,i[d+1+l*p]+=s*(1-g)*c,i[d+1+(l+1)*p]+=s*g*c,i[d+(l+1)*p]+=(1-s)*g*c}})),d({width:p,height:y,data:i},{width:p,height:y,data:a},f>>u),l({width:p,height:y,data:a},{width:p,height:y,data:i},f>>u),d({width:p,height:y,data:i},{width:p,height:y,data:a},f>>u),l({width:p,height:y,data:a},{width:p,height:y,data:i},f>>u),d({width:p,height:y,data:i},{width:p,height:y,data:a},f>>u),l({width:p,height:y,data:a},{width:p,height:y,data:i},f>>u);var s=M(i);if(!Array.isArray(s)){var g=r.max(i);s=r.tickStep(0,g,s),(s=r.range(0,Math.floor(g/s)*s,s)).shift()}return c().thresholds(s).size([p,y])(i).map(A)}function A(t){return t.value*=Math.pow(2,-2*u),t.coordinates.forEach(m),t}function m(t){t.forEach(z)}function z(t){t.forEach(b)}function b(t){t[0]=t[0]*Math.pow(2,u)-w,t[1]=t[1]*Math.pow(2,u)-w}function x(){return p=a+2*(w=3*f)>>u,y=h+2*w>>u,E}return E.x=function(r){return arguments.length?(t="function"==typeof r?r:i(+r),E):t},E.y=function(t){return arguments.length?(e="function"==typeof t?t:i(+t),E):e},E.weight=function(t){return arguments.length?(o="function"==typeof t?t:i(+t),E):o},E.size=function(t){if(!arguments.length)return[a,h];var r=+t[0],n=+t[1];if(!(r>=0&&n>=0))throw new Error("invalid size");return a=r,h=n,x()},E.cellSize=function(t){if(!arguments.length)return 1<<u;if(!((t=+t)>=1))throw new Error("invalid cell size");return u=Math.floor(Math.log(t)/Math.LN2),x()},E.thresholds=function(t){return arguments.length?(M="function"==typeof t?t:Array.isArray(t)?i(n.call(t)):i(t),E):M},E.bandwidth=function(t){if(!arguments.length)return Math.sqrt(f*(f+1));if(!((t=+t)>=0))throw new Error("invalid bandwidth");return f=Math.round((Math.sqrt(4*t*t+1)-1)/2),x()},E},t.contours=c,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "d3-contour",
"version": "2.0.0",
"version": "3.0.0",
"description": "Compute contour polygons using marching squares.",
"homepage": "https://d3js.org/d3-contour/",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-contour.git"
},
"keywords": [

@@ -11,4 +16,3 @@ "d3",

],
"homepage": "https://d3js.org/d3-contour/",
"license": "BSD-3-Clause",
"license": "ISC",
"author": {

@@ -18,10 +22,3 @@ "name": "Mike Bostock",

},
"main": "dist/d3-contour.js",
"unpkg": "dist/d3-contour.min.js",
"jsdelivr": "dist/d3-contour.min.js",
"module": "src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-contour.git"
},
"type": "module",
"files": [

@@ -31,18 +28,29 @@ "dist/**/*.js",

],
"scripts": {
"pretest": "rollup -c",
"test": "tape 'test/**/*-test.js' && eslint src",
"prepublishOnly": "rm -rf dist && yarn test",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js"
"module": "src/index.js",
"main": "src/index.js",
"jsdelivr": "dist/d3-contour.min.js",
"unpkg": "dist/d3-contour.min.js",
"exports": {
"umd": "./dist/d3-contour.min.js",
"default": "./src/index.js"
},
"sideEffects": false,
"dependencies": {
"d3-array": "2 - 3"
},
"devDependencies": {
"eslint": "6",
"rollup": "1",
"rollup-plugin-terser": "5",
"tape": "4"
"d3-polygon": "1 - 3",
"eslint": "7",
"mocha": "8",
"rollup": "2",
"rollup-plugin-terser": "7"
},
"dependencies": {
"d3-array": "2"
"scripts": {
"test": "mocha 'test/**/*-test.js' && eslint src test",
"prepublishOnly": "rm -rf dist && yarn test && rollup -c",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
},
"engines": {
"node": ">=12"
}
}

@@ -9,8 +9,8 @@ # d3-contour

[<img alt="GeoTiff Contours" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/temperature.png" width="420" height="219">](https://bl.ocks.org/mbostock/4886c227038510f1c103ce305bef6fcc)
[<img alt="Cloud Contours" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/clouds.png" width="420" height="219">](https://bl.ocks.org/mbostock/818053c76d79d4841790c332656bf9da)
[<img alt="GeoTiff Contours" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/temperature.png" width="420" height="219">](https://observablehq.com/@d3/geotiff-contours)
[<img alt="Cloud Contours" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/clouds.png" width="420" height="219">](https://observablehq.com/@d3/cloud-contours)
Since the contour polygons are GeoJSON, you can transform and display them using standard tools; see [d3.geoPath](https://github.com/d3/d3-geo/blob/master/README.md#geoPath), [d3.geoProject](https://github.com/d3/d3-geo-projection/blob/master/README.md#geoProject) and [d3.geoStitch](https://github.com/d3/d3-geo-projection/blob/master/README.md#geoStitch), for example. Here the above contours of surface temperature are displayed in the Natural Earth projection:
[<img alt="GeoTiff Contours II" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/reprojection.png" width="420" height="219">](https://bl.ocks.org/mbostock/83c0be21dba7602ee14982b020b12f51)
[<img alt="GeoTiff Contours II" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/reprojection.png" width="420" height="219">](https://observablehq.com/@d3/geotiff-contours-ii)

@@ -24,3 +24,3 @@ Contour plots can also visualize continuous functions by sampling. Here is the Goldstein–Price function (a test function for global optimization) and a trippy animation of *sin*(*x* + *y*)*sin*(*x* - *y*):

[<img alt="Density Contours" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/faithful.png" width="420" height="219">](https://bl.ocks.org/mbostock/e3f4376d54e02d5d43ae32a7cf0e6aa9)
[<img alt="Density Contours" src="https://raw.githubusercontent.com/d3/d3-contour/master/img/faithful.png" width="420" height="219">](https://observablehq.com/@d3/density-contours)

@@ -33,13 +33,25 @@ And here is a density contour plot showing the relationship between the weight and price of 53,940 diamonds:

If you use NPM, `npm install d3-contour`. Otherwise, download the [latest release](https://github.com/d3/d3-contour/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-contour.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
If you use npm, `npm install d3-contour`. You can also download the [latest release on GitHub](https://github.com/d3/d3-contour/releases/latest). For vanilla HTML in modern browsers, import d3-contour from Skypack:
```html
<script src="https://d3js.org/d3-array.v2.min.js"></script>
<script src="https://d3js.org/d3-contour.v2.min.js"></script>
<script type="module">
import {contours} from "https://cdn.skypack.dev/d3-contour@3";
const c = contours(values);
</script>
```
For legacy environments, you can load d3-contour’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:
```html
<script src="https://cdn.jsdelivr.net/npm/d3-array@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-contour@3"></script>
<script>
// Populate a grid of n×m values where -2 ≤ x ≤ 2 and -2 ≤ y ≤ 1.
var n = 256, m = 256, values = new Array(n * m);
for (var j = 0.5, k = 0; j < m; ++j) {
for (var i = 0.5; i < n; ++i, ++k) {
const n = 256, m = 256, values = new Array(n * m);
for (let j = 0.5, k = 0; j < m; ++j) {
for (let i = 0.5; i < n; ++i, ++k) {
values[k] = goldsteinPrice(i / n * 4 - 2, 1 - j / m * 3);

@@ -50,5 +62,5 @@ }

// Compute the contour polygons at log-spaced intervals; returns an array of MultiPolygon.
var contours = d3.contours()
const contours = d3.contours()
.size([n, m])
.thresholds(d3.range(2, 21).map(p => Math.pow(2, p)))
.thresholds(Array.from({ length: 19 }, (_, i) => Math.pow(2, i + 2)))
(values);

@@ -67,7 +79,7 @@

<a name="contours" href="#contours">#</a> d3.<b>contours</b>() [<>](https://github.com/d3/d3-contour/blob/master/src/contours.js "Source")
<a name="contours" href="#contours">#</a> d3.<b>contours</b>() · [Source](https://github.com/d3/d3-contour/blob/master/src/contours.js), [Examples](https://observablehq.com/collection/@d3/d3-contour)
Constructs a new contour generator with the default settings.
<a name="_contours" href="#_contours">#</a> <i>contours</i>(<i>values</i>) [<>](https://github.com/d3/d3-contour/blob/master/src/contours.js "Source")
<a name="_contours" href="#_contours">#</a> <i>contours</i>(<i>values</i>) · [Source](https://github.com/d3/d3-contour/blob/master/src/contours.js)

@@ -94,3 +106,3 @@ Computes the contours for the given array of *values*, returning an array of [GeoJSON](http://geojson.org/geojson-spec.html) [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon) [geometry objects](http://geojson.org/geojson-spec.html#geometry-objects). Each geometry object represents the area where the input <i>values</i> are greater than or equal to the corresponding [threshold value](#contours_thresholds); the threshold value for each geometry object is exposed as <i>geometry</i>.value.

<a name="contours_contour" href="#contours_contour">#</a> <i>contours</i>.<b>contour</b>(<i>values</i>, <i>threshold</i>) [<>](https://github.com/d3/d3-contour/blob/master/src/contours.js "Source")
<a name="contours_contour" href="#contours_contour">#</a> <i>contours</i>.<b>contour</b>(<i>values</i>, <i>threshold</i>) · [Source](https://github.com/d3/d3-contour/blob/master/src/contours.js), [Examples](https://observablehq.com/@d3/animated-contours)

@@ -101,11 +113,11 @@ Computes a single contour, returning a [GeoJSON](http://geojson.org/geojson-spec.html) [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon) [geometry object](http://geojson.org/geojson-spec.html#geometry-objects) representing the area where the input <i>values</i> are greater than or equal to the given [*threshold* value](#contours_thresholds); the threshold value for each geometry object is exposed as <i>geometry</i>.value.

<a name="contours_size" href="#contours_size">#</a> <i>contours</i>.<b>size</b>([<i>size</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/contours.js "Source")
<a name="contours_size" href="#contours_size">#</a> <i>contours</i>.<b>size</b>([<i>size</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/contours.js), [Examples](https://observablehq.com/@d3/animated-contours)
If *size* is specified, sets the expected size of the input *values* grid to the [contour generator](#_contour) and returns the contour generator. The *size* is specified as an array \[<i>n</i>, <i>m</i>\] where <i>n</i> is the number of columns in the grid and <i>m</i> is the number of rows; *n* and *m* must be positive integers. If *size* is not specified, returns the current size which defaults to [1, 1].
<a name="contours_smooth" href="#contours_smooth">#</a> <i>contours</i>.<b>smooth</b>([<i>smooth</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/contours.js "Source")
<a name="contours_smooth" href="#contours_smooth">#</a> <i>contours</i>.<b>smooth</b>([<i>smooth</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/contours.js), [Examples](https://observablehq.com/@d3/contours-smooth)
If *smooth* is specified, sets whether or not the generated contour polygons are smoothed using linear interpolation. If *smooth* is not specified, returns the current smoothing flag, which defaults to true.
<a name="contours_thresholds" href="#contours_thresholds">#</a> <i>contours</i>.<b>thresholds</b>([<i>thresholds</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/contours.js "Source")
<a name="contours_thresholds" href="#contours_thresholds">#</a> <i>contours</i>.<b>thresholds</b>([<i>thresholds</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/contours.js), [Examples](https://observablehq.com/@d3/volcano-contours)

@@ -120,7 +132,7 @@ If *thresholds* is specified, sets the threshold generator to the specified function or array and returns this contour generator. If *thresholds* is not specified, returns the current threshold generator, which by default implements [Sturges’ formula](https://github.com/d3/d3-array/blob/master/README.md#thresholdSturges).

<a name="contourDensity" href="#contourDensity">#</a> d3.<b>contourDensity</b>() [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="contourDensity" href="#contourDensity">#</a> d3.<b>contourDensity</b>() · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js), [Examples](https://observablehq.com/@d3/density-contours)
Constructs a new density estimator with the default settings.
<a name="_density" href="#_density">#</a> <i>density</i>(<i>data</i>) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="_density" href="#_density">#</a> <i>density</i>(<i>data</i>) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js)

@@ -131,3 +143,3 @@ Estimates the density contours for the given array of *data*, returning an array of [GeoJSON](http://geojson.org/geojson-spec.html) [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon) [geometry objects](http://geojson.org/geojson-spec.html#geometry-objects). Each geometry object represents the area where the estimated number of points per square pixel is greater than or equal to the corresponding [threshold value](#density_thresholds); the threshold value for each geometry object is exposed as <i>geometry</i>.value. The returned geometry objects are typically passed to [d3.geoPath](https://github.com/d3/d3-geo/blob/master/README.md#geoPath) to display, using null or [d3.geoIdentity](https://github.com/d3/d3-geo/blob/master/README.md#geoIdentity) as the associated projection. See also [d3.contours](#contours).

<a name="density_x" href="#density_x">#</a> <i>density</i>.<b>x</b>([<i>x</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="density_x" href="#density_x">#</a> <i>density</i>.<b>x</b>([<i>x</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js), [Examples](https://observablehq.com/@d3/density-contours)

@@ -142,3 +154,3 @@ If *x* is specified, sets the *x*-coordinate accessor. If *x* is not specified, returns the current *x*-coordinate accessor, which defaults to:

<a name="density_y" href="#density_y">#</a> <i>density</i>.<b>y</b>([<i>y</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="density_y" href="#density_y">#</a> <i>density</i>.<b>y</b>([<i>y</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js), [Examples](https://observablehq.com/@d3/density-contours)

@@ -153,3 +165,3 @@ If *y* is specified, sets the *y*-coordinate accessor. If *y* is not specified, returns the current *y*-coordinate accessor, which defaults to:

<a name="density_weight" href="#density_weight">#</a> <i>density</i>.<b>weight</b>([<i>weight</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="density_weight" href="#density_weight">#</a> <i>density</i>.<b>weight</b>([<i>weight</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js)<!-- , [Examples](TBD) -->

@@ -164,11 +176,11 @@ If *weight* is specified, sets the accessor for point weights. If *weight* is not specified, returns the current point weight accessor, which defaults to:

<a name="density_size" href="#density_size">#</a> <i>density</i>.<b>size</b>([<i>size</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="density_size" href="#density_size">#</a> <i>density</i>.<b>size</b>([<i>size</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js), [Examples](https://observablehq.com/@d3/density-contours)
If *size* is specified, sets the size of the density estimator to the specified bounds and returns the estimator. The *size* is specified as an array \[<i>width</i>, <i>height</i>\], where <i>width</i> is the maximum *x*-value and <i>height</i> is the maximum *y*-value. If *size* is not specified, returns the current size which defaults to [960, 500]. The [estimated density contours](#_density) are only accurate within the defined size.
<a name="density_cellSize" href="#density_cellSize">#</a> <i>density</i>.<b>cellSize</b>([<i>cellSize</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="density_cellSize" href="#density_cellSize">#</a> <i>density</i>.<b>cellSize</b>([<i>cellSize</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js)<!-- , [Examples](TBD) -->
If *cellSize* is specified, sets the size of individual cells in the underlying bin grid to the specified positive integer and returns the estimator. If *cellSize* is not specified, returns the current cell size, which defaults to 4. The cell size is rounded down to the nearest power of two. Smaller cells produce more detailed contour polygons, but are more expensive to compute.
<a name="density_thresholds" href="#density_thresholds">#</a> <i>density</i>.<b>thresholds</b>([<i>thresholds</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="density_thresholds" href="#density_thresholds">#</a> <i>density</i>.<b>thresholds</b>([<i>thresholds</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js), [Examples](https://observablehq.com/@d3/density-contours)

@@ -181,4 +193,4 @@ If *thresholds* is specified, sets the threshold generator to the specified function or array and returns this contour generator. If *thresholds* is not specified, returns the current threshold generator, which by default generates about twenty nicely-rounded density thresholds.

<a name="density_bandwidth" href="#density_bandwidth">#</a> <i>density</i>.<b>bandwidth</b>([<i>bandwidth</i>]) [<>](https://github.com/d3/d3-contour/blob/master/src/density.js "Source")
<a name="density_bandwidth" href="#density_bandwidth">#</a> <i>density</i>.<b>bandwidth</b>([<i>bandwidth</i>]) · [Source](https://github.com/d3/d3-contour/blob/master/src/density.js), [Examples](https://observablehq.com/@d3/density-contours)
If *bandwidth* is specified, sets the bandwidth (the standard deviation) of the Gaussian kernel and returns the estimate. If *bandwidth* is not specified, returns the current bandwidth, which defaults to 20.4939…. The specified *bandwidth* is currently rounded to the nearest supported value by this implementation, and must be nonnegative.

@@ -1,2 +0,2 @@

import {extent, thresholdSturges, tickStep, range} from "d3-array";
import {extent, thresholdSturges, ticks, tickStep} from "d3-array";
import {slice} from "./array.js";

@@ -39,5 +39,4 @@ import ascending from "./ascending.js";

if (!Array.isArray(tz)) {
var domain = extent(values), start = domain[0], stop = domain[1];
tz = tickStep(start, stop, tz);
tz = range(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
const e = extent(values), ts = tickStep(e[0], e[1], tz);
tz = ticks(Math.floor(e[0] / ts) * ts, Math.floor(e[1] / ts - 1) * ts, tz);
} else {

@@ -47,5 +46,3 @@ tz = tz.slice().sort(ascending);

return tz.map(function(value) {
return contour(values, value);
});
return tz.map(value => contour(values, value));
}

@@ -52,0 +49,0 @@

@@ -34,10 +34,18 @@ import {max, range, tickStep} from "d3-array";

var values0 = new Float32Array(n * m),
values1 = new Float32Array(n * m);
values1 = new Float32Array(n * m),
pow2k = Math.pow(2, -k);
data.forEach(function(d, i, data) {
var xi = (+x(d, i, data) + o) >> k,
yi = (+y(d, i, data) + o) >> k,
var xi = (x(d, i, data) + o) * pow2k,
yi = (y(d, i, data) + o) * pow2k,
wi = +weight(d, i, data);
if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
values0[xi + yi * n] += wi;
var x0 = Math.floor(xi),
y0 = Math.floor(yi),
xt = xi - x0 - 0.5,
yt = yi - y0 - 0.5;
values0[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
values0[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
values0[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
values0[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
}

@@ -44,0 +52,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc