quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 9.44 kB
JavaScript
import{pluckNumber,pluck,COMMASTRING,COMMASPACE,BLANK,extend2,toRaphaelColor,getValidValue,preDefStr,parseConfiguration,parseUnsafeString,parseTooltext,convertColor,getDarkColor,getLightColor}from'../../../../fc-core/src/lib';import{ComponentInterface}from'../../../../fc-core/src/component-interface';import{addDep}from'../../../../fc-core/src/dependency-manager';import bulbAnimation from'./index.animation';var UNDEF,BLANKSTRING=BLANK,POSITION_TOP=preDefStr.POSITION_TOP,POSITION_MIDDLE=preDefStr.POSITION_MIDDLE,showHoverEffectStr=preDefStr.showHoverEffectStr,visibleStr=preDefStr.visibleStr,ROUND=preDefStr.ROUND,ROLLOVER='DataPlotRollOver',ROLLOUT='DataPlotRollOut',FILLMIXDARK10='{dark-10}',EVENTARGS='eventArgs',SETROLLOVERATTR='setRolloverAttr',SETROLLOUTATTR='setRolloutAttr',POINTER='pointer',math=Math,mathMin=math.min,win=window,userAgent=win.navigator.userAgent,isIE=/msie/i.test(userAgent)&&!win.opera,TRACKER_FILL='rgba(192,192,192,'+(isIE?.002:1e-6)+')',createGroup=function(a,b,c){var d=c.getFromEnv('animationManager');return d.setAnimation({el:'group',attr:{name:a},container:b,component:c,label:'group'})};addDep({name:'bulbAnimation',type:'animationRule',extension:bulbAnimation});class BulbDataset extends ComponentInterface{constructor(){super(),this.addData=function(){},this.removeData=function(){},this.components={}}getType(){return'dataset'}getName(){return'bulb'}_manageSpace(a){var b,c,d,e=this,f=e.config,g=e.components.data,h=e.getFromEnv('chart'),i=h.config,j=e.getFromEnv('smartLabel'),k=i.dataLabelStyle,l=pluckNumber(parseInt(k.lineHeight,10),12),m=a,n=i.valuepadding,o=0;return b=g[0],d=b&&b.config,j.useEllipsesOnOverflow(i.useEllipsesWhenOverflow),j.setStyle(k),d&&d.displayValue!==BLANKSTRING&&!i.placevaluesinside&&f.showValue&&(c=j.getOriSize(d.displayValue),d.displayValue===BLANK&&(c={height:l}),0<c.height&&(o=c.height+n),o>m&&(o=m)),f.heightUsed=o,{top:0,bottom:o}}configureAttributes(a){if(!a)return!1;this.config.JSONData=a;var b,c=this,d=c.config.JSONData,e=extend2({},d),f=c.getFromEnv('chart'),g=c.config,h=f.config,i=f.getFromEnv('dataSource').chart;parseConfiguration(e,g,f.config,{data:!0}),g.origW=pluckNumber(i.origw,h.autoscale?f.config.origRenderWidth:h.width||f.config.origRenderWidth),g.origH=pluckNumber(i.origh,h.autoscale?f.config.origRenderHeight:h.height||f.config.origRenderHeight),g.setToolText=getValidValue(parseUnsafeString(pluck(i.plottooltext,UNDEF))),g.useColorNameAsValue=pluckNumber(i.usecolornameasvalue,0),g.enableAnimation=b=pluckNumber(i.animation,i.defaultanimation,1),g.animation=!!b&&{duration:1e3*pluckNumber(i.animationduration,1)},g.showValue=pluckNumber(i.showvalue,1),c._setConfigure()}_setConfigure(a){var 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,I=this,J=I.getFromEnv('chart'),K=I.config,L=J.config,M=I.config.JSONData,N=a||M.data,O=N&&N.length,P=a&&a.data.length||O,Q=J.getFromEnv('dataSource'),R=Q.chart,S=I.getFromEnv('color-manager'),T=pluckNumber(R.showtooltip,1),U=parseUnsafeString(pluck(R.tooltipsepchar,COMMASPACE)),V=L.showhovereffect,W=I.components.data,X=pluckNumber(R.is3d,1),Y=I.getFromEnv('number-formatter'),Z=function(a,b,c){return c?{FCcolor:{cx:.4,cy:.4,r:'80%',color:getLightColor(a,65)+COMMASTRING+getLightColor(a,75)+COMMASTRING+getDarkColor(a,65),alpha:b+COMMASTRING+b+COMMASTRING+b,ratio:'0,30,70',radialGradient:!0}}:convertColor(a,b)};for(W||(W=I.components.data=[]),k=0;k<P;k++)d=a?a&&a.data[k]:N[k],f=W[k],g=f&&f.config,f||(f=W[k]={}),f.config||(g=W[k].config={}),g.setValue=e=Y.getCleanValue(d.value)||0,b=Y.dataLabels(e),j=getValidValue(parseUnsafeString(d.displayvalue)),g.colorRangeGetter=l=I.getFromEnv('colorRange'),m=l.getColorObj(g.setValue),l.colorArr.length||(m=l.config.defaultObj),n=pluckNumber(R.gaugefillalpha,m.alpha,100),o=parseUnsafeString(pluck(m.label,m.name)),p=pluck(m.bordercolor,R.gaugebordercolor,getDarkColor(m.code,70),'000000'),q=pluckNumber(m.borderalpha,R.gaugeborderalpha,'90')*n/100,r=/\{/.test(p),p=r?S.parseColorMix(pluck(m.bordercolor,m.code),p)[0]:p,g.gaugeBorderColor=t=convertColor(p,q),g.gaugeBorderThickness=u=L.showgaugeborder?pluckNumber(R.gaugeborderthickness,1):0,g.fillColor=s=Z(m.code,n,X),0!==V&&(V||R.gaugefillhovercolor||R.plotfillhovercolor||R.gaugefillhoveralpha||R.plotfillhoveralpha||0===R.gaugefillhoveralpha||R.is3donhover||0===R.is3donhover||R.showgaugeborderonhover||0===R.showgaugeborderonhover||R.gaugeborderhovercolor||R.gaugeborderhoveralpha||0===R.gaugeborderhoveralpha||R.gaugeborderhoverthickness||0===R.gaugeborderhoverthickness)&&(V=!0,v=pluck(R.gaugefillhovercolor,R.plotfillhovercolor,FILLMIXDARK10),w=pluckNumber(R.gaugefillhoveralpha,R.plotfillhoveralpha),x=pluckNumber(R.showgaugeborderonhover),x===UNDEF&&(R.gaugeborderhovercolor||R.gaugeborderhoveralpha||0===R.gaugeborderhoveralpha||R.gaugeborderhoverthickness||0===R.gaugeborderhoverthickness?x=1:x=L.showgaugeborder),y=pluck(R.gaugeborderhovercolor,FILLMIXDARK10),z=pluckNumber(R.gaugeborderhoveralpha),A=x?pluckNumber(R.gaugeborderhoverthickness,u||1):0,B=!!pluckNumber(R.is3donhover,X),F={},H={},u!==A&&(F['stroke-width']=A,H['stroke-width']=u),H.fill=toRaphaelColor(s),C=/\{/.test(v),v=C?S.parseColorMix(m.code,v)[0]:pluck(v,m.code),F.fill=toRaphaelColor(Z(v,pluckNumber(w,n),B)),A&&(H.stroke=t,D=/\{/.test(y),F.stroke=convertColor(D?S.parseColorMix(r?v:p,y)[0]:y,pluckNumber(z,q)))),g.setTooltext=getValidValue(parseUnsafeString(pluck(d.tooltext,M.plottooltext,R.plottooltext))),c=!!T&&(g.setTooltext===UNDEF?K.useColorNameAsValue?o:null!==b&&(h==UNDEF?b:h+U+b):parseTooltext(g.setTooltext,[1,2],{formattedValue:b},d,R)),E=j===UNDEF?d.label||(K.useColorNameAsValue?o:b):j,g.toolText=c,g.displayValue=E,g.rolloverProperties={enabled:V,hoverAttr:F,hoverAnimAttr:G,outAttr:H}}updateData(a,b,c){var d=this;d._setConfigure(a,b),c&&d.asynDraw()}draw(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.components.data,s=q.getFromEnv('chart'),t=q.getFromEnv('toolTipController'),u=q.config,v=s.config,w=v.canvasLeft,x=v.canvasTop,y=v.canvasHeight,z=v.canvasWidth,A=s.getChildContainer().plotGroup,B=q.getContainer('container'),C=q.getContainer('trackerContainer'),D=s.getChildContainer('trackerGroup'),E=r[0],F=E&&E.config,G=v.gaugeoriginx,H=v.gaugeoriginy,I=v.gaugeradius,J=v.hasgaugeoriginx,K=v.hasgaugeoriginy,L=v.hasgaugeradius,M=q.getFromEnv('smartLabel'),N=q.getFromEnv('animationManager'),O=q.getContainer('dataLabelContainer'),P=s.config.dataLabelStyle,Q=s.getChildContainer('datalabelsGroup');M.setStyle(P),B||(B=q.addContainer('container',createGroup('bulb',A,q))),C||(C=q.addContainer('trackerContainer',createGroup('bulb-hot',D,q))),O||(O=q.addContainer('dataLabelContainer',N.setAnimation({el:'group',attr:{name:'datalabel'},label:'labelGroup',component:q}))),Q&&Q.appendChild(O),p=E.trackerConfig={},a=F.setValue,c=F.toolText,p.eventArgs={value:a,displayValue:F.displayValue,toolText:c?c:''},E.graphics||(E.graphics={}),G=J===UNDEF?w+z/2:G*u.scaleFactor,H=K===UNDEF?x+y/2:H*u.scaleFactor,f=G,g=H,h=L===UNDEF?mathMin(z/2,y/2):I*u.scaleFactor,b={cx:f,cy:g,r:h,"stroke-linecap":ROUND,stroke:toRaphaelColor(F.gaugeBorderColor),"stroke-width":F.gaugeBorderThickness,fill:toRaphaelColor(F.fillColor)},j=E.graphics.element,i=N.setAnimation({el:j||'circle',attr:b,container:B,component:q,animType:'easeOut',label:'circle'}),j||(E.graphics.element=i),p.attr={cx:f,cy:g,r:h,cursor:F.setLink?POINTER:BLANK,stroke:TRACKER_FILL,"stroke-width":F.plotBorderThickness,fill:TRACKER_FILL,visibility:visibleStr},k=E.graphics,m=k.label,v.placevaluesinside?(n=g,o=POSITION_MIDDLE):(n=g+h+v.valuepadding,o=POSITION_TOP),F.setValue!==BLANKSTRING&&u.showValue&&(e=M.getSmartText(F.displayValue,v.width-v.chartleftmargin-v.chartrightmargin,+v.height-n-v.chartbottommargin),d=e.tooltext||BLANKSTRING,b={text:e.text,"text-anchor":POSITION_MIDDLE,x:G,y:n,"vertical-align":o,fill:P.color,direction:F.textDirection,"text-bound":[P.backgroundColor,P.borderColor,P.borderThickness,P.borderPadding,P.borderRadius,P.borderDash]},k.label&&k.label.show(),l=N.setAnimation({el:m||'text',animType:'easeOut',attr:b,label:'text',container:O,component:q}),!m&&(k.label=l),v.showToolTip?t.enableToolTip(l,d):t.disableToolTip(l)),q.drawTracker()}drawTracker(){var a,b,c,d,e,f,g,h=this,i=h.getFromEnv('chart'),j=h.getFromEnv('animationManager'),k=h.getFromEnv('toolTipController'),l=h.components,m=l.data,n=i.config,o=n.plothovereffect,p=h.getContainer('trackerContainer'),q=!1;c=m[0],b=c&&c.config,a=c.trackerConfig,d=c.graphics.element,g=a.attr,f=c.graphics.hotElement,g&&(e=j.setAnimation({el:f||'circle',attr:g,container:p,component:h,label:'tracker'}),!f&&(c.graphics.hotElement=e,q=!0),(e||d).data(EVENTARGS,a.eventArgs).data(showHoverEffectStr,o).data(SETROLLOVERATTR,b.rolloverProperties.hoverAttr||{}).data(SETROLLOUTATTR,b.rolloverProperties.outAttr||{}),k.enableToolTip(e||d,a.eventArgs.toolText),(q||b.elemCreated)&&(e||d).on('fc-click',function(a){var b=this;i.plotEventHandler(b,a)}).hover(function(a){return function(b){var c=this,d=c.getData(),e=d.setRolloverAttr;0!==d.showHoverEffect&&!0!==d.draged&&(e.fill&&(j.setAnimationState('mouseover'),j.setAnimation({el:a,attr:e,component:h})),i.plotEventHandler(c,b,ROLLOVER))}}(d),function(a){return function(b){var c=this,d=c.getData(),e=d.setRolloutAttr;0!==d.showHoverEffect&&!0!==d.draged&&(e.fill&&(j.setAnimationState('mouseout'),j.setAnimation({el:a,attr:e,component:h})),i.plotEventHandler(c,b,ROLLOUT))}}(d)))}}export default BulbDataset;