UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 12.6 kB
import Pie2DDataset from'../../../../fc-charts/src/dataset/pie2d';import{COMMASPACE,ZEROSTRING,pluck,pluckNumber,toRaphaelColor,parseUnsafeString,getDashStyle,getValidValue,parseTooltext,getFirstValue,convertColor,BLANKSTRING,extend2}from'../../../../fc-core/src/lib';import{addDep,getDep}from'../../../../fc-core/src/dependency-manager';import multilevelpieAnimation from'./index.animation';import{priorityList}from'../../../../fc-core/src/schedular';import raphaelShapesRingpath from'../../../../fc-core/src/_internal/redraphael/redraphael-shapes/redraphael-shapes.ringpath';let UNDEF,Raphael=getDep('redraphael','plugin'),BLANK='',NORMALSTRING='normal',COLOR_FFFFFF='FFFFFF',COLOR_000000='000000',pInt=function(a,b){return parseInt(a,b||10)},DASH_DEF='none',ROLLOVER='DataPlotRollOver',ROLLOUT='DataPlotRollOut',POINTER='pointer',EVENTARGS='eventArgs',PX='px',INNERRADIUS=/^[0-9]+\%?$|^([0-9]+[.][0-9]+)\%?$/,calculateInnerRadius=function(a,b){let c,d=a&&a.length;return a?(c='%'===a.charAt(d-1)?pluckNumber(b)*(pluckNumber(a.split('%')[0])/100):pluckNumber(a),c<b?c:0):0};addDep({name:'multilevelpieAnimation',type:'animationRule',extension:multilevelpieAnimation}),raphaelShapesRingpath(Raphael);class MultiLevelPieDataset extends Pie2DDataset{constructor(){super(),this.components={data:[]},this.graphics={}}getType(){return'dataset'}getName(){return'multiLevelPie'}configureAttributes(a){var b=Math.PI;if(!a)return!1;this.config.JSONData=a;var c,d=this,e=d.getFromEnv('chart'),f=e.config,g=d.config||(d.config={}),h=g.dataLabelOptions||(g.dataLabelOptions={}),i=g.piePlotOptions,j=e.config.style,k=d.config.JSONData,l=e.getFromEnv('dataSource').chart,m=g.enableAnimation=pluckNumber(l.animation,l.defaultanimation,1),n=pluckNumber(-l.centerangle,180),o=pluckNumber(l.totalangle,360),p=function(a,b){for(var c=this.data('plotItem');a.graphics.element;)a.graphics.element.attr({fill:'mouseover'===b?g.hoverFillColor:(a.config||c).color}),a=a.config.parent},q=function(a,b){var c,d=this.data('plotItem');for(a.graphics.element.attr({fill:'mouseover'===b?g.hoverFillColor:(a.config||d).color}),c=0;c<(a.components.data&&a.components.data.length);c++)q.call(this,a.components.data[c],b)},r=function(a){if(g.useHoverColor){var b=this.data('plotItem'),c=b.selfRef;g.highlightParentPieSlices||g.highlightChildPieSlices?!g.highlightParentPieSlices&&g.highlightChildPieSlices?q.call(this,c,a):g.highlightParentPieSlices&&!g.highlightChildPieSlices?p.call(this,c,a):g.highlightParentPieSlices&&g.highlightChildPieSlices&&(p.call(this,c,a),q.call(this,c,a)):c.graphics.element.attr({fill:'mouseover'===a?g.hoverFillColor:(c.config||b).color})}};g.animation=!!m&&{duration:1e3*pluckNumber(l.animationduration,l.moveduration,1)},g.showShadow=pluckNumber(l.showshadow,0),g.useHoverColor=!!pluckNumber(l.usehovercolor,1),g.hoverFillColor=convertColor(pluck(l.hoverfillcolor,'FF5904'),pluckNumber(l.hoverfillalpha,100)),c=getFirstValue(l.valuebordercolor,BLANK),c=c?convertColor(c,pluckNumber(l.valueborderalpha,l.valuebgalpha,l.valuealpha,100)):BLANK,h.style||(h.style={fontFamily:pluck(l.valuefont,j.fontFamily),fontSize:pluckNumber(l.valuefontsize,pInt(j.fontSize,10))+PX,color:convertColor(pluck(l.valuefontcolor,j.color),pluckNumber(l.valuefontalpha,l.valuealpha,100)),fontWeight:pluckNumber(l.valuefontbold)?'bold':NORMALSTRING,fontStyle:pluckNumber(l.valuefontitalic)?'italic':NORMALSTRING,backgroundColor:l.valuebgcolor?convertColor(l.valuebgcolor,pluckNumber(l.valuebgalpha,l.valuealpha,100)):BLANK,border:c||l.valuebgcolor?pluckNumber(l.valueborderthickness,1)+'px solid':BLANK,borderPadding:pluckNumber(l.valueborderpadding,2),borderThickness:pluckNumber(l.valueborderthickness,j.borderThickness,1),borderRadius:pluckNumber(l.valueborderradius,j.borderRadius,0),borderColor:c,borderDash:pluckNumber(l.valueborderdashed,0)?getDashStyle(pluckNumber(l.valueborderdashlen,4),pluckNumber(l.valueborderdashgap,2)):DASH_DEF}),i||(i=g.piePlotOptions={}),i.allowPointSelect=!1,g.borderColor=convertColor(pluck(l.plotbordercolor,l.piebordercolor,COLOR_FFFFFF),l.showplotborder==ZEROSTRING?0:pluck(l.plotborderalpha,l.pieborderalpha,100)),g.showTooltip=pluckNumber(l.showtooltip,1),g.borderWidth=pluckNumber(l.pieborderthickness,l.plotborderthickness,1),i.startingAngle=0,i.size='100%',g.highlightParentPieSlices=pluckNumber(l.highlightparentpieslices,l.highlightparentpienodes,1),g.highlightChildPieSlices=pluckNumber(l.highlightchildpieslices,l.highlightchildpienodes,0),g.showLabels=pluckNumber(l.showlabels,1),g.showValues=pluckNumber(l.showvalues,0),g.showValuesInTooltip=pluckNumber(l.showvaluesintooltip,l.showvalues,0),g.showPercentValues=pluckNumber(l.showpercentvalues,l.showpercentagevalues,0),g.showPercentInTooltip=pluckNumber(l.showpercentintooltip,0),g.toolTipSepChar=pluck(l.tooltipsepchar,l.hovercapsepchar,COMMASPACE),g.labelSepChar=pluck(l.labelsepchar,g.toolTipSepChar),g.tooltext=l.plottooltext,g.alpha=pluck(l.plotfillalpha,l.piefillalpha,100),g.startAngle=(n-o/2)*(b/180),g.endtAngle=(n+o/2)*(b/180),g.initialAngle=g.endtAngle,g.originX=pluckNumber(l.originx),g.originY=pluckNumber(l.originy),g.events={mouseOver:function(){r.call(this,'mouseover')},mouseOut:function(){r.call(this,'mouseout')}},f.plotBorderWidth=0,f.plotBorderWidth=0,g.maxLevel=d.addMSPieCat(k,1,d,g.startAngle,g.endtAngle),g.pieRadius=parseInt(l.pieradius,10),g.innerRadius='0',INNERRADIUS.test(l.innerradius)&&(g.innerRadius=pluck(l.innerradius)),h.distance=0,h.placeLabelsInside=!0}removalFn(a,b){var c=this,d=c.getFromEnv('animationManager');d.setAnimation({el:a,label:'element'===b?'ringpath':'label',component:c,callback:function(){this.remove()}})}removeGraphics(a){var b,c,d,e=this,f=a.components&&a.components.data,g=a.graphics;if(f)for(d=f.length,b=0;b<d;b+=1)e.removeGraphics(f[b]);if(a.graphics)for(c in g)g.hasOwnProperty(c)&&e.removalFn(a.graphics[c],c)}removeChild(a,b,c){var d,e,f=this;if(a.length)for(d=0;d<a.length;d+=1)e=a[d],c?f.removalFn(e,b,c):f.removeGraphics(e,b);else for(d in a)f.removeChild(a[d],b,d)}addMSPieCat(a,b,c,d,e){var f,g,h,j,k,l,m,n,o,p,q,r,s,t,u,v=extend2([],a),w=v.length,x=this,y=c.components.data,z=x.config,A=z.borderWidth,B=z.borderColor,C=x.getFromEnv('number-formatter'),D=x.getFromEnv('color-manager'),E=0,F=z.labelSepChar,G=b,H=y.length,I=function(){x.removeChild.apply(x,arguments)},J=v.length,K=0;for(m=0;m<w;m+=1)k=v[m],k._userValue=C.getCleanValue(k.value,!0),k._value=pluckNumber(k._userValue,1),E+=k._value;for(E=E||1,j=(e-d)/E,m=w-1;0<=m;m-=1)k=v[m],l=j*k._value,n=parseUnsafeString(pluck(k.label,k.name)),p=null===k._userValue?BLANK:C.dataLabels(k._userValue),q=C.percentValue(100*(k._value/E)),o=pluckNumber(k.alpha,z.alpha),s=1===pluckNumber(k.showlabel,z.showLabels)?n:BLANK,1===pluckNumber(k.showvalue,z.showValues)&&(z.showPercentValues?s+=s===BLANK?q:F+q:p!==UNDEF&&p!==BLANK&&(s+=s===BLANK?p:F+p)),r=z.showTooltip?parseUnsafeString(pluck(k.tooltext,k.hovertext,z.tooltext)):UNDEF,r===BLANK?(r=n,z.showValuesInTooltip&&(z.showPercentInTooltip?r+=r===BLANK?q:F+q:p!==UNDEF&&p!==BLANK&&(r+=r===BLANK?p:F+p))):r=parseTooltext(r,[1,2,3,14],{percentValue:q,label:n,formattedValue:p},k),f=y[m],t=d+K,K+=l,f||(f=y[m]={components:{data:[]},config:{},graphics:{}}),f.graphics.element&&(u=f.config.startAngle+f.config.angleStrech),f.config={initialAngle:u||(c.config||c.config).initialAngle,startAngle:t,angleStrech:l,level:b,displayValue:s,toolText:r,link:getValidValue(k.link),doNotSlice:!0,color:convertColor(k.color||D.getPlotColor(),o),borderWidth:pluckNumber(k.borderwidth,A),borderColor:pluck(k.bordercolor,B),dashStyle:pluckNumber(k.valueborderdashed,0)?getDashStyle(pluckNumber(k.borderdashlen,4),pluckNumber(k.borderdashgap,2)):DASH_DEF,shadow:{opacity:.01*Math.round(50<o?1e-4*(o*o*o):.01*(o*o))},isSingleTon:!(1<w)},f.config.parent=c,k.category?(G=Math.max(G,x.addMSPieCat(k.category,b+1,f,t,l+t)),(g=f.components.data.length)>(h=k.category.length)&&I(f.components.data.splice(g-1,h))):(g=f.components.data.length,g&&I(f.components.data.splice(0,g)));return H>J&&I(y.splice(J)),G}parsePlotAttributes(a){var b,c,d,e,f,g,h,j,k,l,m,n,o,p,q,s,t=this,u=t.config||{},v=t.getFromEnv('chart'),w=v.config,x=t.components,y=x.data,z=y.length,A=w.dataLabelStyle,B=w.textDirection,C=w.canvasWidth,D=w.canvasHeight,E=pluckNumber(u.originX,w.canvasLeft+.5*C),F=pluckNumber(u.originY,w.canvasTop+.5*D),G=pluckNumber(2*u.pieRadius,Math.min(C,D)),H=calculateInnerRadius(u.innerRadius,G/2),I=t.config.pool||(t.config.pool={}),J=(G-2*H)/(2*u.maxLevel);for(u.innerSize=2*H,a||(a=t),z=a.components.data.length,o=0;o<z;o+=1)t.parsePlotAttributes(a.components.data[o]);q=a.config,e=q.level,e&&(f=e*J+H,g=(e-1)*J+H,p=a.graphics,j=q.angleStrech,k=q.displayValue,l=!!q.link,h=q.color,m=q.startAngle,n=m+q.angleStrech,s=p.element,I.element&&I.element.length&&(s=p.element=s||I.element.shift()),q.plotItem={chart:v,link:q.link,value:j,color:h,labelText:k,graphics:{element:s},selfRef:a},q.eventArgs={link:q.link,label:q.displayValue,toolText:q.toolText},q.props={element:{attr:{ringpath:[E,F,f,g,m,n],"stroke-width":q.borderWidth,stroke:q.borderColor,fill:toRaphaelColor(q.color),"stroke-dasharray":q.dashStyle,cursor:l?POINTER:BLANKSTRING}}},k!==UNDEF&&k!==BLANKSTRING&&(b=(m+n)/2,d=0===g&&q.isSingleTon?0:g+(f-g)/2,!(c=q._textAttrs)&&(c=q._textAttrs={}),c.text=k,c.fill=A.color||COLOR_000000,c.direction=B,c.cursor=l?POINTER:BLANKSTRING,c.x=E+d*Math.cos(b),c.y=F+d*Math.sin(b),c['text-bound']=[A.backgroundColor,A.borderColor,A.borderThickness,A.borderPadding,A.borderRadius,A.borderDash]))}parseLabelAttributes(a){var b,c,d,e,f,g=this,h=g.components,j=h.data,k=j.length;for(a||(a=g),k=a.components.data.length,e=0;e<k;e+=1)g.parseLabelAttributes(a.components.data[e]);f=a.config,d=f.displayValue,b=f._textAttrs,c=f.level,c&&d!==UNDEF&&d!==BLANKSTRING&&(f.props.label={attr:b})}draw(a){var b,c,d,f,e,g=this,h=g.config||{},j=g.getFromEnv('chart'),k=g.getFromEnv('animationManager'),l=g.getFromEnv('toolTipController'),m=j.config,n=g.components,o=n.data,p=o.length,q=m.dataLabelStyle,r=h.showShadow,s=j.getChildContainer('plotGroup'),t=j.getChildContainer('datalabelsGroup'),u=h.events||{},v=function(a){var b=this,c=u.mouseOver,d=b.plotItem||b.data('plotItem'),e=d.chart,g=e.getDatasets()[0];e.plotEventHandler(b,a,ROLLOVER),c&&c.call(b),g.fireEvent('datasetrollover',{pValue:d.pValue,value:d.value,displayValue:f.displayValue})},w=function(a){var b=this,c=u.mouseOut,d=b.plotItem||b.data('plotItem'),e=d.chart,g=e.getDatasets()[0];e.plotEventHandler(b,a,ROLLOUT),c&&c.call(b),g.fireEvent('datasetrollout',{pValue:d.pValue,value:d.value,displayValue:f.displayValue})},x=g.config.pool||(g.config.pool={}),y=n.removeDataArr,z=y&&y.length;for(z&&g.removeElement(),a||(a=g,t.css(q)),p=a.components.data.length,c=0;c<p;c+=1)g.draw(a.components.data[c]);f=a.config,b=f.level,b?(d=a.graphics,e=d.element,x.element&&x.element.length&&(e=d.element=e||x.element.shift()),e=d.element=k.setAnimation({el:d.element||'ringpath',attr:f.props.element.attr,container:s,component:g,state:'appearing',label:'ringpath'}),e.shadow(r&&!!f.shadow).data('plotItem',f.plotItem).data(EVENTARGS,f.eventArgs).on('fc-mouseover',v).on('fc-mouseout',w).on('fc-click',function(a){var b=this;j.plotEventHandler(b,a)}),l.enableToolTip(e,f.toolText),!c&&!h._drawn&&(h._drawn=!0,t.show(),g.addJob('labelJob',g.drawLabel.bind(g),priorityList.label))):(h._drawn&&g.drawLabel(),g.removeChild(g.config.pool,!0))}drawLabel(a){var b,c,d,e,f,g,h,j,k,l=this,m=l.config||{},n=l.getFromEnv('chart'),o=l.getFromEnv('animationManager'),p=n.config,q=l.components,r=q.data,s=r.length,t=p.dataLabelStyle,u=l.getFromEnv('toolTipController'),v=p.tooltip||{},w=v&&!1!==v.enabled,x=m.events||{},y=l.config.pool||(l.config.pool={}),z=n.getChildContainer('datalabelsGroup');for(z.show(),a||(a=l),s=a.components.data.length,g=0;g<s;g+=1)l.drawLabel(a.components.data[g]);j=a.config,d=j.plotItem,e=j.displayValue,b=j.level,b?(h=a.graphics,f=h.label,e!==UNDEF&&e!==BLANKSTRING?(k=h.label,y.label&&y.label.length&&(k=h.label=k||y.label.shift()),k=h.label=o.setAnimation({el:f||'text',attr:j.props.label.attr,container:z,component:l,state:'appearing',label:'text',css:t}),!f&&k.on('fc-click',function(a){var b=this;n.plotEventHandler(b,a)}).on('fc-mouseout',function(a){var b=this,c=x.mouseOut;n.plotEventHandler(b,a,ROLLOUT),c&&c.call(b)}).on('fc-mouseover',function(a){var b=this,c=x.mouseOver;n.plotEventHandler(b,a,ROLLOVER),c&&c.call(b)}),k.data('plotItem',d).data(EVENTARGS,j.eventArgs),w&&u.enableToolTip(k,c)):(f&&o.setAnimation({el:f,component:l,label:'text'}),delete h.label)):l.removeChild(l.config.pool,!0)}}export default MultiLevelPieDataset;