UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 10.6 kB
import{preDefStr,parseTooltext,pluck,getValidValue,pluckNumber,getFirstValue,isIE,HUNDREDSTRING,hasTouch,TOUCH_THRESHOLD_PIXELS,CLICK_THRESHOLD_PIXELS,parseUnsafeString,convertColor,getFirstColor,getFirstAlpha}from'../../../../fc-core/src/lib';import{_getHoveredPlot,_firePlotEvent,_checkPointerOverErrorBar,removePlots}from'../errorbar2d';import LINEDataset from'../../../../fc-charts/src/dataset/line';import{addDep}from'../../../../fc-core/src/dependency-manager';import errorlineErrorAnimation from'./error.animation';import errorlineLineAnimation from'./line.animation';let UNDEF,colorStrings=preDefStr.colors,COLOR_AAAAAA=colorStrings.AAAAAA,ROUND=preDefStr.ROUND,PERCENTAGESTRING=preDefStr.PERCENTAGESTRING,BLANKSTRING='',COMMASPACE=', ',POINTER='pointer',TRACKER_FILL='rgba(192,192,192,'+(isIE?.002:1e-6)+')',M='M',H='H',V='V',math=Math,mathRound=math.round,mathMin=math.min,mathMax=math.max,mathAbs=math.abs,HTP=hasTouch?TOUCH_THRESHOLD_PIXELS:CLICK_THRESHOLD_PIXELS;addDep({name:'errorlineErrorAnimation',type:'animationRule',extension:errorlineErrorAnimation}),addDep({name:'errorlineLineAnimation',type:'animationRule',extension:errorlineLineAnimation});class ErrorLineDataset extends LINEDataset{getType(){return'dataset'}getName(){return'errorLine'}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=this,B=A.getFromEnv('chart'),C=A.config,D=B.config,E=C.parentYAxis,F=C.JSONData,G=F.data,H=B.getFromEnv('dataSource').chart,I=A.getFromEnv('xAxis'),J=I.getTicksLen(),K=A.components.data,L=A.getFromEnv('number-formatter'),M=C.linethickness,N=-Infinity,O=1/0,P=parseUnsafeString(H.yaxisname),Q=parseUnsafeString(H.xaxisname),R=pluck(H.tooltipsepchar,COMMASPACE),S=pluckNumber(H.seriesnameintooltip,1),T=function(b){var d;return D.showtooltip?null===h?d=!1:b===UNDEF?(S&&(w=getFirstValue(F&&F.seriesname)),d=w?w+R:BLANKSTRING,d+=c.label?c.label+R:BLANKSTRING):(u=[1,2,3,4,5,6,7,99,100,101,102],v={yaxisName:P,xaxisName:Q,formattedValue:c.toolTipValue,errorValue:g,errorDataValue:c.errorToolTipValue,errorPercentValue:c.errorPercentValue,errorPercentDataValue:c.errorPercentValue,label:c.label},d=parseTooltext(b,u,v,a,H,F)):d=!1,d};for(C.errorBarShadow=o=pluckNumber(H.errorbarshadow,H.showshadow,1),C.ignoreEmptyDatasets=pluckNumber(F.ignoreemptydatasets,0),C.notHalfErrorBar=!pluckNumber(H.halferrorbar,1),e=getFirstAlpha(pluck(F.errorbaralpha,H.errorbaralpha,C.alpha)),C.errorBarWidth=pluckNumber(F.errorbarwidth,H.errorbarwidth,5),C.errorBarColor=convertColor(getFirstColor(pluck(F.errorbarcolor,H.errorbarcolor,COLOR_AAAAAA)),e),f=pluckNumber(F.errorbarthickness,H.errorbarthickness,1),C.errorBarThickness=f>M?M:f,C.shadowOpacity=o?e/250:0,C.errorInPercent=x=pluckNumber(F.errorinpercent,H.errorinpercent),C.cumulativeValueOnErrorBar=pluckNumber(F.cumulativevalueonerrorbar,H.cumulativevalueonerrorbar,1),z=0;z<J;z++)(a=G&&G[z],G&&a)&&(b=K[z],c=b&&b.config,b||(b=K[z]={graphics:{}}),b.config||(c=K[z].config={}),r=c.setValue,c.notHalfErrorBar=C.notHalfErrorBar,g=L.getCleanValue(a.errorvalue),c.errorToolTipValue=L.dataLabels(g,E),c.setErrorValue=c.errorValue=s=g,c.hasErrorValue=pluckNumber(a.errorvalue)===UNDEF?0:1,d=c.errorToolTipValue,h=d,j=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,F.errorplottooltext,H.errorplottooltext,h))),y=T(j),c.errorInPercent=pluckNumber(a.errorinpercent,x,0),c.errorInPercent&&(c.setErrorValue=g=pluckNumber((g/100*r).toFixed(2))),c.cumulativeValueOnErrorBar=t=pluckNumber(a.cumulativevalueonerrorbar,C.cumulativeValueOnErrorBar,1),c.positiveErrorValue=L.getCleanValue(pluckNumber(a.positiveerrorvalue,a.errorvalue)),c.errorInPercent&&c.positiveErrorValue&&(c.positiveErrorValue=pluckNumber((c.positiveErrorValue/100*r).toFixed(2))),c.positiveCumulativeErrorValue=r+pluckNumber(c.positiveErrorValue,c.setErrorValue),c.negativeErrorValue=L.getCleanValue(pluckNumber(a.negativeerrorvalue,a.errorvalue)),c.errorInPercent&&c.negativeErrorValue&&(c.negativeErrorValue=pluckNumber((c.negativeErrorValue/100*r).toFixed(2))),c.negativeCumulativeErrorValue=r-pluckNumber(c.negativeErrorValue,c.setErrorValue),c.errorToolTipValue=L.dataLabels(g,E),c.negativeErrorToolTipValue=L.dataLabels(c.negativeErrorValue,E),c.negativeCumulativeErrorTooltipValue=L.dataLabels(c.negativeCumulativeErrorValue,E),c.positiveErrorToolTipValue=L.dataLabels(c.positiveErrorValue,E),c.positiveCumulativeErrorTooltipValue=L.dataLabels(c.positiveCumulativeErrorValue,E),c.errorPercentValue=mathRound(g/r*HUNDREDSTRING*HUNDREDSTRING)/HUNDREDSTRING+PERCENTAGESTRING,m=n=UNDEF,j=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,F.errorplottooltext,H.errorplottooltext,c.positiveErrorToolTipValue))),j&&c.positiveErrorToolTipValue&&(m=T(j)),j=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,F.errorplottooltext,H.errorplottooltext,c.negativeErrorToolTipValue))),j&&c.negativeErrorToolTipValue&&(n=T(j)),(a.positiveerrorvalue||a.negativeerrorvalue)&&(c.halfErrorBar=0,c.notHalfErrorBar=!0),t&&(j=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,F.errorplottooltext,H.errorplottooltext,c.positiveCumulativeErrorTooltipValue))),j&&c.positiveCumulativeErrorTooltipValue&&(k=T(j)),j=getValidValue(parseUnsafeString(pluck(a.errorplottooltext,F.errorplottooltext,H.errorplottooltext,c.negativeCumulativeErrorTooltipValue))),j&&c.negativeCumulativeErrorTooltipValue&&(l=T(j))),p=r+(null===c.positiveErrorValue?g:c.positiveErrorValue),q=r-(c.halfErrorBar?0:0>c.negativeErrorValue&&0>r?0:null===c.negativeErrorValue?g:c.negativeErrorValue),N=mathMax(N,p,q),O=mathMin(O,p,q),null===g&&(g=UNDEF),c.errorValueArr=[],null===c.positiveErrorValue&&(c.positiveErrorValue=UNDEF),s=-c.positiveErrorValue,c.errorValueArr.push({errorValue:s,tooltext:t?k:m||y,errorEdgeBar:!0}),c.errorValueArr.push({errorValue:s,tooltext:m||y}),c.notHalfErrorBar&&(s=c.negativeErrorValue,c.errorValueArr.push({errorValue:s,tooltext:t?l:n||y,errorEdgeBar:!0}),c.errorValueArr.push({errorValue:s,tooltext:n||y})),c.toolText=T(c.setTooltext));C.maxValue=N,C.minValue=O}_show(){var a=this,b=a.chart,c=a.yAxis,d=a.graphics&&a.graphics.container,e=a.graphics&&a.graphics.dataLabelContainer,f=a.graphics&&a.graphics.errorGroupContainer,g=a.graphics&&a.graphics.errorShadowContainer;b._chartAnimation(),d.lineGroup.show(),d.anchorGroup.show(),d.anchorShadowGroup.show(),d.lineShadowGroup.show(),e.show(),a.setState('visible',!0),f&&f.show(),g&&g.show(),a._conatinerHidden=!1,b._setAxisLimits(),c.draw(),b._drawDataset()}_hide(){var a=this,b=a.chart,c=a.yAxis;b._chartAnimation(),a.setState('visible',!1),b._setAxisLimits(),c.draw(),b._drawDataset()}draw(){super.draw(),this.drawErrorValue()}drawErrorValue(){var a,b,c,d,e,f,g,h,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D=this,E=D.config,F=D.getFromEnv('xAxis'),G=F.getTicksLen(),I=D.getState('visible'),J=D.getFromEnv('yAxis'),K=D.components.data,L=E.errorBarThickness,N=E.errorBarWidth,O=E.errorBarColor,P=E.shadowOpacity,Q=D.getContainer('errorPlotGroup'),R=D.getContainer('errorShadowGroup'),S=5<L?L/2:2.5,T=D.getFromEnv('animationManager'),U=function(a){return function(){'disappearing'===a&&this.hide()}};for(b=0;b<G;b++){if(l=K[b],n=l&&l.config,m=n&&n.setValue,l===UNDEF||m===UNDEF||null===m){if(l&&l.graphics.error)for(c=0;c<l.graphics.error.length;c++)l.graphics.error&&l.graphics.error[c]&&T.setAnimation({el:l.graphics.error[c]||'path',label:'path',component:D,doNotRemove:!0,callback:U('disappearing')}).shadow({opacity:0});continue}if(C=l.errorTrackerConfig={},C.errorTrackerArr=[],t=n.errorValueArr,C.errorLen=x=t.length,l.graphics.error||(l.graphics.error=[]),l.graphics.errorTracker||(l.graphics.errorTracker=[]),n.errorValue===BLANKSTRING||n.errorValue===UNDEF||null===n.errorValue&&null===n.positiveErrorValue&&null===n.negativeErrorValue){for(d=0;d<x;d++)l.graphics.error&&l.graphics.error[d]&&T.setAnimation({el:l.graphics.error[d]||'path',label:'path',component:D,callback:U('disappearing')}).shadow({opacity:0});continue}for(f=n.setLink,A=l._xPos,B=l._yPos,h=B,g=A,l.errorBar&&delete l.errorBar,l.errorBar=[];x--;){if(z=null,C.errorTrackerArr[x]={},u=t[x],C.errorTrackerArr[x].tooltext=u.tooltext,w=h,v=u.errorValue,null===v||isNaN(v)){l.graphics.error&&l.graphics.error[x]&&(l.graphics.error[x].hide(),l.graphics.error[x].shadow({opacity:0}));continue}y=N/2,s=I?1:0,r=B+(J.getPixel(0)-J.getPixel(1))*v*s,o=r,p=g,o=mathRound(r)+L%2/2,p=mathRound(g)+L%2/2,l.errorBar[x]||(l.errorBar[x]=[]),u.errorEdgeBar?(q=[M,p-y,o,H,p+y],l.errorBar[x][1]={_xPos:p-y-S,_yPos:o-S,_height:2*S,_width:2*(y+S),_toolText:u.tooltext}):(q=[M,p,w,V,o],l.errorBar[x][0]={_xPos:p-S,_yPos:o<w?o:w,_height:mathAbs(w-o),_width:2*S,_toolText:u.tooltext}),a={path:q,stroke:O,"stroke-width":L,cursor:f?POINTER:BLANKSTRING,"stroke-linecap":ROUND},e=!l.graphics.error[x]&&I?'appearing':I?'updating':'disappearing',z=l.graphics.error[x]=T.setAnimation({el:l.graphics.error[x]||'path',state:e,attr:a,label:'path',component:D,container:Q,callback:U(e)}),'disappearing'!==e&&z.show(),z&&z.shadow({opacity:P},R),C.errorTrackerArr[x].attr={path:q,stroke:TRACKER_FILL,"stroke-width":L<HTP?HTP:L,cursor:f?POINTER:BLANKSTRING}}if(!n.notHalfErrorBar)for(d=2;4>d;d++)l.graphics.error&&l.graphics.error[d]&&T.setAnimation({el:l.graphics.error[d]||'path',label:'path',component:D,doNotRemove:!0,callback:U('disappearing')}).shadow({opacity:0})}}_firePlotEvent(a,b,c){_firePlotEvent.call(this,a,b,c)}_checkPointerOverErrorBar(a,b,c){return _checkPointerOverErrorBar.call(this,a,b,c)}_checkPointerOverPlot(a,b,c){var d,e=this,f=e.components.data,g=f[a],h=g&&g.config;if(g)return d=e.isWithinShape(g,a,b,c),d?(g.errorBarHovered=!1,h.finalTooltext=!1!==h.toolText&&h.toolText):(d=e._checkPointerOverErrorBar(a,b,c),d&&(g.errorBarHovered=!0,h.finalTooltext=d.toolText)),d}_getHoveredPlot(a,b){return _getHoveredPlot.call(this,a,b)}getCanvasPadding(){var a,b,c,d,e,f,g=this,h=g.config,i=.5*h.errorBarWidth,j=g.components||{},k=g.getFromEnv('chart'),l=k.config.dataLabelStyle,m=j.data||[],n=m[0],o=m[m.length-1],p={},q=k.getFromEnv('smartLabel'),r={paddingLeft:0,paddingRight:0};return n&&(a=n.config,f=a.showValue,c=a&&a.anchorProps||{},f&&(b=a.displayValue,q.useEllipsesOnOverflow(k.config.useEllipsesWhenOverflow),q.setStyle(l),p=q.getOriSize(b)),a.setValue&&(d=mathMax(pluckNumber(c.radius,0),i)+pluckNumber(c.borderThickness,0),e=(p.width||0)/2),r.paddingLeft=mathMax(d,e)),o&&(a=o.config,f=a.showValue,c=a&&a.anchorProps||{},f&&(b=a.displayValue,q.setStyle(l),p=q.getOriSize(b)),a.setValue&&(d=mathMax(pluckNumber(c.radius,0),i)+pluckNumber(c.borderThickness,0),e=(p.width||0)/2),r.paddingRight=mathMax(d,e)),r}removePlots(){removePlots.call(this)}}export default ErrorLineDataset;