Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1.0 to 2.2.0

102

dist/d3-array.js

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

// https://d3js.org/d3-array/ v2.1.0 Copyright 2019 Mike Bostock
// https://d3js.org/d3-array/ v2.2.0 Copyright 2019 Mike Bostock
(function (global, factory) {

@@ -170,26 +170,37 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

function dogroup(values, keyof) {
const map = new Map();
let index = -1;
for (const value of values) {
const key = keyof(value, ++index, values);
const group = map.get(key);
if (group) group.push(value);
else map.set(key, [value]);
}
return map;
function group(values, ...keys) {
return nest(values, identity, identity, keys);
}
function groups(values, ...keys) {
return nest(values, Array.from, identity, keys);
}
function rollup(values, reduce, ...keys) {
return nest(values, identity, reduce, keys);
}
function rollups(values, reduce, ...keys) {
return nest(values, Array.from, reduce, keys);
}
function nest(values, map, reduce, keys) {
return (function regroup(values, i) {
if (i >= keys.length) return reduce(values);
const map = dogroup(values, keys[i]);
return new Map(Array.from(map, ([k, v]) => [k, regroup(v, i + 1)]));
const groups = new Map();
const keyof = keys[i++];
let index = -1;
for (const value of values) {
const key = keyof(value, ++index, values);
const group = groups.get(key);
if (group) group.push(value);
else groups.set(key, [value]);
}
for (const [key, values] of groups) {
groups.set(key, regroup(values, i));
}
return map(groups);
})(values, 0);
}
function group(values, ...keys) {
return rollup(values, identity, ...keys);
}
var array = Array.prototype;

@@ -581,9 +592,23 @@

let defined = false;
for (const value of values) {
if (defined
? compare(value, min) < 0
: compare(value, value) === 0) {
min = value;
defined = true;
if (compare.length === 1) {
let minValue;
for (const element of values) {
const value = compare(element);
if (defined
? ascending(value, minValue) < 0
: ascending(value, value) === 0) {
min = element;
minValue = value;
defined = true;
}
}
} else {
for (const value of values) {
if (defined
? compare(value, min) < 0
: compare(value, value) === 0) {
min = value;
defined = true;
}
}
}

@@ -597,10 +622,23 @@ return min;

let index = -1;
for (const value of values) {
++index;
if (minIndex < 0
? compare(value, value) === 0
: compare(value, min) < 0) {
min = value;
minIndex = index;
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;
}
}
} else {
for (const value of values) {
++index;
if (minIndex < 0
? compare(value, value) === 0
: compare(value, min) < 0) {
min = value;
minIndex = index;
}
}
}

@@ -678,2 +716,5 @@ return minIndex;

exports.group = group;
exports.groups = groups;
exports.rollup = rollup;
exports.rollups = rollups;
exports.bin = bin;

@@ -696,3 +737,2 @@ exports.histogram = bin;

exports.range = range;
exports.rollup = rollup;
exports.least = least;

@@ -699,0 +739,0 @@ exports.leastIndex = leastIndex;

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

// https://d3js.org/d3-array/ v2.1.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,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 i(t){return!(t>0)}function l(t){return"object"!=typeof t||"length"in t?t:Array.from(t)}function a(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 i of t)null!=(i=n(i,++u,t))&&(i=+i)>=i&&(f+=(r=i-o)*(i-(o+=r/++e)))}if(e>1)return f/(e-1)}function c(t,n){const r=a(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){return function t(e,o){if(o>=r.length)return n(e);const f=function(t,n){const r=new Map;let e=-1;for(const o of t){const f=n(o,++e,t),u=r.get(f);u?u.push(o):r.set(f,[o])}return r}(e,r[o]);return new Map(Array.from(f,([n,r])=>[n,t(r,o+1)]))}(t,0)}var v=Array.prototype,M=v.slice,p=v.map;function g(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),w=Math.sqrt(2);function x(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>=w?2:1)*Math.pow(10,o):-Math.pow(10,-o)/(f>=m?10:f>=A?5:f>=w?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>=w&&(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,i=e.length,l=new Array(i);for(f=0;f<i;++f)l[f]=t(e[f],f,e);var a=n(l),c=a[0],s=a[1],h=r(l,c,s);Array.isArray(h)||(h=b(c,s,h),h=y(Math.ceil(c/h)*h,s,h));for(var d=h.length;h[0]<=c;)h.shift(),--d;for(;h[d-1]>s;)h.pop(),--d;var v,M=new Array(d+1);for(f=0;f<=d;++f)(v=M[f]=[]).x0=f>0?h[f-1]:c,v.x1=f<d?h[f]:s;for(f=0;f<i;++f)c<=(u=l[f])&&u<=s&&M[o(h,u,0,d)].push(e[f]);return M}return e.value=function(n){return arguments.length?(t="function"==typeof n?n:g(n),e):t},e.domain=function(t){return arguments.length?(n="function"==typeof t?t:g([t[0],t[1]]),e):n},e.thresholds=function(t){return arguments.length?(r="function"==typeof t?t:Array.isArray(t)?g(M.call(t)):g(t),e):r},e}function k(t){return null===t?NaN:+t}function I(t,n,r=k){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 L(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,i=Math.log(n),l=.5*Math.exp(2*i/3),a=.5*Math.sqrt(i*l*(n-l)/n)*(u-n/2<0?-1:1);L(t,r,Math.max(e,Math.floor(r-u*l/n+a)),Math.min(o,Math.floor(r+(n-u)*l/n+a)),f)}const n=t[r];let u=e,i=o;for(j(t,e,r),f(t[o],n)>0&&j(t,e,o);u<i;){for(j(t,u,i),++u,--i;f(t[u],n)<0;)++u;for(;f(t[i],n)>0;)--i}0===f(t[e],n)?j(t,e,i):j(t,++i,o),i<=r&&(e=i+1),r<=i&&(o=i-1)}return t}function j(t,n,r){const e=t[n];t[n]=t[r],t[r]=e}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 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 S(t,r=n){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 _(t){if(!(o=t.length))return[];for(var n=-1,r=F(t,z),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 z(t){return t.length}t.bisect=o,t.bisectRight=o,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 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(l)).map(u),e=t.length-1,o=new Array(e+1).fill(0),f=[];if(e<0||r.some(i))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=c,t.extent=s,t.group=function(t,...n){return d(t,h,...n)},t.bin=q,t.histogram=q,t.thresholdFreedmanDiaconis=function(t,r,e){return t=p.call(t,k).sort(n),Math.ceil((e-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*c(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 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=function(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},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(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 e of t)null!=(e=n(e,++r,t))&&(e=+e)>=e&&(yield e)}}(t,n))).length)return;const r=t.length,e=r>>1;return L(t,e-1,0),0==(1&r)&&L(t,e,e),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,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},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=I,t.quickselect=L,t.range=y,t.rollup=d,t.least=function(t,r=n){let e,o=!1;for(const n of t)(o?r(n,e)<0:0===r(n,n))&&(e=n,o=!0);return e},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 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.ticks=function(t,n,r){var e,o,f,u,i=-1;if(r=+r,(t=+t)==(n=+n)&&r>0)return[t];if((e=n<t)&&(o=t,t=n,n=o),0===(u=x(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));++i<o;)f[i]=(t+i)*u;else for(t=Math.floor(t*u),n=Math.ceil(n*u),f=new Array(o=Math.ceil(t-n+1));++i<o;)f[i]=(t-i)/u;return e&&f.reverse(),f},t.tickIncrement=x,t.tickStep=b,t.transpose=_,t.variance=a,t.zip=function(){return _(arguments)},Object.defineProperty(t,"__esModule",{value:!0})});
// 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})});
{
"name": "d3-array",
"version": "2.1.0",
"version": "2.2.0",
"description": "Array manipulation, ordering, searching, summarizing, etc.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -51,3 +51,3 @@ # d3-array

* [Transformations](#transformations)
* [Bins](#Bins)
* [Bins](#bins)

@@ -58,3 +58,3 @@ ### Statistics

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

@@ -67,3 +67,3 @@ Returns the minimum value in the given *iterable* using natural order. If the iterable contains no comparable values, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the minimum value.

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

@@ -74,3 +74,3 @@ Returns the index of the minimum value in the given *iterable* using natural order. If the iterable contains no comparable values, returns -1. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the minimum value.

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

@@ -83,3 +83,3 @@ Returns the maximum value in the given *iterable* using natural order. If the iterable contains no comparable values, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the maximum value.

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

@@ -90,3 +90,3 @@ Returns the index of the maximum value in the given *iterable* using natural order. If the iterable contains no comparable values, returns -1. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the maximum value.

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

@@ -135,5 +135,6 @@ Returns the [minimum](#min) and [maximum](#max) value in the given *iterable* using natural order. If the iterable contains no comparable values, returns [undefined, undefined]. An optional *accessor* function may be specified, which is equivalent to calling Array.from before computing the extent.

<a name="least" href="#least">#</a> d3.<b>least</b>(<i>iterable</i>[, <i>comparator</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/least.js)
<a name="least" href="#least">#</a> d3.<b>least</b>(<i>iterable</i>[, <i>comparator</i>]) · [Source](https://github.com/d3/d3-array/blob/master/src/least.js), [Examples](https://observablehq.com/@d3/d3-least)
<br><a name="least" href="#least">#</a> d3.<b>least</b>(<i>iterable</i>[, <i>accessor</i>])
Returns the least element of the specified *iterable* according to the specified *comparator*. 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:
Returns 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 undefined. If *comparator* is not specified, it defaults to [ascending](#ascending). For example:

@@ -144,2 +145,3 @@ ```js

d3.least(array, (a, b) => b.foo - a.foo); // {foo: 91}
d3.least(array, a => a.foo); // {foo: 42}
```

@@ -149,5 +151,6 @@

<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)
<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>])
Returns the index of the least element of the specified *iterable* according to the specified *comparator*. 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:
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:

@@ -158,2 +161,3 @@ ```js

d3.leastIndex(array, (a, b) => b.foo - a.foo); // 1
d3.leastIndex(array, a => a.foo); // 0
```

@@ -329,4 +333,8 @@

<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/rollup.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)
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)
[Groups](#group) and reduces the specified *iterable* of values into a Map from *key* to value. For example, given some data:

@@ -383,3 +391,3 @@

<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 "Source")
<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)

@@ -393,3 +401,6 @@ Returns the number of valid number values (*i.e.*, not null, NaN, or undefined) in the specified *iterable*; accepts an accessor.

```
<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)

@@ -439,5 +450,5 @@

<a name="permute" href="#permute">#</a> d3.<b>permute</b>(<i>array</i>, <i>indexes</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/permute.js), [Examples](https://observablehq.com/@d3/d3-permute)
<a name="permute" href="#permute">#</a> d3.<b>permute</b>(<i>source</i>, <i>keys</i>) · [Source](https://github.com/d3/d3-array/blob/master/src/permute.js), [Examples](https://observablehq.com/@d3/d3-permute)
Returns a permutation of the specified *array* using the specified array of *indexes*. The returned array contains the corresponding element in array for each index in indexes, in order. For example:
Returns a permutation of the specified *source* object (or array) using the specified iterable of *keys*. The returned array contains the corresponding property of the source object for each key in *keys*, in order. For example:

@@ -448,3 +459,3 @@ ```js

It is acceptable for the array of indexes to be a different length from the array of elements, and for indexes to be duplicated or omitted.
It is acceptable to have more keys than source elements, and for keys to be duplicated or omitted.

@@ -454,4 +465,4 @@ This method can also be used to extract the values from an object into an array with a stable order. Extracting keyed values in order can be useful for generating data arrays in nested selections. For example:

```js
var object = {yield: 27, variety: "Manchuria", year: 1931, site: "University Farm"},
fields = ["site", "variety", "yield"];
let object = {yield: 27, variety: "Manchuria", year: 1931, site: "University Farm"};
let fields = ["site", "variety", "yield"];

@@ -458,0 +469,0 @@ d3.permute(object, fields); // returns ["University Farm", "Manchuria", 27]

import identity from "./identity.js";
import rollup from "./rollup.js";
export default function group(values, ...keys) {
return rollup(values, identity, ...keys);
return nest(values, identity, identity, keys);
}
export function groups(values, ...keys) {
return nest(values, Array.from, identity, keys);
}
export function rollup(values, reduce, ...keys) {
return nest(values, identity, reduce, keys);
}
export function rollups(values, reduce, ...keys) {
return nest(values, Array.from, reduce, keys);
}
function nest(values, map, reduce, keys) {
return (function regroup(values, i) {
if (i >= keys.length) return reduce(values);
const groups = new Map();
const keyof = keys[i++];
let index = -1;
for (const value of values) {
const key = keyof(value, ++index, values);
const group = groups.get(key);
if (group) group.push(value);
else groups.set(key, [value]);
}
for (const [key, values] of groups) {
groups.set(key, regroup(values, i));
}
return map(groups);
})(values, 0);
}

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

export {default as extent} from "./extent.js";
export {default as group} from "./group.js";
export {default as group, groups, rollup, rollups} from "./group.js";
export {default as bin, default as histogram} from "./bin.js"; // Deprecated; use bin.

@@ -27,3 +27,2 @@ export {default as thresholdFreedmanDiaconis} from "./threshold/freedmanDiaconis.js";

export {default as range} from "./range.js";
export {default as rollup} from "./rollup.js";
export {default as least} from "./least.js";

@@ -30,0 +29,0 @@ export {default as leastIndex} from "./leastIndex.js";

@@ -6,11 +6,25 @@ import ascending from "./ascending.js";

let defined = false;
for (const value of values) {
if (defined
? compare(value, min) < 0
: compare(value, value) === 0) {
min = value;
defined = true;
if (compare.length === 1) {
let minValue;
for (const element of values) {
const value = compare(element);
if (defined
? ascending(value, minValue) < 0
: ascending(value, value) === 0) {
min = element;
minValue = value;
defined = true;
}
}
} else {
for (const value of values) {
if (defined
? compare(value, min) < 0
: compare(value, value) === 0) {
min = value;
defined = true;
}
}
}
return min;
}

@@ -7,12 +7,25 @@ import ascending from "./ascending.js";

let index = -1;
for (const value of values) {
++index;
if (minIndex < 0
? compare(value, value) === 0
: compare(value, min) < 0) {
min = value;
minIndex = index;
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;
}
}
} else {
for (const value of values) {
++index;
if (minIndex < 0
? compare(value, value) === 0
: compare(value, min) < 0) {
min = value;
minIndex = index;
}
}
}
return minIndex;
}
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