quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 5.83 kB
JavaScript
import CartesianLabelManager from'./cartesian-label-manager';import range from'./utils/array/range';import ScaleCategory from'./scales/category';import{toPrecision,UNDEF,parseUnsafeString,pluckNumber,pluck,BLANKSTRING,getDashStyle,preDefStr,extend2,convertColor}from'../lib';import{setTickValues}from'./common-api';var DASH_DEF='none',TRUE_STRING='true',ONE_STRING='1',POSITION_START=preDefStr.POSITION_START,POSITION_MIDDLE=preDefStr.POSITION_MIDDLE,POSITION_TOP=preDefStr.POSITION_TOP,POSITION_BOTTOM=preDefStr.POSITION_BOTTOM,POSITION_END=preDefStr.POSITION_END,queryOptions={wrtVisible:!0};class CategoryAxis extends CartesianLabelManager{constructor(){super(),this.config.scale=new ScaleCategory}getName(){return'category'}getCategoryFromId(a){var b=this.config,c=b.tickValues,d=c&&c.tickIdMap;return d[a]||{}}generateTicks(){let a=this.getScale(),b=this.config,c=a.getDomain(),d=b.categoryNumDivLines+1,e=(c[1]-c[0])/d,f=b.axisRange,{min:g,max:h}=f,i=(h-g)/d;return b._allTicks=range(g,h,i).concat(h),f.tickInterval=i,range(c[0],c[1],e).concat(c[1])}_parseCategoryVline(){var a,b,c,d,e,f,g,h,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H=this,I=H.config,J=I.axisRange,K=J.min,L=J.max,M=H.getFromEnv('chart'),N=M.config,O=N.style||{},P=I.isVertical,Q={fontFamily:N.style.inCanfontFamily,fontSize:N.style.inCanfontSize,color:N.style.inCancolor,lineHeight:N.style.inCanLineHeight};for(b=I.tickValues.vline,c=b.length,C=1!==H.getZoom(),D=H.getVisibleConfig(),f=0;f<c;f++)(d=b[f],e=parseUnsafeString(d.label),g=!!pluckNumber(d.showlabelborder,I.showVLineLabelBorder,1),a=!!pluckNumber(d.showlabelbackground,1),h=pluck(d.labelhalign,P?POSITION_START:POSITION_MIDDLE),'center'===h?h=POSITION_MIDDLE:'left'===h?h=POSITION_START:'right'===h&&(h=POSITION_END),j=pluck(d.labelvalign,P?POSITION_MIDDLE:POSITION_BOTTOM).toLowerCase(),j===POSITION_MIDDLE?j=POSITION_MIDDLE:j===POSITION_TOP?j=POSITION_BOTTOM:j===POSITION_BOTTOM&&(j=POSITION_TOP),k=pluckNumber(d.labelposition,0),l=pluckNumber(d.lineposition,.5),m=pluckNumber(d.showvlines,I.showVLines,1),n=pluckNumber(d.alpha,I.vLineAlpha,80),o=pluck(d.color,I.vLineColor).replace(/^#?/,'#'),p=a?pluck(d.labelbgcolor,I.vLineLabelBgColor,'333333').replace(/^#?/,'#'):BLANKSTRING,y=pluck(d.labelcolor,I.vLineLabelColor,d.color,O.inCancolor,I.vLineColor).replace(/^#?/,'#'),q=pluckNumber(d.thickness,I.vLineThickness,1),A=2,r=!!+pluck(d.dashed,0),s=pluckNumber(d.dashlen,5),u=pluckNumber(d.dashgap,2),t=Q.fontSize,t=parseInt(t.replace(/px/i,''),10),z=pluckNumber(d.rotatelabel,I.rotateVLineLabels)?270:0,l=0>l||1<l?.5:l,k=0>k||1<k?0:k,o=convertColor(o,m?n:'0'),G=d.animate&&!P?d.startIndex+1:d.startIndex,B=H._getVlinePos(G,l)-(d.animate?d.leftShift:0),!(C&&(B<D.minValue||B>D.maxValue)))&&(B<K||B>L||(v={opacity:1,stroke:o,"stroke-width":q,"stroke-dasharray":r?getDashStyle(s,u):DASH_DEF},x={opacity:1,text:e,"text-anchor":h,"vertical-align":j,"text-bound":[]},w={fontSize:Q.fontSize,fontFamily:Q.fontFamily,lineHeight:Q.lineHeight},F=pluckNumber(d.showontop,I.showVLinesOnTop,0),E={from:B,layer:F?3:2,attr:v,type:'line',startIndex:d.startIndex,linePosition:l},e&&(x['text-bound']=[p,m&&g?o:BLANKSTRING,m&&g?1:0,A,UNDEF,m&&g?'solid':BLANKSTRING],x.fill=m?y:o,E.text={label:e,attr:x,layer:4,labelRotation:z,labelPosition:k,css:w}),H.setReferenceInfo(E),H.config.parsedVlineInfo.push(E)))}_parseReferenceVisuals(){super._parseReferenceVisuals(),this.config.drawPlotlines&&this._parseCategoryVline()}categoryInsert(a,b,c){var d,e,f,g,h,j=this,k=j.config,l=k.axisRange.min,m=b.length,n=k.endPad||0;for(d=k.tickValues.tickValue,f=k.tickValues.tickIdMap,e=k.tickValues.vline,g=0;g<m;g+=1)h=extend2({},b[g]),h.vline===TRUE_STRING||!0===h.vline||1===h.vline||h.vline===ONE_STRING?(h.startIndex=a-2,e.push(h)):(h.id&&(f[h.id]={tickObj:h,i:a}),d.splice(a,0,h),a+=1);c&&j._setAxisRange({min:l,max:+toPrecision(d.length-1+n,10)})}categoryDelete(a,b,c){var d,e,f,g,h=this,j=h.config,k=j.axisRange,l=k.min;for(d=j.tickValues.vline,e=0,f=d.length;e<f;e++)d[e].animate=!0,d[e].leftShift=b;g=j.tickValues.tickValue,g.splice(a,b),h._shiftVline(a,b,'left'),c&&h._setAxisRange({min:l,max:k.max-b})}_shiftVline(a,b,c){var d,e,f=this,g=f.config,h=g.tickValues.vline,j=g.tickValues.tickValue.length,k=h.length;for(d=0;d<k;d+=1)e=h[d],e.startIndex>=a&&('right'===c?e.startIndex+=b:e.startIndex-=b,(0>e.startIndex||e.startIndex>=j)&&(h.splice(d,1),k-=1,d-=1))}categoryTranslate(a){var b,c=this,d=c.config,e=c.getPixel(1,queryOptions)-c.getPixel(0,queryOptions);a=(a||0)*e,d.isReverse&&(a=-a),b=['T',a,',','0'].join(''),c.realTimeTranslatableGroups=[{group:d.axisContainer,translationStr:b},{group:d.axisTrendLabelContainer,translationStr:b}]}updateTicksValues(a,b){var c,d,e,f,g,h,j,k=this,l=k.config,m=l.parsedVlineInfo;if(c=l.tickValues.tickValue,c[a])for(j in b)b.hasOwnProperty(j)&&('x'===j&&(d=!0),c[a][j]=b[j]);if(d)for(f=0,g=m.length;f<g;++f)if(e=m[f],h=e.startIndex,h===a)e.from=k._getVlinePos(h,e.linePosition);else if(h+1===a){e.from=k._getVlinePos(h,e.linePosition);break}}_getVlinePos(a,b){let c,d,e,f=this.getTickValues(),g=this.config,{min:h,max:i}=this.getLimit(),j=f[a],k=f[a+1];return j?!k&&(c=f[0]&&f[0].x?i:g.oriCatLen-1,e=!0):(c=f[0]&&f[0].x?h:-1,e=!0),e?d=b:(c=pluckNumber(j.x,j.y,a),d=(c-pluckNumber(k.x,k.y,a+1))*b),c+Math.abs(d)}getInterval(){if(this)return 1}_setAxisRange(a){var b,c,d=a.min,e=a.max,f=this.config,g=f.axisRange,h=f.periodLength,i=f.dataLimit,j=i.max,k=i.min;d>e||((j!==e||k!==d)&&(b=!0),f.visibleMin===UNDEF||f.setPadding||b?(i.max=e,i.min=d,h&&(f.categoryNumDivLines=(e-d)/h-1),c=(e-d)/(f.categoryNumDivLines+1),this.getScale().setDomain([d,e]),f.ticks=range(d,e,c).concat(e),f._allTicks=f.ticks.slice(),g.min=d,g.max=e,g.tickInterval=c,this.setVisibleConfig(g.min,g.max)):f.setPadding=!1)}}CategoryAxis.prototype.setTickValues=setTickValues;export default CategoryAxis;