Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests for dimension.bottom.

  • Loading branch information...
commit 10eb0795bf6eba73cde4a3c9df18f239fe168103 1 parent 9c15373
@mbostock mbostock authored
View
6 crossfilter.js
@@ -722,7 +722,7 @@ function crossfilter() {
return filterIndex((refilter = crossfilter_filterAll)(values));
}
- // Returns the top K selected records, based on this dimension's order.
+ // Returns the top K selected records based on this dimension's order.
// Note: observes this dimension's filter, unlike group and groupAll.
function top(k) {
var array = [],
@@ -738,8 +738,8 @@ function crossfilter() {
return array;
}
-
- // Basically same as top but on ascending order
+
+ // Returns the bottom K selected records based on this dimension's order.
// Note: observes this dimension's filter, unlike group and groupAll.
function bottom(k) {
var array = [],
View
2  crossfilter.min.js
@@ -1 +1 @@
-(function(e){function t(e){return e}function n(e,t){for(var n=0,r=t.length,i=new Array(r);n<r;++n)i[n]=e[t[n]];return i}function i(e){function t(t,n,r,i){while(r<i){var s=r+i>>1;e(t[s])<n?r=s+1:i=s}return r}function n(t,n,r,i){while(r<i){var s=r+i>>1;n<e(t[s])?i=s:r=s+1}return r}return n.right=n,n.left=t,n}function o(e){function t(e,t,n){var i=n-t,s=(i>>>1)+1;while(--s>0)r(e,s,i,t);return e}function n(e,t,n){var i=n-t,s;while(--i>0)s=e[t],e[t]=e[t+i],e[t+i]=s,r(e,1,i,t);return e}function r(t,n,r,i){var s=t[--i+n],o=e(s),u;while((u=n<<1)<=r){u<r&&e(t[i+u])>e(t[i+u+1])&&u++;if(o<=e(t[i+u]))break;t[i+n]=t[i+u],n=u}t[i+n]=s}return t.sort=n,t}function a(e){function n(n,r,i,s){var o=new Array(s=Math.min(i-r,s)),u,a,f,l;for(a=0;a<s;++a)o[a]=n[r++];t(o,0,s);if(r<i){u=e(o[0]);do if(f=e(l=n[r])>u)o[0]=l,u=e(t(o,0,s)[0]);while(++r<i)}return o}var t=o(e);return n}function l(e){function t(t,n,r){for(var i=n+1;i<r;++i){for(var s=i,o=t[i],u=e(o);s>n&&e(t[s-1])>u;--s)t[s]=t[s-1];t[s]=o}return t}return t}function h(e){function n(e,n,i){return(i-n<p?t:r)(e,n,i)}function r(t,r,i){var s=(i-r)/6|0,o=r+s,u=i-1-s,a=r+i-1>>1,f=a-s,l=a+s,c=t[o],h=e(c),p=t[f],d=e(p),v=t[a],m=e(v),g=t[l],y=e(g),b=t[u],w=e(b),E;h>d&&(E=c,c=p,p=E,E=h,h=d,d=E),y>w&&(E=g,g=b,b=E,E=y,y=w,w=E),h>m&&(E=c,c=v,v=E,E=h,h=m,m=E),d>m&&(E=p,p=v,v=E,E=d,d=m,m=E),h>y&&(E=c,c=g,g=E,E=h,h=y,y=E),m>y&&(E=v,v=g,g=E,E=m,m=y,y=E),d>w&&(E=p,p=b,b=E,E=d,d=w,w=E),d>m&&(E=p,p=v,v=E,E=d,d=m,m=E),y>w&&(E=g,g=b,b=E,E=y,y=w,w=E);var S=p,x=d,T=g,N=y;t[o]=c,t[f]=t[r],t[a]=v,t[l]=t[i-1],t[u]=b;var C=r+1,k=i-2,L=x<=N&&x>=N;if(L)for(var A=C;A<=k;++A){var O=t[A],M=e(O);if(M<x)A!==C&&(t[A]=t[C],t[C]=O),++C;else if(M>x)for(;;){var _=e(t[k]);if(_>x){k--;continue}if(_<x){t[A]=t[C],t[C++]=t[k],t[k--]=O;break}t[A]=t[k],t[k--]=O;break}}else for(var A=C;A<=k;A++){var O=t[A],M=e(O);if(M<x)A!==C&&(t[A]=t[C],t[C]=O),++C;else if(M>N)for(;;){var _=e(t[k]);if(_>N){k--;if(k<A)break;continue}_<x?(t[A]=t[C],t[C++]=t[k],t[k--]=O):(t[A]=t[k],t[k--]=O);break}}t[r]=t[C-1],t[C-1]=S,t[i-1]=t[k+1],t[k+1]=T,n(t,r,C-1),n(t,k+2,i);if(L)return t;if(C<o&&k>u){var D,_;while((D=e(t[C]))<=x&&D>=x)++C;while((_=e(t[k]))<=N&&_>=N)--k;for(var A=C;A<=k;A++){var O=t[A],M=e(O);if(M<=x&&M>=x)A!==C&&(t[A]=t[C],t[C]=O),C++;else if(M<=N&&M>=N)for(;;){var _=e(t[k]);if(_<=N&&_>=N){k--;if(k<A)break;continue}_<x?(t[A]=t[C],t[C++]=t[k],t[k--]=O):(t[A]=t[k],t[k--]=O);break}}}return n(t,C,k+1)}var t=l(e);return n}function b(e){return new Array(e)}function w(e,t){return function(n){var r=n.length;return[e.left(n,t,0,r),e.right(n,t,0,r)]}}function E(e,t){var n=t[0],r=t[1];return function(t){var i=t.length;return[e.left(t,n,0,i),e.left(t,r,0,i)]}}function S(e){return[0,e.length]}function x(){return null}function T(){return 0}function N(e){return e+1}function C(e){return e-1}function k(e){return function(t,n){return t+ +e(n)}}function L(e){return function(t,n){return t-e(n)}}function A(){function v(t){var n=s,r=t.length;return r&&(i=i.concat(t),l=g(l,s+=r),p.forEach(function(e){e(t,n,r)})),e}function m(e){function q(t,r,i){D=t.map(e),P=H(M(i),0,i),D=n(D,P);var o=B(D),u=o[0],a=o[1],f;for(f=0;f<u;++f)l[P[f]+r]|=v;for(f=a;f<i;++f)l[P[f]+r]|=v;if(!r){b=D,A=P,F=u,I=a;return}var c=b,h=A,p=0,d=0;b=new Array(s),A=O(s,s);for(f=0;p<r&&d<i;++f)c[p]<D[d]?(b[f]=c[p],A[f]=h[p++]):(b[f]=D[d],A[f]=P[d++]+r);for(;p<r;++p,++f)b[f]=c[p],A[f]=h[p];for(;d<i;++d,++f)b[f]=D[d],A[f]=P[d]+r;o=B(b),F=o[0],I=o[1]}function R(e,t,n){j.forEach(function(e){e(D,P,t,n)}),D=P=null}function U(e){var t,n,r,i=e[0],s=e[1],o=[],u=[];if(i<F)for(t=i,n=Math.min(F,s);t<n;++t)l[r=A[t]]^=v,o.push(r);else if(i>F)for(t=F,n=Math.min(i,I);t<n;++t)l[r=A[t]]^=v,u.push(r);if(s>I)for(t=Math.max(i,I),n=s;t<n;++t)l[r=A[t]]^=v,o.push(r);else if(s<I)for(t=Math.max(F,s),n=I;t<n;++t)l[r=A[t]]^=v,u.push(r);return F=i,I=s,c.forEach(function(e){e(v,o,u)}),d}function z(e){return e==null?V():Array.isArray(e)?X(e):W(e)}function W(e){return U((B=w(r,e))(b))}function X(e){return U((B=E(r,e))(b))}function V(){return U((B=S)(b))}function $(e){var t=[],n=I,r;while(--n>=F&&e>0)l[r=A[n]]||(t.push(i[r]),--e);return t}function J(e){var t=[],n=F,r;while(n<I&&e>0)l[r=A[n]]||(t.push(i[r]),--e),n++;return t}function K(e){function B(t,n,o,a){function U(){++p===h&&(v=y(v,f<<=1),u=y(u,f),h=_(f))}var d=r,v=O(p,h),b=E,w=M,S=p,T=0,N=0,C,k,L,A,B,j;H&&(b=w=x),r=new Array(p),p=0,u=S>1?g(u,s):O(s,h),S&&(L=(k=d[0]).key);while(N<a&&!((A=e(t[N]))>=A))++N;while(N<a){if(k&&L<=A){B=k,j=L,v[T]=p;if(k=d[++T])L=k.key}else B={key:A,value:w()},j=A;r[p]=B;while(!(A>j)){u[C=n[N]+o]=p,l[C]&m||(B.value=b(B.value,i[C]));if(++N>=a)break;A=e(t[N])}U()}while(T<S)r[v[T]=p]=d[T++],U();if(p>T)for(T=0;T<o;++T)u[T]=v[u[T]];C=c.indexOf(D),p>1?(D=F,P=q):(p===1?(D=I,P=R):(D=x,P=x),u=null),c[C]=D}function F(e,t,n){if(e===v||H)return;var s,o,a,f;for(s=0,a=t.length;s<a;++s)l[o=t[s]]&m||(f=r[u[o]],f.value=E(f.value,i[o]));for(s=0,a=n.length;s<a;++s)(l[o=n[s]]&m)===e&&(f=r[u[o]],f.value=S(f.value,i[o]))}function I(e,t,n){if(e===v||H)return;var s,o,u,a=r[0];for(s=0,u=t.length;s<u;++s)l[o=t[s]]&m||(a.value=E(a.value,i[o]));for(s=0,u=n.length;s<u;++s)(l[o=n[s]]&m)===e&&(a.value=S(a.value,i[o]))}function q(){var e,t;for(e=0;e<p;++e)r[e].value=M();for(e=0;e<s;++e)l[e]&m||(t=r[u[e]],t.value=E(t.value,i[e]))}function R(){var e,t=r[0];t.value=M();for(e=0;e<s;++e)l[e]&m||(t.value=E(t.value,i[e]))}function U(){return H&&(P(),H=!1),r}function z(e){var t=d(U(),0,r.length,e);return w.sort(t,0,t.length)}function W(e,t,r){return E=e,S=t,M=r,H=!0,n}function X(){return W(N,C,T)}function V(e){return W(k(e),L(e),T)}function $(e){function t(t){return e(t.value)}return d=a(t),w=o(t),n}function J(){return $(t)}function K(){return p}var n={top:z,all:U,reduce:W,reduceCount:X,reduceSum:V,order:$,orderNatural:J,size:K},r,u,f=8,h=_(f),p=0,d,w,E,S,M,D=x,P=x,H=!0;return arguments.length<1&&(e=t),c.push(D),j.push(B),B(b,A,0,s),X().orderNatural()}function Q(){var e=K(x),t=e.all;return delete e.all,delete e.top,delete e.order,delete e.orderNatural,delete e.size,e.value=function(){return t()[0].value},e}var d={filter:z,filterExact:W,filterRange:X,filterAll:V,top:$,bottom:J,group:K,groupAll:Q},v=1<<u++,m=~v,b,A,D,P,H=h(function(e){return D[e]}),B=S,j=[],F=0,I=0;return p.unshift(q),p.push(R),u>f&&(l=y(l,f<<=1)),q(i,0,s),R(i,0,s),d}function b(){function a(e,r,o){var a;if(u)return;for(a=r;a<s;++a)l[a]||(t=n(t,i[a]))}function f(e,s,o){var a,f,c;if(u)return;for(a=0,c=s.length;a<c;++a)l[f=s[a]]||(t=n(t,i[f]));for(a=0,c=o.length;a<c;++a)l[f=o[a]]===e&&(t=r(t,i[f]))}function h(){var e;t=o();for(e=0;e<s;++e)l[e]||(t=n(t,i[e]))}function d(t,i,s){return n=t,r=i,o=s,u=!0,e}function v(){return d(N,C,T)}function m(e){return d(k(e),L(e),T)}function g(){return u&&(h(),u=!1),t}var e={reduce:d,reduceCount:v,reduceSum:m,value:g},t,n,r,o,u=!0;return c.push(f),p.push(a),a(i,0,s),v()}function A(){return s}var e={add:v,dimension:m,groupAll:b,size:A},i=[],s=0,u=0,f=8,l=d(0),c=[],p=[];return arguments.length?v(arguments[0]):e}function O(e,t){return(t<257?d:t<65537?v:m)(e)}function M(e){var t=O(e,e);for(var n=-1;++n<e;)t[n]=n;return t}function _(e){return e===8?256:e===16?65536:4294967296}A.version="1.0.3",A.permute=n;var r=A.bisect=i(t);r.by=i;var s=A.heap=o(t);s.by=o;var u=A.heapselect=a(t);u.by=a;var f=A.insertionsort=l(t);f.by=l;var c=A.quicksort=h(t);c.by=h;var p=32,d=b,v=b,m=b,g=t,y=t;typeof Uint8Array!="undefined"&&(d=function(e){return new Uint8Array(e)},v=function(e){return new Uint16Array(e)},m=function(e){return new Uint32Array(e)},g=function(e,t){var n=new e.constructor(t);return n.set(e),n},y=function(e,t){var n;switch(t){case 16:n=v(e.length);break;case 32:n=m(e.length);break;default:throw new Error("invalid array width!")}return n.set(e),n}),e.crossfilter=A})(this);
+(function(a){function b(a){return a}function c(a,b){for(var c=0,d=b.length,e=new Array(d);c<d;++c)e[c]=a[b[c]];return e}function e(a){function b(b,c,d,e){while(d<e){var f=d+e>>1;a(b[f])<c?d=f+1:e=f}return d}function c(b,c,d,e){while(d<e){var f=d+e>>1;c<a(b[f])?e=f:d=f+1}return d}return c.right=c,c.left=b,c}function g(a){function b(a,b,c){var e=c-b,f=(e>>>1)+1;while(--f>0)d(a,f,e,b);return a}function c(a,b,c){var e=c-b,f;while(--e>0)f=a[b],a[b]=a[b+e],a[b+e]=f,d(a,1,e,b);return a}function d(b,c,d,e){var f=b[--e+c],g=a(f),h;while((h=c<<1)<=d){h<d&&a(b[e+h])>a(b[e+h+1])&&h++;if(g<=a(b[e+h]))break;b[e+c]=b[e+h],c=h}b[e+c]=f}return b.sort=c,b}function i(a){function c(c,d,e,f){var g=new Array(f=Math.min(e-d,f)),h,i,j,k;for(i=0;i<f;++i)g[i]=c[d++];b(g,0,f);if(d<e){h=a(g[0]);do if(j=a(k=c[d])>h)g[0]=k,h=a(b(g,0,f)[0]);while(++d<e)}return g}var b=g(a);return c}function k(a){function b(b,c,d){for(var e=c+1;e<d;++e){for(var f=e,g=b[e],h=a(g);f>c&&a(b[f-1])>h;--f)b[f]=b[f-1];b[f]=g}return b}return b}function m(a){function c(a,c,e){return(e-c<n?b:d)(a,c,e)}function d(b,d,e){var f=(e-d)/6|0,g=d+f,h=e-1-f,i=d+e-1>>1,j=i-f,k=i+f,l=b[g],m=a(l),n=b[j],o=a(n),p=b[i],q=a(p),r=b[k],s=a(r),t=b[h],u=a(t),v;m>o&&(v=l,l=n,n=v,v=m,m=o,o=v),s>u&&(v=r,r=t,t=v,v=s,s=u,u=v),m>q&&(v=l,l=p,p=v,v=m,m=q,q=v),o>q&&(v=n,n=p,p=v,v=o,o=q,q=v),m>s&&(v=l,l=r,r=v,v=m,m=s,s=v),q>s&&(v=p,p=r,r=v,v=q,q=s,s=v),o>u&&(v=n,n=t,t=v,v=o,o=u,u=v),o>q&&(v=n,n=p,p=v,v=o,o=q,q=v),s>u&&(v=r,r=t,t=v,v=s,s=u,u=v);var w=n,x=o,y=r,z=s;b[g]=l,b[j]=b[d],b[i]=p,b[k]=b[e-1],b[h]=t;var A=d+1,B=e-2,C=x<=z&&x>=z;if(C)for(var D=A;D<=B;++D){var E=b[D],F=a(E);if(F<x)D!==A&&(b[D]=b[A],b[A]=E),++A;else if(F>x)for(;;){var G=a(b[B]);if(G>x){B--;continue}if(G<x){b[D]=b[A],b[A++]=b[B],b[B--]=E;break}b[D]=b[B],b[B--]=E;break}}else for(var D=A;D<=B;D++){var E=b[D],F=a(E);if(F<x)D!==A&&(b[D]=b[A],b[A]=E),++A;else if(F>z)for(;;){var G=a(b[B]);if(G>z){B--;if(B<D)break;continue}G<x?(b[D]=b[A],b[A++]=b[B],b[B--]=E):(b[D]=b[B],b[B--]=E);break}}b[d]=b[A-1],b[A-1]=w,b[e-1]=b[B+1],b[B+1]=y,c(b,d,A-1),c(b,B+2,e);if(C)return b;if(A<g&&B>h){var H,G;while((H=a(b[A]))<=x&&H>=x)++A;while((G=a(b[B]))<=z&&G>=z)--B;for(var D=A;D<=B;D++){var E=b[D],F=a(E);if(F<=x&&F>=x)D!==A&&(b[D]=b[A],b[A]=E),A++;else if(F<=z&&F>=z)for(;;){var G=a(b[B]);if(G<=z&&G>=z){B--;if(B<D)break;continue}G<x?(b[D]=b[A],b[A++]=b[B],b[B--]=E):(b[D]=b[B],b[B--]=E);break}}}return c(b,A,B+1)}var b=k(a);return c}function t(a){return new Array(a)}function u(a,b){return function(c){var d=c.length;return[a.left(c,b,0,d),a.right(c,b,0,d)]}}function v(a,b){var c=b[0],d=b[1];return function(b){var e=b.length;return[a.left(b,c,0,e),a.left(b,d,0,e)]}}function w(a){return[0,a.length]}function x(){return null}function y(){return 0}function z(a){return a+1}function A(a){return a-1}function B(a){return function(b,c){return b+ +a(c)}}function C(a){return function(b,c){return b-a(c)}}function D(){function p(b){var c=f,d=b.length;return d&&(e=e.concat(b),k=r(k,f+=d),n.forEach(function(a){a(b,c,d)})),a}function q(a){function P(b,d,e){H=b.map(a),I=J(F(e),0,e),H=c(H,I);var g=K(H),h=g[0],i=g[1],j;for(j=0;j<h;++j)k[I[j]+d]|=p;for(j=i;j<e;++j)k[I[j]+d]|=p;if(!d){t=H,D=I,N=h,O=i;return}var l=t,m=D,n=0,o=0;t=new Array(f),D=E(f,f);for(j=0;n<d&&o<e;++j)l[n]<H[o]?(t[j]=l[n],D[j]=m[n++]):(t[j]=H[o],D[j]=I[o++]+d);for(;n<d;++n,++j)t[j]=l[n],D[j]=m[n];for(;o<e;++o,++j)t[j]=H[o],D[j]=I[o]+d;g=K(t),N=g[0],O=g[1]}function Q(a,b,c){L.forEach(function(a){a(H,I,b,c)}),H=I=null}function R(a){var b,c,d,e=a[0],f=a[1],g=[],h=[];if(e<N)for(b=e,c=Math.min(N,f);b<c;++b)k[d=D[b]]^=p,g.push(d);else if(e>N)for(b=N,c=Math.min(e,O);b<c;++b)k[d=D[b]]^=p,h.push(d);if(f>O)for(b=Math.max(e,O),c=f;b<c;++b)k[d=D[b]]^=p,g.push(d);else if(f<O)for(b=Math.max(N,f),c=O;b<c;++b)k[d=D[b]]^=p,h.push(d);return N=e,O=f,l.forEach(function(a){a(p,g,h)}),o}function S(a){return a==null?V():Array.isArray(a)?U(a):T(a)}function T(a){return R((K=u(d,a))(t))}function U(a){return R((K=v(d,a))(t))}function V(){return R((K=w)(t))}function W(a){var b=[],c=O,d;while(--c>=N&&a>0)k[d=D[c]]||(b.push(e[d]),--a);return b}function X(a){var b=[],c=N,d;while(c<O&&a>0)k[d=D[c]]||(b.push(e[d]),--a),c++;return b}function Y(a){function K(b,c,g,i){function Q(){++n===m&&(p=s(p,j<<=1),h=s(h,j),m=G(j))}var o=d,p=E(n,m),t=v,u=F,w=n,y=0,z=0,A,B,C,D,K,L;J&&(t=u=x),d=new Array(n),n=0,h=w>1?r(h,f):E(f,m),w&&(C=(B=o[0]).key);while(z<i&&!((D=a(b[z]))>=D))++z;while(z<i){if(B&&C<=D){K=B,L=C,p[y]=n;if(B=o[++y])C=B.key}else K={key:D,value:u()},L=D;d[n]=K;while(!(D>L)){h[A=c[z]+g]=n,k[A]&q||(K.value=t(K.value,e[A]));if(++z>=i)break;D=a(b[z])}Q()}while(y<w)d[p[y]=n]=o[y++],Q();if(n>y)for(y=0;y<g;++y)h[y]=p[h[y]];A=l.indexOf(H),n>1?(H=M,I=O):(n===1?(H=N,I=P):(H=x,I=x),h=null),l[A]=H}function M(a,b,c){if(a===p||J)return;var f,g,i,j;for(f=0,i=b.length;f<i;++f)k[g=b[f]]&q||(j=d[h[g]],j.value=v(j.value,e[g]));for(f=0,i=c.length;f<i;++f)(k[g=c[f]]&q)===a&&(j=d[h[g]],j.value=w(j.value,e[g]))}function N(a,b,c){if(a===p||J)return;var f,g,h,i=d[0];for(f=0,h=b.length;f<h;++f)k[g=b[f]]&q||(i.value=v(i.value,e[g]));for(f=0,h=c.length;f<h;++f)(k[g=c[f]]&q)===a&&(i.value=w(i.value,e[g]))}function O(){var a,b;for(a=0;a<n;++a)d[a].value=F();for(a=0;a<f;++a)k[a]&q||(b=d[h[a]],b.value=v(b.value,e[a]))}function P(){var a,b=d[0];b.value=F();for(a=0;a<f;++a)k[a]&q||(b.value=v(b.value,e[a]))}function Q(){return J&&(I(),J=!1),d}function R(a){var b=o(Q(),0,d.length,a);return u.sort(b,0,b.length)}function S(a,b,d){return v=a,w=b,F=d,J=!0,c}function T(){return S(z,A,y)}function U(a){return S(B(a),C(a),y)}function V(a){function b(b){return a(b.value)}return o=i(b),u=g(b),c}function W(){return V(b)}function X(){return n}var c={top:R,all:Q,reduce:S,reduceCount:T,reduceSum:U,order:V,orderNatural:W,size:X},d,h,j=8,m=G(j),n=0,o,u,v,w,F,H=x,I=x,J=!0;return arguments.length<1&&(a=b),l.push(H),L.push(K),K(t,D,0,f),T().orderNatural()}function Z(){var a=Y(x),b=a.all;return delete a.all,delete a.top,delete a.order,delete a.orderNatural,delete a.size,a.value=function(){return b()[0].value},a}var o={filter:S,filterExact:T,filterRange:U,filterAll:V,top:W,bottom:X,group:Y,groupAll:Z},p=1<<h++,q=~p,t,D,H,I,J=m(function(a){return H[a]}),K=w,L=[],N=0,O=0;return n.unshift(P),n.push(Q),h>j&&(k=s(k,j<<=1)),P(e,0,f),Q(e,0,f),o}function t(){function i(a,d,g){var i;if(h)return;for(i=d;i<f;++i)k[i]||(b=c(b,e[i]))}function j(a,f,g){var i,j,l;if(h)return;for(i=0,l=f.length;i<l;++i)k[j=f[i]]||(b=c(b,e[j]));for(i=0,l=g.length;i<l;++i)k[j=g[i]]===a&&(b=d(b,e[j]))}function m(){var a;b=g();for(a=0;a<f;++a)k[a]||(b=c(b,e[a]))}function o(b,e,f){return c=b,d=e,g=f,h=!0,a}function p(){return o(z,A,y)}function q(a){return o(B(a),C(a),y)}function r(){return h&&(m(),h=!1),b}var a={reduce:o,reduceCount:p,reduceSum:q,value:r},b,c,d,g,h=!0;return l.push(j),n.push(i),i(e,0,f),p()}function D(){return f}var a={add:p,dimension:q,groupAll:t,size:D},e=[],f=0,h=0,j=8,k=o(0),l=[],n=[];return arguments.length?p(arguments[0]):a}function E(a,b){return(b<257?o:b<65537?p:q)(a)}function F(a){var b=E(a,a);for(var c=-1;++c<a;)b[c]=c;return b}function G(a){return a===8?256:a===16?65536:4294967296}D.version="1.0.3",D.permute=c;var d=D.bisect=e(b);d.by=e;var f=D.heap=g(b);f.by=g;var h=D.heapselect=i(b);h.by=i;var j=D.insertionsort=k(b);j.by=k;var l=D.quicksort=m(b);l.by=m;var n=32,o=t,p=t,q=t,r=b,s=b;typeof Uint8Array!="undefined"&&(o=function(a){return new Uint8Array(a)},p=function(a){return new Uint16Array(a)},q=function(a){return new Uint32Array(a)},r=function(a,b){var c=new a.constructor(b);return c.set(a),c},s=function(a,b){var c;switch(b){case 16:c=p(a.length);break;case 32:c=q(a.length);break;default:throw new Error("invalid array width!")}return c.set(a),c}),a.crossfilter=D})(this);
View
6 src/crossfilter.js
@@ -207,7 +207,7 @@ function crossfilter() {
return filterIndex((refilter = crossfilter_filterAll)(values));
}
- // Returns the top K selected records, based on this dimension's order.
+ // Returns the top K selected records based on this dimension's order.
// Note: observes this dimension's filter, unlike group and groupAll.
function top(k) {
var array = [],
@@ -223,8 +223,8 @@ function crossfilter() {
return array;
}
-
- // Basically same as top but on ascending order
+
+ // Returns the bottom K selected records based on this dimension's order.
// Note: observes this dimension's filter, unlike group and groupAll.
function bottom(k) {
var array = [],
View
95 test/crossfilter-test.js
@@ -41,9 +41,9 @@ suite.addBatch({
{date: "2011-11-14T21:26:30Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T21:30:55Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T21:31:05Z", quantity: 2, total: 90, tip: 0, type: "tab"},
- {date: "2011-11-14T22:30:22Z", quantity: 2, total: 90, tip: 0, type: "tab"},
+ {date: "2011-11-14T22:30:22Z", quantity: 2, total: 89, tip: 0, type: "tab"},
{date: "2011-11-14T22:34:28Z", quantity: 2, total: 190, tip: 100, type: "tab"},
- {date: "2011-11-14T22:48:05Z", quantity: 2, total: 90, tip: 0, type: "tab"},
+ {date: "2011-11-14T22:48:05Z", quantity: 2, total: 91, tip: 0, type: "tab"},
{date: "2011-11-14T22:51:40Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T22:58:54Z", quantity: 2, total: 100, tip: 0, type: "visa"},
{date: "2011-11-14T23:06:25Z", quantity: 2, total: 190, tip: 100, type: "tab"},
@@ -165,6 +165,95 @@ suite.addBatch({
}
},
+ "bottom": {
+ "returns the bottom k records by value, in descending order": function(data) {
+ assert.deepEqual(data.total.bottom(3), [
+ {date: "2011-11-14T22:30:22Z", quantity: 2, total: 89, tip: 0, type: "tab"},
+ {date: "2011-11-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
+ {date: "2011-11-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"}
+ ]);
+ assert.deepEqual(data.date.bottom(3), [
+ {date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
+ {date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab"},
+ {date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"}
+ ]);
+ },
+ "observes the associated dimension's filters": function(data) {
+ try {
+ data.quantity.filterExact(4);
+ assert.deepEqual(data.total.bottom(3), [
+ {date: "2011-11-14T21:18:48Z", quantity: 4, total: 270, tip: 0, type: "tab"}
+ ]);
+ } finally {
+ data.quantity.filterAll();
+ }
+ try {
+ data.date.filterRange([new Date(Date.UTC(2011, 10, 14, 19)), new Date(Date.UTC(2011, 10, 14, 20))]);
+ assert.deepEqual(data.date.bottom(10), [
+ {date: "2011-11-14T19:00:31Z", quantity: 2, total: 190, tip: 100, type: "tab"},
+ {date: "2011-11-14T19:04:22Z", quantity: 2, total: 90, tip: 0, type: "tab"},
+ {date: "2011-11-14T19:30:44Z", quantity: 2, total: 90, tip: 0, type: "tab"}
+ ]);
+ data.date.filterRange([Date.UTC(2011, 10, 14, 19), Date.UTC(2011, 10, 14, 20)]); // also comparable
+ assert.deepEqual(data.date.bottom(10), [
+ {date: "2011-11-14T19:00:31Z", quantity: 2, total: 190, type: "tab", tip: 100},
+ {date: "2011-11-14T19:04:22Z", quantity: 2, total: 90, type: "tab", tip: 0},
+ {date: "2011-11-14T19:30:44Z", quantity: 2, total: 90, type: "tab", tip: 0}
+ ]);
+ } finally {
+ data.date.filterAll();
+ }
+ },
+ "observes other dimensions' filters": function(data) {
+ try {
+ data.type.filterExact("tab");
+ assert.deepEqual(data.total.bottom(2), [
+ {date: "2011-11-14T22:30:22Z", quantity: 2, total: 89, tip: 0, type: "tab"},
+ {date: "2011-11-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"}
+ ]);
+ data.type.filterExact("visa");
+ assert.deepEqual(data.total.bottom(1), [
+ {date: "2011-11-14T22:58:54Z", quantity: 2, total: 100, tip: 0, type: "visa"}
+ ]);
+ data.quantity.filterExact(2);
+ assert.deepEqual(data.tip.bottom(1), [
+ {date: "2011-11-14T22:58:54Z", quantity: 2, total: 100, tip: 0, type: "visa"}
+ ]);
+ } finally {
+ data.type.filterAll();
+ data.quantity.filterAll();
+ }
+ try {
+ data.type.filterExact("tab");
+ assert.deepEqual(data.date.bottom(2), [
+ {date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
+ {date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab"}
+ ]);
+ data.type.filterExact("visa");
+ assert.deepEqual(data.date.bottom(1), [
+ {date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"}
+ ]);
+ data.quantity.filterExact(2);
+ assert.deepEqual(data.date.bottom(1), [
+ {date: "2011-11-14T17:38:40Z", quantity: 2, total: 200, tip: 100, type: "visa"}
+ ]);
+ } finally {
+ data.type.filterAll();
+ data.quantity.filterAll();
+ }
+ },
+ "negative or zero k returns an empty array": function(data) {
+ assert.deepEqual(data.quantity.bottom(0), []);
+ assert.deepEqual(data.quantity.bottom(-1), []);
+ assert.deepEqual(data.quantity.bottom(NaN), []);
+ assert.deepEqual(data.quantity.bottom(-Infinity), []);
+ assert.deepEqual(data.date.bottom(0), []);
+ assert.deepEqual(data.date.bottom(-1), []);
+ assert.deepEqual(data.date.bottom(NaN), []);
+ assert.deepEqual(data.date.bottom(-Infinity), []);
+ }
+ },
+
"filterExact": {
"selects records that match the specified value exactly": function(data) {
try {
@@ -182,7 +271,7 @@ suite.addBatch({
data.tip.filterExact(null); // equivalent to 0 by natural ordering
assert.deepEqual(data.date.top(2), [
{date: "2011-11-14T22:58:54Z", quantity: 2, total: 100, tip: 0, type: "visa"},
- {date: "2011-11-14T22:48:05Z", quantity: 2, total: 90, tip: 0, type: "tab"}
+ {date: "2011-11-14T22:48:05Z", quantity: 2, total: 91, tip: 0, type: "tab"}
]);
} finally {
data.tip.filterAll();
Please sign in to comment.
Something went wrong with that request. Please try again.