quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 2.42 kB
JavaScript
import ScaleContinuous,{copyScale,deInterpolateLinear as deinterpolate}from'../../../fc-core/src/axis/scales/continuous';import reinterpolate from'../../../fc-core/src/axis/utils/interpolators/number';import timeTicks,{tickInterval}from'../time-intervals/ticks';import enUS from'../time-converter/locales/en-US';import{TimeConverter}from'../time-converter';const durationSecond=1e3,durationMinute=60000,durationHour=3600000,durationDay=86400000,durationWeek=604800000,durationMonth=2592000000,durationYear=31536000000,date=a=>new Date(a),number=a=>a instanceof Date?+a:+new Date(+a),nice=(a,b)=>{const c=a.slice();let d,e=0,f=c.length-1,g=c[e],h=c[f];return h<g&&(d=e,e=f,f=d,d=g,g=h,h=d),c[e]=b.floor(g),c[f]=b.ceil(h),c};class ScaleCalendar extends ScaleContinuous{constructor(a,b,c,d,e,f,g,h){super(deinterpolate,reinterpolate),this.timeIntervals={year:a,month:b,week:c,day:d,hour:e,minute:f,second:g,millisecond:h},this.tickIntervals=[[this.timeIntervals.second,1,durationSecond],[this.timeIntervals.second,5,5000],[this.timeIntervals.second,15,15000],[this.timeIntervals.second,30,30000],[this.timeIntervals.minute,1,durationMinute],[this.timeIntervals.minute,5,300000],[this.timeIntervals.minute,15,900000],[this.timeIntervals.minute,30,1800000],[this.timeIntervals.hour,1,durationHour],[this.timeIntervals.hour,3,10800000],[this.timeIntervals.hour,6,21600000],[this.timeIntervals.hour,12,43200000],[this.timeIntervals.day,1,durationDay],[this.timeIntervals.day,2,172800000],[this.timeIntervals.week,1,durationWeek],[this.timeIntervals.month,1,durationMonth],[this.timeIntervals.month,3,7776000000],[this.timeIntervals.year,1,durationYear]],this.locale=enUS,this._localeConverter=new TimeConverter(enUS)}setDomain(a){return super.setDomain(a.map(number))}getDomain(){return super.getDomain().map(date)}ticks(a,b){const c=super.getDomain();return timeTicks(c[0],c[c.length-1],a,b,this.tickIntervals,this.timeIntervals)}nice(a,b){const c=super.getDomain(),d=tickInterval(c[0],c[c.length-1],a,b,this.tickIntervals,this.timeIntervals);return d?super.setDomain(nice(c,d)):this}getDomainValue(a){return new Date(super.getDomainValue(a))}setLocale(a=enUS){return this.locale=a,this._localeConverter=new TimeConverter(this.locale),this}copy(){const{year:a,month:b,week:c,day:d,hour:e,minute:f,second:g,millisecond:h}=this.timeIntervals;return copyScale(this,new ScaleCalendar(a,b,c,d,e,f,g,h))}}export default ScaleCalendar;