Socket
Socket
Sign inDemoInstall

d3-array

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-array - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

src/greatest.js

136

dist/d3-array.js

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

// https://d3js.org/d3-array/ v2.2.0 Copyright 2019 Mike Bostock
// https://d3js.org/d3-array/ v2.3.0 Copyright 2019 Mike Bostock
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, (function (exports) { 'use strict';
(global = global || self, factory(global.d3 = global.d3 || {}));
}(this, function (exports) { 'use strict';

@@ -359,3 +359,24 @@ function ascending(a, b) {

function quantile(values, p, valueof = number) {
function* numbers(values, valueof) {
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
yield value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
yield value;
}
}
}
}
function quantile(values, p, valueof) {
return quantileSorted(Float64Array.from(numbers(values, valueof)).sort(ascending), p);
}
function quantileSorted(values, p, valueof = number) {
if (!(n = values.length)) return;

@@ -488,19 +509,2 @@ if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);

function* numbers(values, valueof) {
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
yield value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
yield value;
}
}
}
}
function median(values, valueof) {

@@ -619,14 +623,31 @@ values = Float64Array.from(numbers(values, valueof));

function leastIndex(values, compare = ascending) {
let min;
let minIndex = -1;
if (compare.length === 1) return minIndex(values, compare);
let minValue;
let min = -1;
let index = -1;
for (const value of values) {
++index;
if (min < 0
? compare(value, value) === 0
: compare(value, minValue) < 0) {
minValue = value;
min = index;
}
}
return min;
}
function greatest(values, compare = ascending) {
let max;
let defined = false;
if (compare.length === 1) {
let maxValue;
for (const element of values) {
++index;
const value = compare(element);
if (minIndex < 0
? ascending(value, value) === 0
: ascending(value, min) < 0) {
min = value;
minIndex = index;
if (defined
? ascending(value, maxValue) > 0
: ascending(value, value) === 0) {
max = element;
maxValue = value;
defined = true;
}

@@ -636,14 +657,30 @@ }

for (const value of values) {
++index;
if (minIndex < 0
? compare(value, value) === 0
: compare(value, min) < 0) {
min = value;
minIndex = index;
if (defined
? compare(value, max) > 0
: compare(value, value) === 0) {
max = value;
defined = true;
}
}
}
return minIndex;
return max;
}
function greatestIndex(values, compare = ascending) {
if (compare.length === 1) return maxIndex(values, compare);
let maxValue;
let max = -1;
let index = -1;
for (const value of values) {
++index;
if (max < 0
? compare(value, value) === 0
: compare(value, maxValue) > 0) {
maxValue = value;
max = index;
}
}
return max;
}
function scan(values, compare) {

@@ -706,6 +743,7 @@ const index = leastIndex(values, compare);

exports.ascending = ascending;
exports.bin = bin;
exports.bisect = bisectRight;
exports.bisectLeft = bisectLeft;
exports.bisectRight = bisectRight;
exports.bisectLeft = bisectLeft;
exports.ascending = ascending;
exports.bisector = bisector;

@@ -717,11 +755,9 @@ exports.count = count;

exports.extent = extent;
exports.greatest = greatest;
exports.greatestIndex = greatestIndex;
exports.group = group;
exports.groups = groups;
exports.rollup = rollup;
exports.rollups = rollups;
exports.bin = bin;
exports.histogram = bin;
exports.thresholdFreedmanDiaconis = freedmanDiaconis;
exports.thresholdScott = scott;
exports.thresholdSturges = sturges;
exports.least = least;
exports.leastIndex = leastIndex;
exports.max = max;

@@ -737,12 +773,16 @@ exports.maxIndex = maxIndex;

exports.quantile = quantile;
exports.quantileSorted = quantileSorted;
exports.quickselect = quickselect;
exports.range = range;
exports.least = least;
exports.leastIndex = leastIndex;
exports.rollup = rollup;
exports.rollups = rollups;
exports.scan = scan;
exports.shuffle = shuffle;
exports.sum = sum;
exports.ticks = ticks;
exports.thresholdFreedmanDiaconis = freedmanDiaconis;
exports.thresholdScott = scott;
exports.thresholdSturges = sturges;
exports.tickIncrement = tickIncrement;
exports.tickStep = tickStep;
exports.ticks = ticks;
exports.transpose = transpose;

@@ -754,2 +794,2 @@ exports.variance = variance;

})));
}));

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

// https://d3js.org/d3-array/ v2.2.0 Copyright 2019 Mike Bostock
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})}(this,function(t){"use strict";function n(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function r(t){var r;return 1===t.length&&(r=t,t=function(t,o){return n(r(t),o)}),{left:function(n,r,o,e){for(null==o&&(o=0),null==e&&(e=n.length);o<e;){var f=o+e>>>1;t(n[f],r)<0?o=f+1:e=f}return o},right:function(n,r,o,e){for(null==o&&(o=0),null==e&&(e=n.length);o<e;){var f=o+e>>>1;t(n[f],r)>0?e=f:o=f+1}return o}}}var o=r(n),e=o.right,f=o.left;function u(t){return 0|t.length}function l(t){return!(t>0)}function i(t){return"object"!=typeof t||"length"in t?t:Array.from(t)}function c(t,n){let r,o=0,e=0,f=0;if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(f+=(r=n-e)*(n-(e+=r/++o)));else{let u=-1;for(let l of t)null!=(l=n(l,++u,t))&&(l=+l)>=l&&(f+=(r=l-e)*(l-(e+=r/++o)))}if(o>1)return f/(o-1)}function a(t,n){const r=c(t,n);return r?Math.sqrt(r):r}function s(t,n){let r,o;if(void 0===n)for(const n of t)null!=n&&(void 0===r?n>=n&&(r=o=n):(r>n&&(r=n),o<n&&(o=n)));else{let e=-1;for(let f of t)null!=(f=n(f,++e,t))&&(void 0===r?f>=f&&(r=o=f):(r>f&&(r=f),o<f&&(o=f)))}return[r,o]}function h(t){return t}function d(t,n,r,o){return function t(e,f){if(f>=o.length)return r(e);const u=new Map,l=o[f++];let i=-1;for(const t of e){const n=l(t,++i,e),r=u.get(n);r?r.push(t):u.set(n,[t])}for(const[n,r]of u)u.set(n,t(r,f));return n(u)}(t,0)}var v=Array.prototype,p=v.slice,M=v.map;function g(t){return function(){return t}}function y(t,n,r){t=+t,n=+n,r=(e=arguments.length)<2?(n=t,t=0,1):e<3?1:+r;for(var o=-1,e=0|Math.max(0,Math.ceil((n-t)/r)),f=new Array(e);++o<e;)f[o]=t+o*r;return f}var m=Math.sqrt(50),A=Math.sqrt(10),x=Math.sqrt(2);function w(t,n,r){var o=(n-t)/Math.max(0,r),e=Math.floor(Math.log(o)/Math.LN10),f=o/Math.pow(10,e);return e>=0?(f>=m?10:f>=A?5:f>=x?2:1)*Math.pow(10,e):-Math.pow(10,-e)/(f>=m?10:f>=A?5:f>=x?2:1)}function b(t,n,r){var o=Math.abs(n-t)/Math.max(0,r),e=Math.pow(10,Math.floor(Math.log(o)/Math.LN10)),f=o/e;return f>=m?e*=10:f>=A?e*=5:f>=x&&(e*=2),n<t?-e:e}function N(t){return Math.ceil(Math.log(t.length)/Math.LN2)+1}function q(){var t=h,n=s,r=N;function o(o){Array.isArray(o)||(o=Array.from(o));var f,u,l=o.length,i=new Array(l);for(f=0;f<l;++f)i[f]=t(o[f],f,o);var c=n(i),a=c[0],s=c[1],h=r(i,a,s);Array.isArray(h)||(h=b(a,s,h),h=y(Math.ceil(a/h)*h,s,h));for(var d=h.length;h[0]<=a;)h.shift(),--d;for(;h[d-1]>s;)h.pop(),--d;var v,p=new Array(d+1);for(f=0;f<=d;++f)(v=p[f]=[]).x0=f>0?h[f-1]:a,v.x1=f<d?h[f]:s;for(f=0;f<l;++f)a<=(u=i[f])&&u<=s&&p[e(h,u,0,d)].push(o[f]);return p}return o.value=function(n){return arguments.length?(t="function"==typeof n?n:g(n),o):t},o.domain=function(t){return arguments.length?(n="function"==typeof t?t:g([t[0],t[1]]),o):n},o.thresholds=function(t){return arguments.length?(r="function"==typeof t?t:Array.isArray(t)?g(p.call(t)):g(t),o):r},o}function k(t){return null===t?NaN:+t}function I(t,n,r=k){if(o=t.length){if((n=+n)<=0||o<2)return+r(t[0],0,t);if(n>=1)return+r(t[o-1],o-1,t);var o,e=(o-1)*n,f=Math.floor(e),u=+r(t[f],f,t);return u+(+r(t[f+1],f+1,t)-u)*(e-f)}}function L(t,r,o=0,e=t.length-1,f=n){for(;e>o;){if(e-o>600){const n=e-o+1,u=r-o+1,l=Math.log(n),i=.5*Math.exp(2*l/3),c=.5*Math.sqrt(l*i*(n-i)/n)*(u-n/2<0?-1:1);L(t,r,Math.max(o,Math.floor(r-u*i/n+c)),Math.min(e,Math.floor(r+(n-u)*i/n+c)),f)}const n=t[r];let u=o,l=e;for(j(t,o,r),f(t[e],n)>0&&j(t,o,e);u<l;){for(j(t,u,l),++u,--l;f(t[u],n)<0;)++u;for(;f(t[l],n)>0;)--l}0===f(t[o],n)?j(t,o,l):j(t,++l,e),l<=r&&(o=l+1),r<=l&&(e=l-1)}return t}function j(t,n,r){const o=t[n];t[n]=t[r],t[r]=o}function F(t,n){let r;if(void 0===n)for(const n of t)null!=n&&(r>n||void 0===r&&n>=n)&&(r=n);else{let o=-1;for(let e of t)null!=(e=n(e,++o,t))&&(r>e||void 0===r&&e>=e)&&(r=e)}return r}function S(t,r=n){let o,e=-1,f=-1;if(1===r.length)for(const u of t){++f;const t=r(u);(e<0?0===n(t,t):n(t,o)<0)&&(o=t,e=f)}else for(const n of t)++f,(e<0?0===r(n,n):r(n,o)<0)&&(o=n,e=f);return e}function _(t){if(!(e=t.length))return[];for(var n=-1,r=F(t,z),o=new Array(r);++n<r;)for(var e,f=-1,u=o[n]=new Array(e);++f<e;)u[f]=t[f][n];return o}function z(t){return t.length}t.bisect=e,t.bisectRight=e,t.bisectLeft=f,t.ascending=n,t.bisector=r,t.count=function(t,n){let r=0;if(void 0===n)for(const n of t)null!=n&&n>=n&&++r;else{let o=-1;for(let e of t)null!=(e=n(e,++o,t))&&e>=e&&++r}return r},t.cross=function(...t){const n="function"==typeof t[t.length-1]&&function(t){return n=>t(...n)}(t.pop()),r=(t=t.map(i)).map(u),o=t.length-1,e=new Array(o+1).fill(0),f=[];if(o<0||r.some(l))return f;for(;;){f.push(e.map((n,r)=>t[r][n]));let u=o;for(;++e[u]===r[u];){if(0===u)return n?f.map(n):f;e[u--]=0}}},t.descending=function(t,n){return n<t?-1:n>t?1:n>=t?0:NaN},t.deviation=a,t.extent=s,t.group=function(t,...n){return d(t,h,h,n)},t.groups=function(t,...n){return d(t,Array.from,h,n)},t.rollup=function(t,n,...r){return d(t,h,n,r)},t.rollups=function(t,n,...r){return d(t,Array.from,n,r)},t.bin=q,t.histogram=q,t.thresholdFreedmanDiaconis=function(t,r,o){return t=M.call(t,k).sort(n),Math.ceil((o-r)/(2*(I(t,.75)-I(t,.25))*Math.pow(t.length,-1/3)))},t.thresholdScott=function(t,n,r){return Math.ceil((r-n)/(3.5*a(t)*Math.pow(t.length,-1/3)))},t.thresholdSturges=N,t.max=function(t,n){let r;if(void 0===n)for(const n of t)null!=n&&(r<n||void 0===r&&n>=n)&&(r=n);else{let o=-1;for(let e of t)null!=(e=n(e,++o,t))&&(r<e||void 0===r&&e>=e)&&(r=e)}return r},t.maxIndex=function(t,n){let r,o=-1,e=-1;if(void 0===n)for(const n of t)++e,null!=n&&(r<n||void 0===r&&n>=n)&&(r=n,o=e);else for(let f of t)null!=(f=n(f,++e,t))&&(r<f||void 0===r&&f>=f)&&(r=f,o=e);return o},t.mean=function(t,n){let r=0,o=0;if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(++r,o+=n);else{let e=-1;for(let f of t)null!=(f=n(f,++e,t))&&(f=+f)>=f&&(++r,o+=f)}if(r)return o/r},t.median=function(t,n){if(!(t=Float64Array.from(function*(t,n){if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(yield n);else{let r=-1;for(let o of t)null!=(o=n(o,++r,t))&&(o=+o)>=o&&(yield o)}}(t,n))).length)return;const r=t.length,o=r>>1;return L(t,o-1,0),0==(1&r)&&L(t,o,o),I(t,.5)},t.merge=function(t){return Array.from(function*(t){for(const n of t)yield*n}(t))},t.min=F,t.minIndex=function(t,n){let r,o=-1,e=-1;if(void 0===n)for(const n of t)++e,null!=n&&(r>n||void 0===r&&n>=n)&&(r=n,o=e);else for(let f of t)null!=(f=n(f,++e,t))&&(r>f||void 0===r&&f>=f)&&(r=f,o=e);return o},t.pairs=function(t,n=function(t,n){return[t,n]}){const r=[];let o,e=!1;for(const f of t)e&&r.push(n(o,f)),o=f,e=!0;return r},t.permute=function(t,n){return Array.from(n,n=>t[n])},t.quantile=I,t.quickselect=L,t.range=y,t.least=function(t,r=n){let o,e=!1;if(1===r.length){let f;for(const u of t){const t=r(u);(e?n(t,f)<0:0===n(t,t))&&(o=u,f=t,e=!0)}}else for(const n of t)(e?r(n,o)<0:0===r(n,n))&&(o=n,e=!0);return o},t.leastIndex=S,t.scan=function(t,n){const r=S(t,n);return r<0?void 0:r},t.shuffle=function(t,n=0,r=t.length){for(var o,e,f=r-(n=+n);f;)e=Math.random()*f--|0,o=t[f+n],t[f+n]=t[e+n],t[e+n]=o;return t},t.sum=function(t,n){let r=0;if(void 0===n)for(let n of t)(n=+n)&&(r+=n);else{let o=-1;for(let e of t)(e=+n(e,++o,t))&&(r+=e)}return r},t.ticks=function(t,n,r){var o,e,f,u,l=-1;if(r=+r,(t=+t)==(n=+n)&&r>0)return[t];if((o=n<t)&&(e=t,t=n,n=e),0===(u=w(t,n,r))||!isFinite(u))return[];if(u>0)for(t=Math.ceil(t/u),n=Math.floor(n/u),f=new Array(e=Math.ceil(n-t+1));++l<e;)f[l]=(t+l)*u;else for(t=Math.floor(t*u),n=Math.ceil(n*u),f=new Array(e=Math.ceil(t-n+1));++l<e;)f[l]=(t-l)/u;return o&&f.reverse(),f},t.tickIncrement=w,t.tickStep=b,t.transpose=_,t.variance=c,t.zip=function(){return _(arguments)},Object.defineProperty(t,"__esModule",{value:!0})});
// https://d3js.org/d3-array/ v2.3.0 Copyright 2019 Mike Bostock
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).d3=t.d3||{})}(this,function(t){"use strict";function n(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}function r(t){var r;return 1===t.length&&(r=t,t=function(t,e){return n(r(t),e)}),{left:function(n,r,e,o){for(null==e&&(e=0),null==o&&(o=n.length);e<o;){var f=e+o>>>1;t(n[f],r)<0?e=f+1:o=f}return e},right:function(n,r,e,o){for(null==e&&(e=0),null==o&&(o=n.length);e<o;){var f=e+o>>>1;t(n[f],r)>0?o=f:e=f+1}return e}}}var e=r(n),o=e.right,f=e.left;function u(t){return 0|t.length}function l(t){return!(t>0)}function i(t){return"object"!=typeof t||"length"in t?t:Array.from(t)}function c(t,n){let r,e=0,o=0,f=0;if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(f+=(r=n-o)*(n-(o+=r/++e)));else{let u=-1;for(let l of t)null!=(l=n(l,++u,t))&&(l=+l)>=l&&(f+=(r=l-o)*(l-(o+=r/++e)))}if(e>1)return f/(e-1)}function a(t,n){const r=c(t,n);return r?Math.sqrt(r):r}function s(t,n){let r,e;if(void 0===n)for(const n of t)null!=n&&(void 0===r?n>=n&&(r=e=n):(r>n&&(r=n),e<n&&(e=n)));else{let o=-1;for(let f of t)null!=(f=n(f,++o,t))&&(void 0===r?f>=f&&(r=e=f):(r>f&&(r=f),e<f&&(e=f)))}return[r,e]}function h(t){return t}function d(t,n,r,e){return function t(o,f){if(f>=e.length)return r(o);const u=new Map,l=e[f++];let i=-1;for(const t of o){const n=l(t,++i,o),r=u.get(n);r?r.push(t):u.set(n,[t])}for(const[n,r]of u)u.set(n,t(r,f));return n(u)}(t,0)}var g=Array.prototype,v=g.slice,p=g.map;function M(t){return function(){return t}}function y(t,n,r){t=+t,n=+n,r=(o=arguments.length)<2?(n=t,t=0,1):o<3?1:+r;for(var e=-1,o=0|Math.max(0,Math.ceil((n-t)/r)),f=new Array(o);++e<o;)f[e]=t+e*r;return f}var m=Math.sqrt(50),A=Math.sqrt(10),x=Math.sqrt(2);function w(t,n,r){var e=(n-t)/Math.max(0,r),o=Math.floor(Math.log(e)/Math.LN10),f=e/Math.pow(10,o);return o>=0?(f>=m?10:f>=A?5:f>=x?2:1)*Math.pow(10,o):-Math.pow(10,-o)/(f>=m?10:f>=A?5:f>=x?2:1)}function b(t,n,r){var e=Math.abs(n-t)/Math.max(0,r),o=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),f=e/o;return f>=m?o*=10:f>=A?o*=5:f>=x&&(o*=2),n<t?-o:o}function N(t){return Math.ceil(Math.log(t.length)/Math.LN2)+1}function q(){var t=h,n=s,r=N;function e(e){Array.isArray(e)||(e=Array.from(e));var f,u,l=e.length,i=new Array(l);for(f=0;f<l;++f)i[f]=t(e[f],f,e);var c=n(i),a=c[0],s=c[1],h=r(i,a,s);Array.isArray(h)||(h=b(a,s,h),h=y(Math.ceil(a/h)*h,s,h));for(var d=h.length;h[0]<=a;)h.shift(),--d;for(;h[d-1]>s;)h.pop(),--d;var g,v=new Array(d+1);for(f=0;f<=d;++f)(g=v[f]=[]).x0=f>0?h[f-1]:a,g.x1=f<d?h[f]:s;for(f=0;f<l;++f)a<=(u=i[f])&&u<=s&&v[o(h,u,0,d)].push(e[f]);return v}return e.value=function(n){return arguments.length?(t="function"==typeof n?n:M(n),e):t},e.domain=function(t){return arguments.length?(n="function"==typeof t?t:M([t[0],t[1]]),e):n},e.thresholds=function(t){return arguments.length?(r="function"==typeof t?t:Array.isArray(t)?M(v.call(t)):M(t),e):r},e}function I(t){return null===t?NaN:+t}function*k(t,n){if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(yield n);else{let r=-1;for(let e of t)null!=(e=n(e,++r,t))&&(e=+e)>=e&&(yield e)}}function F(t,r,e){return L(Float64Array.from(k(t,e)).sort(n),r)}function L(t,n,r=I){if(e=t.length){if((n=+n)<=0||e<2)return+r(t[0],0,t);if(n>=1)return+r(t[e-1],e-1,t);var e,o=(e-1)*n,f=Math.floor(o),u=+r(t[f],f,t);return u+(+r(t[f+1],f+1,t)-u)*(o-f)}}function S(t,n){let r,e=-1,o=-1;if(void 0===n)for(const n of t)++o,null!=n&&(r<n||void 0===r&&n>=n)&&(r=n,e=o);else for(let f of t)null!=(f=n(f,++o,t))&&(r<f||void 0===r&&f>=f)&&(r=f,e=o);return e}function j(t,r,e=0,o=t.length-1,f=n){for(;o>e;){if(o-e>600){const n=o-e+1,u=r-e+1,l=Math.log(n),i=.5*Math.exp(2*l/3),c=.5*Math.sqrt(l*i*(n-i)/n)*(u-n/2<0?-1:1);j(t,r,Math.max(e,Math.floor(r-u*i/n+c)),Math.min(o,Math.floor(r+(n-u)*i/n+c)),f)}const n=t[r];let u=e,l=o;for(_(t,e,r),f(t[o],n)>0&&_(t,e,o);u<l;){for(_(t,u,l),++u,--l;f(t[u],n)<0;)++u;for(;f(t[l],n)>0;)--l}0===f(t[e],n)?_(t,e,l):_(t,++l,o),l<=r&&(e=l+1),r<=l&&(o=l-1)}return t}function _(t,n,r){const e=t[n];t[n]=t[r],t[r]=e}function z(t,n){let r;if(void 0===n)for(const n of t)null!=n&&(r>n||void 0===r&&n>=n)&&(r=n);else{let e=-1;for(let o of t)null!=(o=n(o,++e,t))&&(r>o||void 0===r&&o>=o)&&(r=o)}return r}function D(t,n){let r,e=-1,o=-1;if(void 0===n)for(const n of t)++o,null!=n&&(r>n||void 0===r&&n>=n)&&(r=n,e=o);else for(let f of t)null!=(f=n(f,++o,t))&&(r>f||void 0===r&&f>=f)&&(r=f,e=o);return e}function O(t,r=n){if(1===r.length)return D(t,r);let e,o=-1,f=-1;for(const n of t)++f,(o<0?0===r(n,n):r(n,e)<0)&&(e=n,o=f);return o}function P(t){if(!(o=t.length))return[];for(var n=-1,r=z(t,R),e=new Array(r);++n<r;)for(var o,f=-1,u=e[n]=new Array(o);++f<o;)u[f]=t[f][n];return e}function R(t){return t.length}t.ascending=n,t.bin=q,t.bisect=o,t.bisectLeft=f,t.bisectRight=o,t.bisector=r,t.count=function(t,n){let r=0;if(void 0===n)for(const n of t)null!=n&&n>=n&&++r;else{let e=-1;for(let o of t)null!=(o=n(o,++e,t))&&o>=o&&++r}return r},t.cross=function(...t){const n="function"==typeof t[t.length-1]&&function(t){return n=>t(...n)}(t.pop()),r=(t=t.map(i)).map(u),e=t.length-1,o=new Array(e+1).fill(0),f=[];if(e<0||r.some(l))return f;for(;;){f.push(o.map((n,r)=>t[r][n]));let u=e;for(;++o[u]===r[u];){if(0===u)return n?f.map(n):f;o[u--]=0}}},t.descending=function(t,n){return n<t?-1:n>t?1:n>=t?0:NaN},t.deviation=a,t.extent=s,t.greatest=function(t,r=n){let e,o=!1;if(1===r.length){let f;for(const u of t){const t=r(u);(o?n(t,f)>0:0===n(t,t))&&(e=u,f=t,o=!0)}}else for(const n of t)(o?r(n,e)>0:0===r(n,n))&&(e=n,o=!0);return e},t.greatestIndex=function(t,r=n){if(1===r.length)return S(t,r);let e,o=-1,f=-1;for(const n of t)++f,(o<0?0===r(n,n):r(n,e)>0)&&(e=n,o=f);return o},t.group=function(t,...n){return d(t,h,h,n)},t.groups=function(t,...n){return d(t,Array.from,h,n)},t.histogram=q,t.least=function(t,r=n){let e,o=!1;if(1===r.length){let f;for(const u of t){const t=r(u);(o?n(t,f)<0:0===n(t,t))&&(e=u,f=t,o=!0)}}else for(const n of t)(o?r(n,e)<0:0===r(n,n))&&(e=n,o=!0);return e},t.leastIndex=O,t.max=function(t,n){let r;if(void 0===n)for(const n of t)null!=n&&(r<n||void 0===r&&n>=n)&&(r=n);else{let e=-1;for(let o of t)null!=(o=n(o,++e,t))&&(r<o||void 0===r&&o>=o)&&(r=o)}return r},t.maxIndex=S,t.mean=function(t,n){let r=0,e=0;if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(++r,e+=n);else{let o=-1;for(let f of t)null!=(f=n(f,++o,t))&&(f=+f)>=f&&(++r,e+=f)}if(r)return e/r},t.median=function(t,n){if(!(t=Float64Array.from(k(t,n))).length)return;const r=t.length,e=r>>1;return j(t,e-1,0),0==(1&r)&&j(t,e,e),F(t,.5)},t.merge=function(t){return Array.from(function*(t){for(const n of t)yield*n}(t))},t.min=z,t.minIndex=D,t.pairs=function(t,n=function(t,n){return[t,n]}){const r=[];let e,o=!1;for(const f of t)o&&r.push(n(e,f)),e=f,o=!0;return r},t.permute=function(t,n){return Array.from(n,n=>t[n])},t.quantile=F,t.quantileSorted=L,t.quickselect=j,t.range=y,t.rollup=function(t,n,...r){return d(t,h,n,r)},t.rollups=function(t,n,...r){return d(t,Array.from,n,r)},t.scan=function(t,n){const r=O(t,n);return r<0?void 0:r},t.shuffle=function(t,n=0,r=t.length){for(var e,o,f=r-(n=+n);f;)o=Math.random()*f--|0,e=t[f+n],t[f+n]=t[o+n],t[o+n]=e;return t},t.sum=function(t,n){let r=0;if(void 0===n)for(let n of t)(n=+n)&&(r+=n);else{let e=-1;for(let o of t)(o=+n(o,++e,t))&&(r+=o)}return r},t.thresholdFreedmanDiaconis=function(t,r,e){return t=p.call(t,I).sort(n),Math.ceil((e-r)/(2*(F(t,.75)-F(t,.25))*Math.pow(t.length,-1/3)))},t.thresholdScott=function(t,n,r){return Math.ceil((r-n)/(3.5*a(t)*Math.pow(t.length,-1/3)))},t.thresholdSturges=N,t.tickIncrement=w,t.tickStep=b,t.ticks=function(t,n,r){var e,o,f,u,l=-1;if(r=+r,(t=+t)==(n=+n)&&r>0)return[t];if((e=n<t)&&(o=t,t=n,n=o),0===(u=w(t,n,r))||!isFinite(u))return[];if(u>0)for(t=Math.ceil(t/u),n=Math.floor(n/u),f=new Array(o=Math.ceil(n-t+1));++l<o;)f[l]=(t+l)*u;else for(t=Math.floor(t*u),n=Math.ceil(n*u),f=new Array(o=Math.ceil(t-n+1));++l<o;)f[l]=(t-l)/u;return e&&f.reverse(),f},t.transpose=P,t.variance=c,t.zip=function(){return P(arguments)},Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "d3-array",
"version": "2.2.0",
"version": "2.3.0",
"description": "Array manipulation, ordering, searching, summarizing, etc.",

@@ -29,2 +29,6 @@ "keywords": [

},
"files": [
"dist/**/*.js",
"src/**/*.js"
],
"scripts": {

@@ -36,6 +40,8 @@ "pretest": "rollup -c",

},
"sideEffects": false,
"devDependencies": {
"eslint": "5",
"rollup": "0.67",
"rollup-plugin-terser": "3",
"eslint": "6",
"jsdom": "15",
"rollup": "1",
"rollup-plugin-terser": "5",
"seedrandom": "2",

@@ -42,0 +48,0 @@ "tape": "4"

@@ -89,17 +89,17 @@ # d3-array

<a name="sum" href="#sum">#</a> d3.<b>sum</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/sum.js)
<a name="sum" href="#sum">#</a> d3.<b>sum</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/sum.js), [Examples](https://observablehq.com/@d3/d3-sum)
Returns the sum of the given *iterable* of numbers. If the iterable contains no numbers, returns 0. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the sum. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="mean" href="#mean">#</a> d3.<b>mean</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/mean.js)
<a name="mean" href="#mean">#</a> d3.<b>mean</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/mean.js), [Examples](https://observablehq.com/@d3/d3-mean-d3-median-and-friends)
Returns the mean of the given *iterable* of numbers. If the iterable contains no numbers, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the mean. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="median" href="#median">#</a> d3.<b>median</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/median.js)
<a name="median" href="#median">#</a> d3.<b>median</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/median.js), [Examples](https://observablehq.com/@d3/d3-mean-d3-median-and-friends)
Returns the median of the given *iterable* of numbers using the [R-7 method](https://en.wikipedia.org/wiki/Quantile#Estimating_quantiles_from_a_sample). If the iterable contains no numbers, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the median. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="quantile" href="#quantile">#</a> d3.<b>quantile</b>(<i>array</i>, <i>p</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/quantile.js)
<a name="quantile" href="#quantile">#</a> d3.<b>quantile</b>(<i>iterable</i>, <i>p</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/quantile.js), [Examples](https://observablehq.com/@d3/d3-mean-d3-median-and-friends)
Returns the *p*-quantile of the given **sorted** *array* of numbers, where *p* is a number in the range [0, 1]. For example, the median can be computed using *p* = 0.5, the first quartile at *p* = 0.25, and the third quartile at *p* = 0.75. This particular implementation uses the [R-7 method](http://en.wikipedia.org/wiki/Quantile#Quantiles_of_a_population), which is the default for the R programming language and Excel. For example:
Returns the *p*-quantile of the given *iterable* of numbers, where *p* is a number in the range [0, 1]. For example, the median can be computed using *p* = 0.5, the first quartile at *p* = 0.25, and the third quartile at *p* = 0.75. This particular implementation uses the [R-7 method](http://en.wikipedia.org/wiki/Quantile#Quantiles_of_a_population), which is the default for the R programming language and Excel. For example:

@@ -116,10 +116,14 @@ ```js

An optional *accessor* function may be specified, which is equivalent to calling *array*.map(*accessor*) before computing the quantile, except that it is only called on the elements needed to compute the quantile.
An optional *accessor* function may be specified, which is equivalent to calling *array*.map(*accessor*) before computing the quantile.
<a name="variance" href="#variance">#</a> d3.<b>variance</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/variance.js)
<a name="quantileSorted" href="#quantileSorted">#</a> d3.<b>quantileSorted</b>(<i>array</i>, <i>p</i>[, <i>accessor</i>]) [Source](https://github.com/d3/d3-array/blob/master/src/quantile.js "Source")
Returns an [unbiased estimator of the population variance](http://mathworld.wolfram.com/SampleVariance.html) of the given *iterable* of numbers. If the iterable has fewer than two numbers, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the variance. This method ignores undefined and NaN values; this is useful for ignoring missing data.
Similar to *quantile*, but expects the input to be a **sorted** *array* of values. In contrast with *quantile*, the accessor is only called on the elements needed to compute the quantile.
<a name="deviation" href="#deviation">#</a> d3.<b>deviation</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/deviation.js)
<a name="variance" href="#variance">#</a> d3.<b>variance</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/variance.js), [Examples](https://observablehq.com/@d3/d3-mean-d3-median-and-friends)
Returns an [unbiased estimator of the population variance](http://mathworld.wolfram.com/SampleVariance.html) of the given *iterable* of numbers using [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm). If the iterable has fewer than two numbers, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the variance. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="deviation" href="#deviation">#</a> d3.<b>deviation</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/deviation.js), [Examples](https://observablehq.com/@d3/d3-mean-d3-median-and-friends)
Returns the standard deviation, defined as the square root of the [bias-corrected variance](#variance), of the given *iterable* of numbers. If the iterable has fewer than two numbers, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the standard deviation. This method ignores undefined and NaN values; this is useful for ignoring missing data.

@@ -146,3 +150,3 @@

<a name="leastIndex" href="#leastIndex">#</a> d3.<b>leastIndex</b>(<i>iterable</i>[, <i>comparator</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/leastIndex.js), [Examples](https://observablehq.com/@d3/d3-least)
<br><a name="leastIndex" href="#leastIndex">#</a> d3.<b>leastIndex</b>(<i>iterable</i>[, <i>comparator</i>])
<br><a name="leastIndex" href="#leastIndex">#</a> d3.<b>leastIndex</b>(<i>iterable</i>[, <i>accessor</i>])

@@ -160,6 +164,30 @@ Returns the index of the least element of the specified *iterable* according to the specified *comparator* or *accessor*. If the given *iterable* contains no comparable elements (*i.e.*, the comparator returns NaN when comparing each element to itself), returns -1. If *comparator* is not specified, it defaults to [ascending](#ascending). For example:

<a name="scan" href="#scan">#</a> d3.<b>scan</b>(<i>iterable</i>[, <i>comparator</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/scan.js)
<a name="greatest" href="#greatest">#</a> d3.<b>greatest</b>(<i>iterable</i>[, <i>comparator</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/greatest.js), [Examples](https://observablehq.com/@d3/d3-least)
<br><a name="greatest" href="#greatest">#</a> d3.<b>greatest</b>(<i>iterable</i>[, <i>accessor</i>])
Deprecated; use [leastIndex](#leastIndex) instead.
Returns the greatest element of the specified *iterable* according to the specified *comparator* or *accessor*. If the given *iterable* contains no comparable elements (*i.e.*, the comparator returns NaN when comparing each element to itself), returns undefined. If *comparator* is not specified, it defaults to [ascending](#ascending). For example:
```js
const array = [{foo: 42}, {foo: 91}];
d3.greatest(array, (a, b) => a.foo - b.foo); // {foo: 91}
d3.greatest(array, (a, b) => b.foo - a.foo); // {foo: 42}
d3.greatest(array, a => a.foo); // {foo: 91}
```
This function is similar to [max](#max), except it allows the use of a comparator rather than an accessor.
<a name="greatestIndex" href="#greatestIndex">#</a> d3.<b>greatestIndex</b>(<i>iterable</i>[, <i>comparator</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/greatestIndex.js), [Examples](https://observablehq.com/@d3/d3-least)
<br><a name="greatestIndex" href="#greatestIndex">#</a> d3.<b>greatestIndex</b>(<i>iterable</i>[, <i>accessor</i>])
Returns the index of the greatest element of the specified *iterable* according to the specified *comparator* or *accessor*. If the given *iterable* contains no comparable elements (*i.e.*, the comparator returns NaN when comparing each element to itself), returns -1. If *comparator* is not specified, it defaults to [ascending](#ascending). For example:
```js
const array = [{foo: 42}, {foo: 91}];
d3.greatestIndex(array, (a, b) => a.foo - b.foo); // 1
d3.greatestIndex(array, (a, b) => b.foo - a.foo); // 0
d3.greatestIndex(array, a => a.foo); // 1
```
This function is similar to [maxIndex](#maxIndex), except it allows the use of a comparator rather than an accessor.
<a name="bisectLeft" href="#bisectLeft">#</a> d3.<b>bisectLeft</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]]) · [Source](https://github.com/d3/d3-array/blob/master/src/bisect.js)

@@ -169,3 +197,3 @@

<a name="bisect" href="#bisect">#</a> d3.<b>bisect</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]]) · [Source](https://github.com/d3/d3-array/blob/master/src/bisect.js)
<a name="bisect" href="#bisect">#</a> d3.<b>bisect</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]]) · [Source](https://github.com/d3/d3-array/blob/master/src/bisect.js), [Examples](https://observablehq.com/@d3/d3-bisect)
<br><a name="bisectRight" href="#bisectRight">#</a> d3.<b>bisectRight</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]])

@@ -211,3 +239,3 @@

<a name="quickselect" href="#quickselect">#</a> d3.<b>quickselect</b>(<i>array</i>, <i>k</i>, <i>left</i> = 0, <i>right</i> = <i>array</i>.length - 1, <i>compare</i> = ascending) · [Source](https://github.com/d3/d3-array/blob/master/src/quickselect.js)
<a name="quickselect" href="#quickselect">#</a> d3.<b>quickselect</b>(<i>array</i>, <i>k</i>, <i>left</i> = 0, <i>right</i> = <i>array</i>.length - 1, <i>compare</i> = ascending) · [Source](https://github.com/d3/d3-array/blob/master/src/quickselect.js), [Examples](https://observablehq.com/@d3/d3-quickselect)

@@ -244,3 +272,3 @@ See [mourner/quickselect](https://github.com/mourner/quickselect/blob/master/README.md).

<a name="group" href="#group">#</a> d3.<b>group</b>(<i>iterable</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js)
<a name="group" href="#group">#</a> d3.<b>group</b>(<i>iterable</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js), [Examples](https://observablehq.com/@d3/d3-group-d3-rollup)

@@ -330,7 +358,7 @@ Groups the specified *iterable* of values into a Map from *key* to array of value. For example, given some data:

<a name="groups" href="#groups">#</a> d3.<b>groups</b>(<i>iterable</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js)
<a name="groups" href="#groups">#</a> d3.<b>groups</b>(<i>iterable</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js), [Examples](https://observablehq.com/@d3/d3-group-d3-rollup)
Equivalent to [group](#group), but returns nested arrays instead of nested maps.
<a name="rollup" href="#rollup">#</a> d3.<b>rollup</b>(<i>iterable</i>, <i>reduce</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js)
<a name="rollup" href="#rollup">#</a> d3.<b>rollup</b>(<i>iterable</i>, <i>reduce</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js), [Examples](https://observablehq.com/@d3/d3-group-d3-rollup)

@@ -388,2 +416,6 @@ [Groups](#group) and reduces the specified *iterable* of values into a Map from *key* to value. For example, given some data:

<a name="rollups" href="#rollups">#</a> d3.<b>rollups</b>(<i>iterable</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js), [Examples](https://observablehq.com/@d3/d3-group-d3-rollup)
Equivalent to [rollup](#rollup), but returns nested arrays instead of nested maps.
<a name="count" href="#count">#</a> d3.<b>count</b>(<i>iterable</i>[, <i>accessor</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/count.js), [Examples](https://observablehq.com/@d3/d3-count)

@@ -398,6 +430,2 @@

```
<a name="rollups" href="#rollups">#</a> d3.<b>rollups</b>(<i>iterable</i>, <i>...keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/group.js)
Equivalent to [rollup](#rollup), but returns nested arrays instead of nested maps.
<a name="cross" href="#cross">#</a> d3.<b>cross</b>(<i>...iterables</i>[, <i>reducer</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/cross.js), [Examples](https://observablehq.com/@d3/d3-cross)

@@ -470,3 +498,3 @@

<a name="ticks" href="#ticks">#</a> d3.<b>ticks</b>(<i>start</i>, <i>stop</i>, <i>count</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/ticks.js)
<a name="ticks" href="#ticks">#</a> d3.<b>ticks</b>(<i>start</i>, <i>stop</i>, <i>count</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/ticks.js), [Examples](https://observablehq.com/@d3/d3-ticks)

@@ -477,7 +505,7 @@ Returns an array of approximately *count* + 1 uniformly-spaced, nicely-rounded values between *start* and *stop* (inclusive). Each value is a power of ten multiplied by 1, 2 or 5. See also [d3.tickIncrement](#tickIncrement), [d3.tickStep](#tickStep) and [*linear*.ticks](https://github.com/d3/d3-scale/blob/master/README.md#linear_ticks).

<a name="tickIncrement" href="#tickIncrement">#</a> d3.<b>tickIncrement</b>(<i>start</i>, <i>stop</i>, <i>count</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/ticks.js)
<a name="tickIncrement" href="#tickIncrement">#</a> d3.<b>tickIncrement</b>(<i>start</i>, <i>stop</i>, <i>count</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/ticks.js), [Examples](https://observablehq.com/@d3/d3-ticks)
Like [d3.tickStep](#tickStep), except requires that *start* is always less than or equal to *step*, and if the tick step for the given *start*, *stop* and *count* would be less than one, returns the negative inverse tick step instead. This method is always guaranteed to return an integer, and is used by [d3.ticks](#ticks) to guarantee that the returned tick values are represented as precisely as possible in IEEE 754 floating point.
<a name="tickStep" href="#tickStep">#</a> d3.<b>tickStep</b>(<i>start</i>, <i>stop</i>, <i>count</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/ticks.js)
<a name="tickStep" href="#tickStep">#</a> d3.<b>tickStep</b>(<i>start</i>, <i>stop</i>, <i>count</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/ticks.js), [Examples](https://observablehq.com/@d3/d3-ticks)

@@ -507,7 +535,7 @@ Returns the difference between adjacent tick values if the same arguments were passed to [d3.ticks](#ticks): a nicely-rounded value that is a power of ten multiplied by 1, 2 or 5. Note that due to the limited precision of IEEE 754 floating point, the returned value may not be exact decimals; use [d3-format](https://github.com/d3/d3-format) to format numbers for human consumption.

<a name="transpose" href="#transpose">#</a> d3.<b>transpose</b>(<i>matrix</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/transpose.js)
<a name="transpose" href="#transpose">#</a> d3.<b>transpose</b>(<i>matrix</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/transpose.js), [Examples](https://observablehq.com/@d3/d3-transpose)
Uses the [zip](#zip) operator as a two-dimensional [matrix transpose](http://en.wikipedia.org/wiki/Transpose).
<a name="zip" href="#zip">#</a> d3.<b>zip</b>(<i>arrays…</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/zip.js)
<a name="zip" href="#zip">#</a> d3.<b>zip</b>(<i>arrays…</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/zip.js), [Examples](https://observablehq.com/@d3/d3-transpose)

@@ -526,7 +554,7 @@ Returns an array of arrays, where the *i*th array contains the *i*th element from each of the argument *arrays*. The returned array is truncated in length to the shortest array in *arrays*. If *arrays* contains only a single array, the returned array contains one-element arrays. With no arguments, the returned array is empty.

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

@@ -538,3 +566,3 @@ Bins the given iterable of *data* samples. Returns an array of bins, where each bin is an array containing the associated elements from the input *data*. Thus, the `length` of the bin is the number of elements in that bin. Each bin has two additional attributes:

<a name="bin_value" href="#bin_value">#</a> <i>bin</i>.<b>value</b>([<i>value</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/bin.js)
<a name="bin_value" href="#bin_value">#</a> <i>bin</i>.<b>value</b>([<i>value</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/bin.js), [Examples](https://observablehq.com/@d3/d3-bin)

@@ -547,3 +575,3 @@ If *value* is specified, sets the value accessor to the specified function or constant and returns this bin generator. If *value* is not specified, returns the current value accessor, which defaults to the identity function.

<a name="bin_domain" href="#bin_domain">#</a> <i>bin</i>.<b>domain</b>([<i>domain</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/bin.js)
<a name="bin_domain" href="#bin_domain">#</a> <i>bin</i>.<b>domain</b>([<i>domain</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/bin.js), [Examples](https://observablehq.com/@d3/d3-bin)

@@ -568,3 +596,3 @@ If *domain* is specified, sets the domain accessor to the specified function or array and returns this bin generator. If *domain* is not specified, returns the current domain accessor, which defaults to [extent](#extent). The bin domain is defined as an array [*min*, *max*], where *min* is the minimum observable value and *max* is the maximum observable value; both values are inclusive. Any value outside of this domain will be ignored when the bins are [generated](#_bin).

<a name="bin_thresholds" href="#bin_thresholds">#</a> <i>bin</i>.<b>thresholds</b>([<i>count</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/bin.js)
<a name="bin_thresholds" href="#bin_thresholds">#</a> <i>bin</i>.<b>thresholds</b>([<i>count</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/bin.js), [Examples](https://observablehq.com/@d3/d3-bin)
<br><a name="bin_thresholds" href="#bin_thresholds">#</a> <i>bin</i>.<b>thresholds</b>([<i>thresholds</i>])

@@ -582,12 +610,12 @@

<a name="thresholdFreedmanDiaconis" href="#thresholdFreedmanDiaconis">#</a> d3.<b>thresholdFreedmanDiaconis</b>(<i>values</i>, <i>min</i>, <i>max</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/threshold/freedmanDiaconis.js)
<a name="thresholdFreedmanDiaconis" href="#thresholdFreedmanDiaconis">#</a> d3.<b>thresholdFreedmanDiaconis</b>(<i>values</i>, <i>min</i>, <i>max</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/threshold/freedmanDiaconis.js), [Examples](https://observablehq.com/@d3/d3-bin)
Returns the number of bins according to the [Freedman–Diaconis rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition); the input *values* must be numbers.
<a name="thresholdScott" href="#thresholdScott">#</a> d3.<b>thresholdScott</b>(<i>values</i>, <i>min</i>, <i>max</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/threshold/scott.js)
<a name="thresholdScott" href="#thresholdScott">#</a> d3.<b>thresholdScott</b>(<i>values</i>, <i>min</i>, <i>max</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/threshold/scott.js), [Examples](https://observablehq.com/@d3/d3-bin)
Returns the number of bins according to [Scott’s normal reference rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition); the input *values* must be numbers.
<a name="thresholdSturges" href="#thresholdSturges">#</a> d3.<b>thresholdSturges</b>(<i>values</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/threshold/sturges.js)
<a name="thresholdSturges" href="#thresholdSturges">#</a> d3.<b>thresholdSturges</b>(<i>values</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/threshold/sturges.js), [Examples](https://observablehq.com/@d3/d3-bin)
Returns the number of bins according to [Sturges’ formula](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition); the input *values* must be numbers.

@@ -23,3 +23,3 @@ export {default as bisect, bisectRight, bisectLeft} from "./bisect.js";

export {default as permute} from "./permute.js";
export {default as quantile} from "./quantile.js";
export {default as quantile, quantileSorted} from "./quantile.js";
export {default as quickselect} from "./quickselect.js";

@@ -29,2 +29,4 @@ export {default as range} from "./range.js";

export {default as leastIndex} from "./leastIndex.js";
export {default as greatest} from "./greatest.js";
export {default as greatestIndex} from "./greatestIndex.js";
export {default as scan} from "./scan.js"; // Deprecated; use leastIndex.

@@ -31,0 +33,0 @@ export {default as shuffle} from "./shuffle.js";

import ascending from "./ascending.js";
import minIndex from "./minIndex.js";
export default function leastIndex(values, compare = ascending) {
let min;
let minIndex = -1;
if (compare.length === 1) return minIndex(values, compare);
let minValue;
let min = -1;
let index = -1;
if (compare.length === 1) {
for (const element of values) {
++index;
const value = compare(element);
if (minIndex < 0
? ascending(value, value) === 0
: ascending(value, min) < 0) {
min = value;
minIndex = index;
}
for (const value of values) {
++index;
if (min < 0
? compare(value, value) === 0
: compare(value, minValue) < 0) {
minValue = value;
min = index;
}
} else {
for (const value of values) {
++index;
if (minIndex < 0
? compare(value, value) === 0
: compare(value, min) < 0) {
min = value;
minIndex = index;
}
}
}
return minIndex;
return min;
}

@@ -0,21 +1,5 @@

import {numbers} from "./number.js";
import quantile from "./quantile.js";
import quickselect from "./quickselect.js";
function* numbers(values, valueof) {
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
yield value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
yield value;
}
}
}
}
export default function(values, valueof) {

@@ -22,0 +6,0 @@ values = Float64Array.from(numbers(values, valueof));

export default function(x) {
return x === null ? NaN : +x;
}
export function* numbers(values, valueof) {
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
yield value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
yield value;
}
}
}
}

@@ -1,4 +0,9 @@

import number from "./number.js";
import ascending from "./ascending.js";
import number, {numbers} from "./number.js";
export default function quantile(values, p, valueof = number) {
export default function quantile(values, p, valueof) {
return quantileSorted(Float64Array.from(numbers(values, valueof)).sort(ascending), p);
}
export function quantileSorted(values, p, valueof = number) {
if (!(n = values.length)) return;

@@ -5,0 +10,0 @@ if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc