-
Notifications
You must be signed in to change notification settings - Fork 0
/
crossfilter-ma.min.js
2 lines (2 loc) · 4.68 KB
/
crossfilter-ma.min.js
1
2
!function(){function a(a){"use strict";function b(a,b){1===a?b.sort(function(a,b){return a.rollingAverage>b.rollingAverage?1:a.rollingAverage<b.rollingAverage?-1:0}):-1===a&&b.sort(function(a,b){return a.rollingAverage>b.rollingAverage?-1:a.rollingAverage<b.rollingAverage?1:0})}function c(a,b){1===a?b.sort(function(a,b){return a.percentageChange>b.percentageChange?1:a.percentageChange<b.percentageChange?-1:0}):-1===a&&b.sort(function(a,b){return a.percentageChange>b.percentageChange?-1:a.percentageChange<b.percentageChange?1:0})}var d={};d.version="1.2.2",d.constants={DEFAULT_MOVING_AVERAGE_NODES:2};var d=d||{};d.accumulateGroupForNDayMovingAverage=function(a,c,e,f){if(!a||!a.all||"function"!=typeof a.all)throw new Error("You must pass in a crossfilter group!");c="undefined"!=typeof c?c:d.constants.DEFAULT_MOVING_AVERAGE_NODES,f="undefined"!=typeof f?!!f:!1,e="undefined"!=typeof e?!!e:!1;var g,h,i=!1;return{ndays:function(a){return"undefined"==typeof a?c:void(c=a)},rolldown:function(a){return"undefined"==typeof a?e:void(e=!!a)},_debug:function(a){return"undefined"==typeof a?f:void(f=!!a)},_defaultKeyAccessor:function(){return function(a){return a.key}},_defaultValueAccessor:function(){return function(a){return a.value}},keyAccessor:function(a){return"undefined"==typeof a?("undefined"==typeof g&&(g=this._defaultKeyAccessor()),g):void(g=a)},valueAccessor:function(a){return"undefined"==typeof a?("undefined"==typeof h&&(h=this._defaultValueAccessor()),h):void(h=a)},orderByMovingAverage:function(a){if("undefined"==typeof a)return i;switch(a){case 1:i=1;break;case-1:i=-1;break;default:case 0:i=!1}},all:function(){var d=this,g=0,h=a.all(),j={};h.forEach(function(a){j[d.keyAccessor()(a)]=d.valueAccessor()(a)});var k=Object.keys(j).sort(),l=h.map(function(a){for(var b=d.keyAccessor()(a),h=d.valueAccessor()(a),i=k.indexOf(b),l=c,m=0,n=0,o=0,p=[];--l>0;){var q=k[i-l];if(!q&&!e)break;if(q){var r=j[q],s=r;m++,n+=s,f&&p.push({key:q,value:s})}}m++,n+=h,f&&(g+=h,p.push({key:b,value:h})),o=n/m,c>m&&!e&&(o=0);var t={key:b,value:h,rollingAverage:o};return f&&(t._debug={cumulate:g,datumsUsed:p}),t});return b(i,l),l},top:function(){var d=this,g=0,h=a.top.apply(a,arguments),j={};h.forEach(function(a){j[d.keyAccessor()(a)]=d.valueAccessor()(a)});var k=Object.keys(j).sort(),l=h.map(function(a){for(var b=d.keyAccessor()(a),h=d.valueAccessor()(a),i=k.indexOf(b),l=c,m=0,n=0,o=0,p=[];--l>0;){var q=k[i-l];if(!q&&!e)break;if(q){var r=j[q],s=r;m++,n+=s,f&&p.push({key:q,value:s})}}m++,n+=h,f&&(g+=h,p.push({key:b,value:h})),o=n/m,c>m&&!e&&(o=0);var t={key:b,value:h,rollingAverage:o};return f&&(t._debug={cumulate:g,datumsUsed:p}),t});return b(i,l),l}}};var d=d||{};return d.accumulateGroupForPercentageChange=function(a,b){if(!a||!a.all||"function"!=typeof a.all)throw new Error("You must pass in a crossfilter group!");b="undefined"!=typeof b?!!b:!1;var d,e,f=!1;return{_debug:function(a){return"undefined"==typeof a?b:void(b=!!a)},_defaultKeyAccessor:function(){return function(a){return a.key}},_defaultValueAccessor:function(){return function(a){return a.value}},keyAccessor:function(a){return"undefined"==typeof a?("undefined"==typeof d&&(d=this._defaultKeyAccessor()),d):void(d=a)},valueAccessor:function(a){return"undefined"==typeof a?("undefined"==typeof e&&(e=this._defaultValueAccessor()),e):void(e=a)},orderByPercentageChange:function(a){if("undefined"==typeof a)return f;switch(a){case 1:f=1;break;case-1:f=-1;break;default:case 0:f=!1}},all:function(){var d=this,e=a.all(),g={};e.forEach(function(a){g[d.keyAccessor()(a)]=d.valueAccessor()(a)});var h=Object.keys(g).sort(),i=e.map(function(a){var c,e=a,f=0,i=h.indexOf(d.keyAccessor()(a)),j=h[i-1];if(j){var k=g[j];c=k;var l=d.valueAccessor()(e)-c;if(0!==l){var m=l/c;f=100*m}else f=0}var n={key:a.key,value:a.value,percentageChange:f};return b&&(n._debug={thisDayKey:e.key,thisDayValue:e.value,prevDayKey:j?j:"None",prevDayValue:c?c:"None"}),n});return c(f,i),i},top:function(){var d=this,e=a.top.apply(a,arguments),g={};e.forEach(function(a){g[d.keyAccessor()(a)]=d.valueAccessor()(a)});var h=Object.keys(g).sort(),i=e.map(function(a){var c,e=a,f=0,i=h.indexOf(d.keyAccessor()(a)),j=h[i-1];if(j){var k=g[j];c=k;var l=d.valueAccessor()(e)-c;if(0!==l){var m=l/c;f=100*m}else f=0}var n={key:a.key,value:a.value,percentageChange:f};return b&&(n._debug={thisDayKey:e.key,thisDayValue:e.value,prevDayKey:j?j:"None",prevDayValue:j?c:"None"}),n});return c(f,i),i}}},d.crossfilter=a,d}if("function"==typeof define&&define.amd)define(["crossfilter"],a);else if("object"==typeof module&&module.exports){var b=require("crossfilter");"function"!=typeof b&&(b=b.crossfilter),module.exports=a(b)}else this["crossfilter-ma"]=a(crossfilter),this.crossfilter$ma=this["crossfilter-ma"]}();
//# sourceMappingURL=crossfilter-ma.min.js.map