UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 8.41 kB
import{BLANKSTRING,pluck,pluckNumber,POSITION_START,parseTooltext,POSITION_END,getLightColor,parseColor}from'../../../../fc-core/src/lib';import LineDataset from'../../../../fc-charts/src/dataset/line';import{addDep}from'../../../../fc-core/src/dependency-manager';import sparklineAnimation from'./index.animation';var UNDEF,GUTTER_PADDING=2,defined=function(a){return a!==UNDEF&&null!==a},drawSparkValues=function(){var a,b,c,d,e,f,g,h=this,i=h.getFromEnv('chart'),j=i.config,k=j.dataLabelStyle,l=j.valuepadding+GUTTER_PADDING,m=h.getContainer('labelGroup'),n=h.getFromEnv('animationManager'),o=h.getGraphicalElement('closeValue'),p=h.getGraphicalElement('openValue'),q=h.getGraphicalElement('startBraces'),r=h.getGraphicalElement('highValue'),s=h.getGraphicalElement('separator'),t=h.getGraphicalElement('lowValue'),u=h.getGraphicalElement('endBraces'),v=j.sparkValues||(j.sparkValues={}),w=h.getFromEnv('smartLabel'),x='[',y=']',z='|',A={class:'fusioncharts-label',"text-anchor":POSITION_END,fill:k.color,"font-size":k.fontSize,"font-weight":k.fontWeight,"font-style":k.fontStyle,"font-family":k.fontFamily,visibility:'visible'},B={x:0,y:0};i.getChildContainer('datalabelsGroup').attr({"clip-rect":null}),B.y=.5*j.canvasHeight+j.canvasTop,B.x=j.canvasLeft-l,(v.openValue&&v.openValue.label||b)&&(b=n.setAnimation({el:p||'text',state:'appearing',container:m,attr:{text:v.openValue.label,x:B.x,y:B.y,fill:v.openValue.color||A.fill,"text-anchor":POSITION_END,"line-height":k.lineHeight,"text-bound":[k.backgroundColor,k.borderColor,k.borderThickness,k.borderPadding,k.borderRadius,k.borderDash],visibility:'visible'},label:'label',component:h}),!p&&h.addGraphicalElement('openValue',b)),A['text-anchor']=POSITION_START,B.x=j.canvasWidth+j.canvasLeft+l,(v.closeValue&&v.closeValue.label||a)&&(a=n.setAnimation({el:o||'text',container:m,state:'appearing',attr:{text:v.closeValue.label,x:B.x,y:B.y,fill:v.closeValue.color||A.fill,"text-anchor":POSITION_START,"line-height":k.lineHeight,"text-bound":[k.backgroundColor,k.borderColor,k.borderThickness,k.borderPadding,k.borderRadius,k.borderDash],visibility:'visible'},label:'label',component:h}),!o&&h.addGraphicalElement('closeValue',a),B.x+=v.closeValue.smartObj&&v.closeValue.smartObj.width+GUTTER_PADDING+l||0),(v.highLowValue&&v.highLowValue.label||d)&&(v.highLowValue&&v.highLowValue.label===BLANKSTRING&&(z=x=y=BLANKSTRING),w.useEllipsesOnOverflow(j.useEllipsesWhenOverflow),w.setStyle(k),c=n.setAnimation({el:q||'text',state:'appearing',container:m,attr:{text:x,x:B.x,y:B.y,"text-anchor":POSITION_START,visibility:'visible'},label:'label',component:h}),!q&&h.addGraphicalElement('startBraces',c),B.x+=w.getSmartText(x).width,d=n.setAnimation({el:r||'text',state:'appearing',container:m,attr:{text:v.highValue.label,x:B.x,y:B.y,"text-anchor":POSITION_START,fill:v.highValue.color||A.fill,visibility:'visible'},label:'label',component:h}),!r&&h.addGraphicalElement('highValue',d),B.x+=w.getSmartText(v.highValue.label).width,e=n.setAnimation({el:s||'text',state:'appearing',container:m,attr:{text:z,x:B.x,y:B.y,"text-anchor":POSITION_START,visibility:'visible'},label:'label',component:h}),!s&&h.addGraphicalElement('separator',e),B.x+=w.getSmartText(z).width,f=n.setAnimation({el:t||'text',container:m,state:'appearing',attr:{text:v.lowValue.label,x:B.x,y:B.y,"text-anchor":POSITION_START,fill:v.lowValue.color||A.fill,visibility:'visible'},label:'label',component:h}),!t&&h.addGraphicalElement('lowValue',f),B.x+=w.getSmartText(v.lowValue.label).width,g=n.setAnimation({el:u||'text',state:'appearing',container:m,attr:{text:y,x:B.x,y:B.y,"text-anchor":POSITION_START,visibility:'visible'},label:'label',component:h}),!u&&h.addGraphicalElement('endBraces',g)),h.labelDrawn=!0};addDep({name:'sparklineAnimation',type:'animationRule',extension:sparklineAnimation});class SparkLineDataset extends LineDataset{getType(){return'dataset'}getName(){return'sparkLine'}parseAttributes(){super.parseAttributes();var a=this,b=a.getFromEnv('chart'),c=a.config,d=a.config.JSONData,e=b.getFromEnv('chart-attrib');c.showValues=pluckNumber(d.showvalues,e.showvalues,0),c.linethickness=pluckNumber(d.linethickness,e.linethickness,1)}_setConfigure(a){super._setConfigure();var b,c,d,e,f,g,h,j,k,l,m,n,o,p,q,r,s=this,t=s.getFromEnv('chart'),u=s.config,v=s.config.JSONData,w=t.getFromEnv('dataSource').chart,x=a||v.data,y=s.getFromEnv('xAxis'),z=a&&a.data.length||y.getTicksLen(),A=s.getFromEnv('color-manager'),B=t.config,C=parseColor(pluck(w.opencolor,'0099FF')),D=parseColor(pluck(w.closecolor,'0099FF')),E=parseColor(pluck(w.highcolor,'00CC00')),F=parseColor(pluck(w.lowcolor,'CC0000')),G=parseColor(pluck(w.anchorcolor,A.getColor('plotFillColor'))),H=pluckNumber(w.showopenanchor,w.drawanchors,w.showanchors,1),I=pluckNumber(w.showcloseanchor,w.drawanchors,w.showanchors,1),J=pluckNumber(w.showhighanchor,w.drawanchors,w.showanchors,1),K=pluckNumber(w.showlowanchor,w.drawanchors,w.showanchors,1),L=pluckNumber(w.anchoralpha,100),M=pluckNumber(w.drawanchors,w.showanchors,0),N=M?pluckNumber(w.anchoralpha,100):0,O=pluck(w.linecolor,A.getColor('plotFillColor'));for(d=s.components.data,j=u.maxValue,k=u.minValue,u.shadow={opacity:pluckNumber(w.showshadow,0)?u.alpha/100:0},c=d[0],e=c.config,e.anchorProps.bgColor=pluck(c.anchorbgcolor,C),e.anchorProps.enabled=!!H,e.anchorProps.bgAlpha=H?l:0,e.anchorProps.enabled&&e.hoverEffects&&(e.hoverEffects.anchorColor=pluck(w.openhovercolor,w.anchorhovercolor,w.plotfillhovercolor,getLightColor(C,70)),e.hoverEffects.anchorBgAlpha=pluckNumber(w.openhoveralpha,w.anchorhoveralpha,w.plotfillhoveralpha,100)),o=e.displayValue,c=d[z-1],e=c.config,e.anchorProps.bgColor=pluck(c.anchorbgcolor,D),e.anchorProps.enabled=!!I,e.anchorProps.bgAlpha=I?l:0,e.anchorProps.enabled&&e.hoverEffects&&(e.hoverEffects.anchorColor=pluck(w.closehovercolor,w.anchorhovercolor,w.plotfillhovercolor,getLightColor(D,70)),e.hoverEffects.anchorBgAlpha=pluckNumber(w.closehoveralpha,w.anchorhoveralpha,w.plotfillhoveralpha,100)),r=e.displayValue,f=0;f<z;f++)c=d[f],e=c.config,b=x[f],l=pluckNumber(b.anchorbgalpha,L),u.maxRadius=-Infinity,0!==f&&f!==z-1&&(e.anchorProps.bgColor=pluck(b.anchorbgcolor,G),e.anchorProps.bgAlpha=pluckNumber(b.anchorbgalpha,N),e.hoverEffects.anchorColor=parseColor(pluck(w.anchorhovercolor,w.plotfillhovercolor,getLightColor(O,70))),e.hoverEffects.anchorBgAlpha=pluckNumber(w.lowhoveralpha,w.anchorhoveralpha,w.plotfillhoveralpha,100)),e.anchorProps.radius=pluckNumber(w.anchorradius,b.anchorradius,2),e.anchorProps.borderThickness=0,e.hoverEffects.anchorBorderThickness=0,e.hoverEffects.anchorRadius=pluckNumber(w.anchorhoverradius,w.anchorradius,b.anchorradius,3),u.maxRadius=Math.max(e.anchorProps.radius+e.anchorProps.borderThickness/2,u.maxRadius),e.setValue===k&&(e.anchorProps.bgColor=pluck(b.anchorbgcolor,F),e.hoverEffects.anchorColor=pluck(w.lowhovercolor,w.anchorhovercolor,w.plotfillhovercolor,getLightColor(F,70)),e.hoverEffects.anchorBgAlpha=pluckNumber(w.lowhoveralpha,w.anchorhoveralpha,w.plotfillhoveralpha,100),e.anchorProps.enabled=!!K,e.anchorProps.bgAlpha=K?l:0,n=e.displayValue),e.setValue===j&&(e.anchorProps.bgColor=pluck(b.anchorbgcolor,E),e.hoverEffects.anchorColor=pluck(w.highhovercolor,w.anchorhovercolor,w.plotfillhovercolor,getLightColor(E,70)),e.hoverEffects.anchorBgAlpha=pluckNumber(w.highhoveralpha,w.anchorhoveralpha,w.plotfillhoveralpha,100),e.anchorProps.enabled=!!J,e.anchorProps.bgAlpha=J?l:0,m=e.displayValue),defined(e.setValue)&&(h=1),e._x=f,e._y=e.setValue;for(g=B.sparkValues={openValue:{color:C},closeValue:{color:D},highValue:{color:E},lowValue:{color:F},highLowValue:{}},h&&(g.openValue.label=pluckNumber(w.showopenvalue,1)?o:BLANKSTRING,g.closeValue.label=pluckNumber(w.showclosevalue,1)?r:BLANKSTRING,pluckNumber(w.showhighlowvalue,1)&&(g.highLowValue.label='['+m+' | '+n+']',g.highValue.label=m,g.lowValue.label=n)),f=0;f<z;f++){let a=d[f],c=a.config;c.setTooltext!==UNDEF&&(p=[54,55,56,57,58,59,60,61],q={openValue:g.openValue.label,openDataValue:g.openValue.label,closeValue:g.closeValue.label,closeDataValue:g.closeValue.label,highValue:g.highValue.label,highDataValue:g.highValue.label,lowValue:g.lowValue.label,lowDataValue:g.lowValue.label},c.toolText=parseTooltext(c.setTooltext,p,q,b,w,v),c.finalTooltext=c.setTooltext=c.toolText)}}draw(){var a=this;super.draw(),a._drawSparkValues()}_drawSparkValues(){var a=this;drawSparkValues.call(a)}}export default SparkLineDataset;