quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 6.07 kB
JavaScript
import CartesianAxis from'./cartesian';import ScaleLog from'./scales/log';import diff from'./utils/array/diff';import{UNDEF,pluckNumber,pluck,preDefStr,extent,getSuggestiveRotation,convertColor}from'../lib';import{getTrendLineLimits}from'./common-api';var validate=function(a){return!(null===a||a===UNDEF||''===a||isNaN(a))},queryOptions={wrtVisible:!0},POSITION_START=preDefStr.POSITION_START,POSITION_TOP=preDefStr.POSITION_TOP,POSITION_BOTTOM=preDefStr.POSITION_BOTTOM,POSITION_END=preDefStr.POSITION_END,LABEL_ID='_label',logTicksMerge=function(a=[],b=[]){if(0===a.length)return[];let c=a.length,d=b.length,e=c-1,f=d-1,g=[a[e]];for(e--;0<=e;)b[f]>a[e]?(g.push(b[f]),f--):(g.push(a[e]),e--);return g};class LogAxis extends CartesianAxis{constructor(){super(),this.config.scale=new ScaleLog,this.config.labelMap=[]}__setDefaultConfig(){super.__setDefaultConfig();let a=this.config;a.base=10,a.showMinorDivLineValues=1,a.numMinorDivLines=UNDEF}getName(){return'log'}configureAttributes(a){var b,c=this,d=c.config,e=c.getFromEnv('number-formatter'),f=c.getFromEnv('color-manager');super.configureAttributes(a),b=d.rawAttr,d.minorDivlinecolor=convertColor(pluck(b.minorDivlinecolor,f.getColor('divLineColor')),pluckNumber(b.minorDivLineAlpha,f.getColor('divLineAlpha')/2)),d.axisMinValue=e.getCleanValue(b.axisMinValue),d.axisMaxValue=e.getCleanValue(b.axisMaxValue),d.minorTicks=[],0>=d.axisMinValue&&(d.axisMinValue=UNDEF),0>=d.axisMaxValue&&(d.axisMaxValue=UNDEF),c.getScale().setBase(d.base),d.minorDivLineThickness=pluckNumber(b.minorDivLineThickness,1),d.band.isDraw=0}generateTicks(){let a=this.getScale().ticks();return this.config._allTicks=a.slice(),a}generateMinorTicks(){return this.getScale().minorTicks(this.config.numMinorDivLines)}_setAxisRange({min:a=.1,max:b=1}){var c=this.getScale().setDomain([a,b]).nice(),d=this.config,e=d.axisRange;d.ticks=this.generateTicks(),d.minorTicks=this.generateMinorTicks(),[a,b]=c.getDomain(),e.max=b,e.min=a,this.setVisibleConfig(a,b)}setDataLimit(a,b){var c,d,e=this,f=e.config,g=f.axisMaxValue,h=f.axisMinValue;validate(h)&&+h<=b&&(b=h),validate(g)&&+g>=a&&(a=g),0===b&&(b=1),0===a&&(a=f.base),[c,d]=e.getTrendLineLimits(),[b,a]=extent([c,d,b,a],b=>+b),this._setAxisRange({min:b,max:a})}_parseLabel(){var a,b,c,d,e,f,g,h,j,k,l,m,n,o,p,q,r,s=this,t=s.config,u=s.getFromEnv('chart'),v=u.config,w=t.axisRange,x=t.isOpposit,y=t.labels,z=y.style,A=t.isVertical,B=w.max,C=w.min,D=v.canvasBottom,E=v.canvasLeft,F=v.canvasRight,G=v.canvasTop,H=t.labelPadding,I=s.getFromEnv('number-formatter'),J=t.labelMaxH,K=t.labelMaxW,L=t.axisStartPosition,M=s.components,N=t.minorTicks;if(z.lineHeight&&(f=z.lineHeight,-1!==f.indexOf('px')&&(f=f.replace('px',''),f=parseFloat(f))),t.labels.isDraw)for(r=1!==s.getZoom(),q=M.labels,a=t.labels.step?w.tickInterval*t.labels.step:w.tickInterval,e=t.labels.rotation,d=this.getVisibleConfig(),M.labelIndexArr=[],t.allTicks=k=logTicksMerge(t.ticks,t.minorTicks),p=A?J:K,l=k.length,b=0;b<l;b++)if((m=k[b],n=s.getPixel(m,queryOptions),!(0<=N.indexOf(m))||t.showMinorDivLineValues)&&!(o&&n>o-p&&n<o+p)&&!(r&&(m<d.minValue||m>d.maxValue))&&(t.labels.drawNormalVal||t.labels.drawLimitVal&&(m===C||m===B))&&(t.labels.drawNormalVal||m===C||m===B)&&(t.labels.drawLimitVal||m!==C&&m!==B)&&(0!==t.showZeroPlaneValue||0!==t.showZeroPlane||0!==m)){if(1===t.showZeroPlane&&1===t.showZeroPlaneValue&&(0>m&&0<m+a||0<m&&0>m-a))if(A){if(n+J>=s.getPixel(0,queryOptions)&&s.getPixel(0,queryOptions)>=n-J)continue;}else if(n+K>=s.getPixel(0,queryOptions)&&s.getPixel(0,queryOptions)>=n-K)continue;j={fill:z.color,"font-size":z.fontSize},A?(g=t.numberFormatterFn?I[t.numberFormatterFn]:t.isPercent?I.percentValue:I.yAxis,c=''+g.call(I,m),h=t.hasCategory?t.categories.category[b].labelPadding||0:0,j['text-anchor']=x?POSITION_START:POSITION_END,j.text=c,j.x=x?(L||F)+H:(L||E)-H,j.y=h?n+h:n,o=j.y):(g=t.numberFormatterFn?I[t.numberFormatterFn]:t.isPercent?I.percentValue:I.xAxis,c=''+g.call(I,m),h=t.hasCategory?+t.categories.category[b].labelPadding||0:0,j.text=c,j.x=n,j.y=x?(L||G)-H:(L||D)+H,h&&(j.y+=h),e?(j['text-anchor']=x?POSITION_START:POSITION_END,j['vertical-align']='middle'):j['vertical-align']=x?POSITION_BOTTOM:POSITION_TOP,o=j.x),y.shiftX&&(j.x+=y.shiftX),y.shiftY&&(j.y+=y.shiftY),j.transform=getSuggestiveRotation(e,j.x,j.y),M.labelIndexArr.push(b),q[b]=q[b]||{config:{props:{label:{}}}},q[b].config.props.label.attr=j,q[b].config.props.label.css=c.css,q[b].config.value=m}}_drawLabel(){var a,b,c,d,e,f,g,h,k,l=this,m=l.config,n=l.getFromEnv('animationManager'),o=m.labels,p=o.style,q=m.axisContainer,r=[],s=l.components,t=s.labelIndexArr,u={fontFamily:p.fontFamily,fontSize:p.fontSize,fontWeight:p.fontWeight,fontStyle:p.fontStyle,lineHeight:p.lineHeight},v=b=>{for(a=0;a<b.length;++a)e=l.getGraphicalElement(b[a]),e&&l.removeGraphicalElement(e)};if(m.labels.isDraw){for(k=s.labels,q.css(u),g=t.length,b=0;b<g;b++)a=t[b],h=k[a].config.value,c=h+LABEL_ID,f=l.getGraphicalElement(c),r.push(c),f=this.addGraphicalElement(c,n.setAnimation({container:q,el:f||'text',attr:k[a].config.props.label.attr,data:{value:h},component:this,label:'text',css:k[a].config.props.label.css}));d=diff(m.labelMap,r)}else d=m.labelMap;m.labelMap=r,v(d)}_getVMaxLabelDimention(){var a,b,c,d,e,f,g,h,j=this,k=j.config,l=j.getFromEnv('chart'),m=j.getFromEnv('smartLabel'),n=j.getFromEnv('number-formatter'),o=k.labels.style,p=0;for(m.useEllipsesOnOverflow(l.config.useEllipsesWhenOverflow),m.setStyle({fontSize:o.fontSize,fontFamily:o.fontFamily,lineHeight:o.lineHeight,fontWeight:o.fontWeight}),g=k.isPercent?n.percentValue:n.xAxis,k.allTicks=a=logTicksMerge(k.ticks,k.minorTicks),b=a.length,d=0;d<b;d++)h=a[d],e=''+g.call(n,h),f=m.getOriSize(e),j.components.labels[d]={config:{width:f.width,height:f.height,props:{label:{}}}},e.length>p&&(c=f,p=e.length);return c}_getHMaxLabelDimention(){return this._getVMaxLabelDimention()}getCleanValue(a){var b=this,c=null;return a=Math.abs(a),0<a&&(c=b.getFromEnv('number-formatter').getCleanValue(a)),c}}LogAxis.prototype.getTrendLineLimits=getTrendLineLimits;export default LogAxis;