UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 2.17 kB
const DEFAULT_THRESHOLD_PIXELS=4,clamp=(a,b,c)=>Math.min(Math.max(a,b),c),date=a=>new Date(a),_getStandardBin=function(a,b){for(var c=Math.floor,d=0,e=a.length-1,f=e,g=c((e+d)/2),h=b instanceof Array?b[2]:b.unit.ms*b.multiplier;d<e;){if(h<a[g][2])f=e=g-1;else if(h>a[g][2])d=g+1;else{f=g;break}g=c((e+d)/2)}return b instanceof Array?a[f]:a[f][2]===h?a[f]:[a[f-1][0],b.multiplier,h]},_calculateIndexOfIntervals=a=>{let b,c={},d=a.length;for(b=d-1;0<=b;b--)c[a[b][0].name()]=b;return c};class BinDecider{constructor(a){this.setStandardBins(a),this.binRange=[0,1],this.binDomain=[0,1],this.thresholdPixels=DEFAULT_THRESHOLD_PIXELS,this.intervalIndexMap=_calculateIndexOfIntervals(this.getStandardBins())}setStandardBins(a){this.standardBins=a}getStandardBins(){return this.standardBins}setScale(a){this.scale=a}getScale(){return this.scale}_computeRangeThreshold(a){var b=Math.abs;const c=this.getBinRange(),d=c[0],e=c[1],f=clamp(a,1,b(d-e)),g=+this.getScale().getDomainValue(0),h=+this.getScale().getDomainValue(f),i=b(h-g),j=this.getBinMin(),k=this.getBinMax(),l=Math.max(0,this.standardBins.findIndex(a=>a[2]>=i));this._threshold=this.standardBins[l][2]<j[2]?j:k&&this.standardBins[l][2]>k[2]&&k[2]>=j[2]?k:this.standardBins[l]}setBinRange(a){return this.binRange=a.slice(),this.getScale().setRange(this.binRange),this.getScale().setDomain(this.binDomain),this._computeRangeThreshold(this.thresholdPixels),this}getBinRange(){return this.binRange}setBinDomain(a){return this.binDomain=a.slice(),this.getScale().setRange(this.binRange),this.getScale().setDomain(this.binDomain),this._computeRangeThreshold(this.thresholdPixels),this}getBinDomain(){return this.binDomain.slice().map(date)}setBinMin(a){const b=_getStandardBin(this.standardBins,a);return this.minBin=b,this}getBinMin(){return this.minBin}setBinMax(a){const b=_getStandardBin(this.standardBins,a);this.maxBin=b}getBinMax(){return this.maxBin}setRangeThreshold(a=DEFAULT_THRESHOLD_PIXELS){return a!==this.thresholdPixels&&this._computeRangeThreshold(this.thresholdPixels=a),this}getRangeThreshold(){return this._threshold}}export default BinDecider;export{_calculateIndexOfIntervals,DEFAULT_THRESHOLD_PIXELS};