UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 3.15 kB
import{BLANKSTRING,pluckNumber,preDefStr}from'../../../../fc-core/src/lib';import Bar from'../bar2d';let UNDEF,visibleStr=preDefStr.visibleStr,hiddenStr=preDefStr.hiddenStr,POSITION_MIDDLE=preDefStr.POSITION_MIDDLE,POSITION_START=preDefStr.POSITION_START,POSITION_END=preDefStr.POSITION_END,math=Math,mathMax=math.max,defined=function(a){return a!==UNDEF&&null!==a};function checkOverlap(a,b){let c,d,e,f,g=a.x,h=a.width;for(c=0,d=b.length;c<d;c++)if(f=b[c].width,e=b[c].x,b[c].labelShown&&g+h>=e&&e+f>=g)return!0;return!1}class OverlappedColumn extends Bar{constructor(){super(),this._labeldimensionMap={}}drawLabel(){var a,b,c,d,e,f,g,h,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D=this,E=D.getFromEnv('chart'),F=E.config,G=D.config.JSONData,H=D.getFromEnv('animationManager'),I=E.getChildren('canvas')[0].config,J=E.config.dataLabelStyle,K=G.data,L=E.config.categories,M=E.config.is3D,N=E.config.isstacked,O=L&&L.length,P=K&&K.length,Q=D.getData(),R=E.getFromEnv('smartLabel'),S=I.yDepth,T=I.xDepth,U=E.getFromEnv('number-formatter'),V='',W=F.placevaluesinside,X=F.canvasWidth,Y=F.canvasLeft,Z=F.valuepadding+2,$=D.getContainer('labelGroup'),_=D.getSkippingInfo&&D.getSkippingInfo(),aa=_&&_.skippingApplied,ba=_&&_.labelDraw||[],ca=ba.length,da=D.getJSONIndex(),ea=D.getState('visible'),fa=function(){this.hide()},ga=function(){this.show()};for(ea&&$.show(),R.setStyle(J),a=aa?ca:O<P?O:P,e=0;e<a;e++){if(d=aa?ba[e]:e,b=Q[d],v=b&&b.config,r=v&&v.setValue,b===UNDEF||r===UNDEF||null===r||!0===v.labelSkip){C=b&&b.graphics,C&&C.label&&C.label.hide(),v&&delete v.labelSkip;continue}(g=b.graphics,!!g)&&(f=K[d],o=b._yPos,p=b._xPos,r=U.getCleanValue(f.value),n=0>pluckNumber(r),h=b._height,q=b._width,s=N?POSITION_MIDDLE:n?W?POSITION_START:POSITION_END:W?POSITION_END:POSITION_START,V=v.displayValue,A=g.label,v.showValue&&defined(V)&&V!==BLANKSTRING&&null!==r?(c={text:V,fill:J.color,"text-bound":[J.backgroundColor,J.borderColor,J.borderThickness,J.borderPadding,J.borderRadius,J.borderDash],"line-height":J.lineHeight,visibility:D.getState('visible')?visibleStr:hiddenStr},B=R.getOriSize(V),t=B.width,t+=Z,u=Z,k=o+.5*h,l=p+(n?0:q),m=n?p-Y:Y+X-(p+q),W?q>=t?(l+=n?u:-u,M&&(k+=S,l-=T)):t<m?(l+=n?-u:u,s=n?POSITION_END:POSITION_START,M&&n&&(l-=T)):n?(l=p+q+mathMax(t-p-q+Y,0)-u,s=POSITION_END):(l=p-mathMax(t-(Y+X-p),0)+u,s=POSITION_START):m>=t?(l+=n?-u:u,M&&n&&(l-=T,k+=T)):l+=n?u+t:-(u+t),(l>Y+X||l<Y)&&(l=Y+4,s=POSITION_START),c['text-anchor']=s,c.x=l,c.y=k,c['text-bound']=[J.backgroundColor,J.borderColor,J.borderThickness,J.borderPadding,J.borderRadius,J.borderDash],c.opacity=ea?1:0,x=E.getDatasets().map(a=>a.getJSONIndex()<da&&a._labeldimensionMap[e]).filter(Boolean),y={x:l,y:k,width:B.width,height:B.height},z=checkOverlap(y,x),D._labeldimensionMap[e]=y,z?g.label&&(g.label=H.setAnimation({el:g.label,component:D}),D._labeldimensionMap[e].labelShown=!1):(w=H.setAnimation({el:A||'text',container:$,component:D,attr:c,callback:ea?ga:fa,label:'plotLabel'}),!A&&(g.label=w)),D._labeldimensionMap[e].labelShown=ea&&!z):g.label&&(g.label=H.setAnimation({el:g.label,component:D}),D._labeldimensionMap[e].labelShown=!1))}}}export default OverlappedColumn;