UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 12.5 kB
import{preDefStr,parseTooltext,pluck,getValidValue,pluckNumber,getFirstValue,HUNDREDSTRING,parseUnsafeString,convertColor,getFirstAlpha,getFirstColor}from'../../../../fc-core/src/lib';import ColumnDataset from'../../../../fc-charts/src/dataset/column';import{addDep}from'../../../../fc-core/src/dependency-manager';import errorbarAnimation from'./index.animation';let UNDEF,removePlots,_getHoveredPlot,_firePlotEvent,_checkPointerOverPlot,_checkPointerOverErrorBar,colorStrings=preDefStr.colors,COLOR_AAAAAA=colorStrings.AAAAAA,ROUND=preDefStr.ROUND,MOUSEOVER='mouseOver',MOUSEOUT='mouseOut',PERCENTAGESTRING=preDefStr.PERCENTAGESTRING,pStr=preDefStr.pStr,sStr=preDefStr.sStr,BLANKSTRING='',ROLLOVER='DataPlotRollOver',ROLLOUT='DataPlotRollOut',COMMASPACE=', ',DEFAULT_CURSOR='default',POINTER='pointer',EVENTARGS='eventArgs',GROUPID='groupId',M='M',H='H',V='V',_rolloverResponseSetter=function(a,b,c,d){var e=b.graphics,f=b.errorBarHovered,g=e&&e.element,h=a.getFromEnv('animationManager'),i=g&&g.getData();!f&&g&&0!==i.showHoverEffect&&(h.setAnimationState(MOUSEOVER),h.setAnimation({el:g,label:'rect',component:d,attr:g.getData().setRolloverAttr,doNotRemove:!0})),g&&a.plotEventHandler(g,c,ROLLOVER)},_rolloutResponseSetter=function(a,b,c,d){var e=b.graphics,f=b.errorBarHovered,g=e&&e.element,h=a.getFromEnv('animationManager'),i=g&&g.getData();!f&&g&&0!==i.showHoverEffect&&(h.setAnimationState(MOUSEOUT),h.setAnimation({el:g,label:'rect',component:d,attr:g.getData().setRolloutAttr,doNotRemove:!0})),g&&a.plotEventHandler(g,c,ROLLOUT)};addDep({name:'errorbar2DColumnAnimation',type:'animationRule',extension:errorbarAnimation.column}),addDep({name:'errorbar2DErrorAnimation',type:'animationRule',extension:errorbarAnimation.error});class ErrorBar2DDataset extends ColumnDataset{getType(){return'dataset'}getName(){return'errorBar2D'}ErrorValueConfigure(){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=Math.min,E=this,F=E.config,G=F.JSONData,H=G.data,I=1,J=E.getFromEnv('chart-attrib'),K=E.components.data,L=parseUnsafeString(J.yaxisname),M=parseUnsafeString(J.xaxisname),N=pluckNumber(J.seriesnameintooltip,1),O=parseUnsafeString(pluck(J.tooltipsepchar,', ')),P=E.getFromEnv('number-formatter'),Q=-Infinity,R=1/0,S=E.getFromEnv('xAxis'),T=S.getTicksLen(),U=D(T,I),V=function(b){var d;return F.showTooltip?null===m?d=!1:b===UNDEF?(N&&(e=getFirstValue(G&&G.seriesname)),d=e?e+O:BLANKSTRING,d+=c.label?c.label+O:BLANKSTRING):(g=[1,2,3,4,5,6,7,99,100,101,102,120,121],h={yaxisName:L,xaxisName:M,formattedValue:c.toolTipValue,errorValue:l,errorDataValue:c.errorToolTipValue,errorPercentValue:c.errorPercentValue,errorPercentDataValue:c.errorPercentValue,positiveErrorValue:c.positiveErrorToolTipValue,negativeErrorValue:c.negativeErrorToolTipValue,label:c.label},d=parseTooltext(b,g,h,a,J,G)):d=!1,d};for(F.showTooltip=pluckNumber(J.showtooltip,1),F.errorInPercent=f=pluckNumber(G.errorinpercent,J.errorinpercent),F.showValues=pluckNumber(G.showvalues,J.showvalues,0),F.errorBarShadow=o=pluckNumber(J.errorbarshadow,J.showshadow,1),F.ignoreEmptyDatasets=pluckNumber(G.ignoreemptydatasets,0),u=pluckNumber(J.halferrorbar,1),F.notHalfErrorBar=!pluckNumber(J.halferrorbar,1),k=getFirstAlpha(pluck(G.errorbaralpha,J.errorbaralpha,F.plotfillalpha)),F.errorBarWidthPercent=pluckNumber(G.errorbarwidthpercent,J.errorbarwidthpercent,70),F.errorBarColor=convertColor(getFirstColor(pluck(G.errorbarcolor,J.errorbarcolor,COLOR_AAAAAA)),k),F.errorBarThickness=pluckNumber(G.errorbarthickness,J.errorbarthickness,1),F.shadowOpacity=o?k/250:0,F.parentYAxis=p=pluck(G.parentyaxis&&G.parentyaxis.toLowerCase(),pStr)===sStr?1:0,F.cumulativeValueOnErrorBar=pluckNumber(G.cumulativevalueonerrorbar,J.cumulativevalueonerrorbar,1),C=0;C<U;C++)(b=K[C],!!b)&&(a=H&&H[C],c=b&&b.config,A=UNDEF,B=UNDEF,pluckNumber(a.value)!==UNDEF)&&(b||(b=K[C]={graphics:{}}),b.config||(c=K[C].config={}),q=c.setValue,c.setErrorValue=l=P.getCleanValue(a.errorvalue),c.errorInPercent=pluckNumber(a.errorinpercent,f,0),c.errorInPercent&&(c.setErrorValue=l=pluckNumber((l/100*q).toFixed(2))),c.cumulativeValueOnErrorBar=pluckNumber(a.cumulativevalueonerrorbar,F.cumulativeValueOnErrorBar,1),c.positiveErrorValue=P.getCleanValue(pluckNumber(a.positiveerrorvalue,a.errorvalue)),c.errorInPercent&&c.positiveErrorValue&&(c.positiveErrorValue=pluckNumber((c.positiveErrorValue/100*q).toFixed(2))),c.positiveCumulativeErrorValue=q+pluckNumber(c.positiveErrorValue,c.setErrorValue),c.negativeErrorValue=P.getCleanValue(pluckNumber(a.negativeerrorvalue,a.errorvalue)),c.errorInPercent&&c.negativeErrorValue&&(c.negativeErrorValue=pluckNumber((c.negativeErrorValue/100*q).toFixed(2))),c.negativeCumulativeErrorValue=q-pluckNumber(c.negativeErrorValue,c.setErrorValue),c.errorToolTipValue=P.dataLabels(l,p),c.negativeErrorToolTipValue=P.dataLabels(c.negativeErrorValue,p),c.negativeCumulativeErrorTooltipValue=P.dataLabels(c.negativeCumulativeErrorValue,p),c.positiveErrorToolTipValue=P.dataLabels(c.positiveErrorValue,p),c.positiveCumulativeErrorTooltipValue=P.dataLabels(c.positiveCumulativeErrorValue,p),c.errorPercentValue=Math.round(l/q*HUNDREDSTRING*HUNDREDSTRING)/HUNDREDSTRING+PERCENTAGESTRING,x=c.cumulativeValueOnErrorBar,c.notHalfErrorBar=F.notHalfErrorBar,c.halfErrorBar=u,c.showValue=pluckNumber(a.showvalue,F.showValues),c.hasErrorValue=pluckNumber(a.errorvalue)===UNDEF?0:1,r=c.errorValue=l,j=c.errorToolTipValue,m=j,n=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,G.errorplottooltext,J.errorplottooltext,m))),d=V(n),A=B=UNDEF,n=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,G.errorplottooltext,J.errorplottooltext,c.positiveErrorToolTipValue))),n&&c.positiveErrorToolTipValue&&(A=V(n)),n=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,G.errorplottooltext,J.errorplottooltext,c.negativeErrorToolTipValue))),n&&c.negativeErrorToolTipValue&&(B=V(n)),x&&(n=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,G.errorplottooltext,J.errorplottooltext,c.positiveCumulativeErrorTooltipValue))),n&&c.positiveCumulativeErrorTooltipValue&&(y=V(n)),n=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,G.errorplottooltext,J.errorplottooltext,c.negativeCumulativeErrorTooltipValue))),n&&c.negativeCumulativeErrorTooltipValue&&(z=V(n))),v=c.positiveErrorValue,w=c.negativeErrorValue,(a.positiveerrorvalue||a.negativeerrorvalue)&&(c.halfErrorBar=0,c.notHalfErrorBar=!0),s=q+(null===v?l:v),t=q-(c.halfErrorBar?0:0>w&&0>q?0:null===w?l:w),Q=Math.max(Q,s,t),R=D(R,s,t),c.errorValueArr=[],null===c.positiveErrorValue&&(c.positiveErrorValue=UNDEF),r=-c.positiveErrorValue,c.errorValueArr.push({errorValue:r,tooltext:x?y:A||d,errorEdgeBar:!0}),c.errorValueArr.push({errorValue:r,tooltext:A||d}),c.notHalfErrorBar&&(r=c.negativeErrorValue,c.errorValueArr.push({errorValue:r,tooltext:x?z:B||d,errorEdgeBar:!0}),c.errorValueArr.push({errorValue:r,tooltext:B||d})),c.toolText=V(c.setTooltext));F.maxValue=Q,F.minValue=R}drawErrorValue(){var a,b,c,d,e,f,g,h,j,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,I,J,K=Math.round,L=this,N=L.getJSONIndex(),O=L.config,P=L.getState('visible'),Q=L.getFromEnv('chart'),R=L.getFromEnv('yAxis'),S=L.components.data,T=O.errorBarThickness,U=O.errorBarWidthPercent,W=O.errorBarColor,X=O.shadowOpacity,Y=L.getContainer('errorPlotGroup'),Z=L.getContainer('errorShadowGroup'),$=O.scrollMinVal,_=O.scrollMaxVal,aa=function(a){return function(){'disappearing'===a?this.hide():this.show()}},ba=L.getFromEnv('animationManager');for(b=$;b<_;b++)if(g=S[b],!!g){if(G=g.trackerConfig,J=g.errorTrackerConfig={},J.errorTrackerArr=[],j=g&&g.config,h=j&&j.setValue,g===UNDEF)continue;else if(g&&(h===UNDEF||null===h||j.errorValue===BLANKSTRING||j.errorValue===UNDEF||null===j.errorValue&&null===j.positiveErrorValue&&null===j.negativeErrorValue)){for(v=g.graphics.error&&g.graphics.error.length,c=0;c<v;c++)g.graphics.error&&g.graphics.error[c]&&(ba.setAnimation({el:g.graphics.error[c],label:'path',callback:aa('disappearing')}),g.graphics.error[c].shadow({opacity:0}));continue}for(g.errorBar&&delete g.errorBar,r=j.errorValueArr,J.errorLen=v=r.length,g.graphics.error||(g.graphics.error=[]),y=N+'_'+b,d=j.setLink,A=0>h,B=g._xPos,C=g._yPos,D=g._width,E=g._height,f=A?C+E:C,e=B+D/2,g.errorBar||(g.errorBar=[]);v--;){if(z=null,J.errorTrackerArr[v]={},s=r[v],J.errorTrackerArr[v].tooltext=s.tooltext,F=s.errorStartValue,u=isNaN(F)?f:R.getPixel(F),t=s.errorValue,null===t||isNaN(t)){g.graphics.error&&g.graphics.error[v]&&ba.setAnimation({el:g.graphics.error[v],label:'path',doNotRemove:!0,callback:aa('disappearing')}).shadow({opacity:0});continue}w=D*(U/100),x=w/2,q=P?-1:0,p=R.getPixel(R.getValue(isNaN(F)?C:u)+t*q,{wrtVisible:!0}),A&&(p+=E),m=p,n=e,T=pluckNumber(s.errorBarThickness,T),I=5<T?T/2:2.5,m=K(p)+T%2/2,n=K(e)+T%2/2,g.errorBar[v]||(g.errorBar[v]=[]),s.errorEdgeBar?(o=[M,n-x,m,H,n+x],g.errorBar[v][1]={_xPos:n-x-I,_yPos:m-I,_height:2*I,_width:2*(x+I),_toolText:s.tooltext}):(o=[M,n,u,V,m],g.errorBar[v][0]={_xPos:n-I,_yPos:m<u?m:u,_height:Math.abs(u-m),_width:2*I,_toolText:s.tooltext}),W=pluck(s.errorBarColor,W),a={path:o,stroke:W,"stroke-width":T,cursor:d?POINTER:BLANKSTRING,"stroke-linecap":ROUND},l=!g.graphics.error[v]&&P?'appearing':P?'updating':'disappearing',z=g.graphics.error[v]=ba.setAnimation({el:g.graphics.error[v]||'path',container:Y,component:L,attr:a,label:'path',state:l,callback:aa(l)}).shadow({opacity:X},Z),Q.config.enablemousetracking&&z.data(GROUPID,y).data(EVENTARGS,G.eventArgs)}if(!j.notHalfErrorBar)for(c=2;4>c;c++)g.graphics.error&&g.graphics.error[c]&&ba.setAnimation({el:g.graphics.error[c],label:'path',doNotRemove:!0,callback:aa('disappearing')}).shadow({opacity:0})}}_firePlotEvent(a,b,c){var d=this,e=d.getFromEnv('chart'),f=d.components.data[b],g=d.getFromEnv('toolTipController'),h=f.graphics.element,i=f.errorBarHovered,j=f.config,k=j.setLink;h&&('fc-mouseover'===a?(d._decideTooltipType(b,c),_rolloverResponseSetter(e,f,c,this),k&&(h.node.style.cursor=POINTER)):'fc-mouseout'===a?(g.hide(d.config.currentToolTip),_rolloutResponseSetter(e,f,c,this),k&&(h.node.style.cursor=DEFAULT_CURSOR)):'fc-click'===a?e.plotEventHandler(h,c):'fc-mousemove'===a?(d._decideTooltipType(b,c),i&&!f._isRollover?(0!==h.showHoverEffect&&h.attr(h.getData().setRolloutAttr),f._isRollover=!0,f._isRollout=!1):!i&&!f._isRollout&&(0!==h.showHoverEffect&&h.attr(h.getData().setRolloverAttr),f._isRollover=!1,f._isRollout=!0)):void 0)}_checkPointerOverErrorBar(a,b,c){var d,e,f,g,h,i,j,k,l,m,n=this,o=n.components.data,p=o[a];if(p&&(e=p.errorBar,!!e))for(g=e&&e.length;g--;)for(f=e[g],h=f&&f.length;h--;)if(f[h]&&f[h]._xPos&&(j=f[h]._xPos,k=f[h]._yPos,l=f[h]._height,m=f[h]._width,i=f[h]._toolText,d=b>=j&&b<=j+m&&c>=k&&c<=k+l,d))return{pointIndex:a,hovered:d,pointObj:o[a],toolText:i}}_checkPointerOverPlot(a,b,c){var d,e,f=this,g=f.components.data,h=f.getFromEnv('chart-attrib'),i=f.config.JSONData,j=g[a],k=j&&j.config;if(j)return d=i.plottooltext||h.plottooltext?BLANKSTRING:k.toolTipValue,e=f._checkPointerOverErrorBar(a,b,c),e?(j.errorBarHovered=!0,k.finalTooltext=e.toolText):(e=f._checkPointerOverColumn(a,b,c),j.errorBarHovered=!1,e&&(k.finalTooltext=!1!==k.toolText&&k.toolText+d)),e}_getHoveredPlot(a,b){var c,d,e=this,f=e.getFromEnv('xAxis');return c=f.getValue(a),d=Math.round(c),0<d-c?e._checkPointerOverPlot(d,a,b)||e._checkPointerOverPlot(d-1,a,b):e._checkPointerOverPlot(d+1,a,b)||e._checkPointerOverPlot(d,a,b)}removePlots(){var a,b,c,d,e=this,f=e.components,g=f.removeDataArr,h=f.pool||(f.pool={element:[],hotElement:[],label:[]}),j=g.length,l=e.getFromEnv('animationManager');for(c=0;c<j;c++)if(a=g[0],g.splice(0,1),a&&a.graphics){for(b=a.graphics,b.element&&b.element.hide()&&b.element.shadow({opacity:0}),d=0;4>d;d++)b.error&&b.error[d]&&l.setAnimation({el:b.error[d],label:'path'});a.graphics.element&&(h.element=h.element.concat(a.graphics.element)),a.graphics.hotElement&&(h.hotElement=h.hotElement.concat(a.graphics.hotElement)),a.graphics.label&&(h.label=h.label.concat(a.graphics.label))}f.pool=h}}removePlots=ErrorBar2DDataset.prototype.removePlots,_getHoveredPlot=ErrorBar2DDataset.prototype._getHoveredPlot,_firePlotEvent=ErrorBar2DDataset.prototype._firePlotEvent,_checkPointerOverPlot=ErrorBar2DDataset.prototype._checkPointerOverPlot,_checkPointerOverErrorBar=ErrorBar2DDataset.prototype._checkPointerOverErrorBar;export{_getHoveredPlot,removePlots,_rolloverResponseSetter,_rolloutResponseSetter,_firePlotEvent,_checkPointerOverErrorBar,_checkPointerOverPlot};export default ErrorBar2DDataset;