UNPKG

zingchart

Version:

Our JavaScript charting library is a commercial product. But the full branded version is free to try, forever.

8 lines (7 loc) 7.52 kB
/* All of the code within the ZingChart software is developed and copyrighted by ZingChart, Inc., and may not be copied, replicated, or used in any other software or application without prior permission from ZingChart. All usage must coincide with the ZingChart End User License Agreement which can be requested by email at support@zingchart.com. Build 2.9.11_ES6 */ zingchart.setModule("flame"),function(){zingchart.plugins.flame=zingchart.plugins.flame||{};var t={},e={},a={},l={},o={};zingchart.bind(null,"dataparse",function(i,r){var n,p,_,C,Z,d,c,v,h;for(C=0,Z=r[ZC._[16]].length;C<Z;C++)if(r[ZC._[16]][C].type&&("flame"===r[ZC._[16]][C].type||"vflame"===r[ZC._[16]][C].type)){a[i.id]||(a[i.id]={}),l[i.id]||(l[i.id]=-1),o[i.id]=[],t[i.id]||(t[i.id]=JSON.stringify(r));var f=r[ZC._[16]][C].type;r[ZC._[16]][C]["plugin-type"]=f;var s=r[ZC._[16]][C];zingchart.normalize(s),s.type="flame"===f?"hbar":"vbar";var g={};s.options&&(g=s.options[f]||s.options),ZC._todash_(g);var u=g.root||"";e[i.id]=u;var x=g.palette||["#6A921F","#007FA3","#A62B02","#B79007","#563D02","#0B32A0","#00BAF2","#E80C60","#E2D51A","#9B26AF","#FB301E","#00AE4D","#20398B"],m=g["text-attr"]||"text",b=g["value-attr"]||ZC._[9];if(s[ZC._[11]]=s[ZC._[11]]||[],!(s[ZC._[11]]instanceof Array)){var z=[],A={},y=function(t,e){var a=(t.text||t.name||t[m]).toLowerCase().replace(/[^a-z0-9_]+/gi,"");A[a]?a+=A[a]++:A[a]=1;var l={id:a,text:t.text||t.name||t[m]||a,value:t[ZC._[9]]||t[ZC._[21]]||t[b],parent:e||""};if(z.push(l),t.children)for(var o=0;o<t.children.length;o++)y(t.children[o],a)};y(s[ZC._[11]]),s[ZC._[11]]=z}for(var F={},k=[].concat(s[ZC._[11]]).reverse(),w=0,B=k.length,M=0;k.length&&B-- >=0;)for(n=k.length-1;n>=0;n--)d=(c=k[n]).id||"id"+w++,""===(h=c.parent||"")?(F[d]={id:d,level:0,parent:"",text:c.text||c.name||c[m]||d,value:c[ZC._[9]]||c[ZC._[21]]||c[b],children:[]},o[i.id].push(d),k.splice(n,1)):F[h]&&(F[h].children.push(d),F[d]={id:d,level:F[h].level+1,parent:h,text:c.text||c.name||c[m]||d,value:c[ZC._[9]]||c[ZC._[21]]||c[b],children:[]},k.splice(n,1),M=Math.max(M,F[d].level));var R=function(t,e){return e=e||[],F[t]&&""!==F[t].parent&&(e.push(F[t].parent),e=e.concat(R(F[t].parent))),e};if(""!==u){for(d in F)d!==u?(v=R(d),-1===ZC.AV(v,u)&&delete F[d]):(F[d]["up-parent"]=F[d].parent,F[d].parent="");var V=F[u].level;for(d in F)F[d].level-=V;M-=V}var X=0,Y=0;for(_=0;_<=M;_++){if(0===_)for(d in F)0===F[d].level&&Y++;for(d in F){var E="";a[i.id][d]?E=a[i.id][d]:(F[d].level===_&&(E=0===F[d].level||1===F[d].level&&1===Y?x[X++%x.length]:F[F[d].parent].color),a[i.id][d]=E),F[d].color=E}}var I=function(t){if(F[t]){if(null===ZC._n_(F[t][ZC._[9]]))if(0===F[t].children.length)F[t][ZC._[9]]=0;else{for(var e=0,a=0;a<F[t].children.length;a++)e+=I(F[t].children[a]);F[t][ZC._[9]]=e}return parseFloat(F[t][ZC._[9]])}};for(d in F)F[d][ZC._[9]]=I(d);if(-1===l[i.id]){for(d in F)if(0!==F[d].level&&(1!==F[d].level||1!==Y)&&a[i.id][d]){v=R(d);var J=1===Y?v[v.length-2]:v[v.length-1],K=1-F[d][ZC._[9]]/F[J][ZC._[9]];a[i.id][d]=F[d].color=ZC.AR.RC(F[d].color,40*K)}l[i.id]=1}var D=[],L=0;for(_=0;_<=M;_++){if(D[_]){var N=[];for(n=0;n<D[_].length;n++){var G=(c=F[D[_][n]]).children,j=0;for(p=0;p<G.length;p++)N.push(G[p]),j+=F[G[p]][ZC._[9]];if(j<c[ZC._[9]]){var O="sbfakeid"+L++;F[O]={id:O,parent:c.id,value:c[ZC._[9]]-j,level:c.level,children:[],fake:!0,color:c.color},N.push(O)}}D[_]=[].concat(N)}else for(d in D[_]=[],F)F[d].level===_&&D[_].push(d);_<M&&(D[_+1]=[].concat(D[_]))}var P=0;for(n=0;n<D[0].length;n++)P+=F[D[0][n]].value;for(s.flat=!0,s.plotarea=s.plotarea||{},s.plotarea["mask-tolerance"]=s.plotarea["mask-tolerance"]||[0,0],s[ZC._[50]]=s[ZC._[50]]||{},s[ZC._[50]].visible=!1,s[ZC._[51]]=s[ZC._[51]]||{},s[ZC._[51]].visible=!1,s[ZC._[51]].zooming=!0,s[ZC._[51]]["min-value"]=0,s[ZC._[51]]["max-value"]=P,s[ZC._[51]].step=P/100,s[ZC._[51]].normalize=!1,s.zoom=s.zoom||{},s.tooltip=s.tooltip||{},s.tooltip.align=ZC._c_(s.tooltip.align,"left"),s.plot=s.plot||{},s.plot.aspect="histogram",s.plot["bar-width"]="100%",s.plot["bars-overlap"]="100%",s.plot.tolerance=-5,s.plot["fast-rules"]=!0,s.plot.alpha=ZC._c_(s.plot.alpha,1),s.plot[ZC._[62]]=ZC._c_(s.plot[ZC._[62]],1),s.plot[ZC._[61]]=ZC._c_(s.plot[ZC._[61]],"#cccccc"),s.plot["border-alpha"]=ZC._c_(s.plot["border-alpha"],.2),s.plot[ZC._[17]]=s.plot[ZC._[17]]||{},s.plot[ZC._[17]]["js-rule"]="zingchart.plugins.flame.valueBoxJsRule()",s.plot[ZC._[17]]["tooltip-text"]=ZC._c_(s.plot[ZC._[17]]["tooltip-text"],'<span style="font-size:13px">%plot-text</span><br/>Value:%node-value (%data-pc-value%)'),s.plot[ZC._[17]].text=ZC._c_(s.plot[ZC._[17]].text,"%data-vbtext"),s.plot[ZC._[17]][ZC._[7]]=ZC._c_(s.plot[ZC._[17]][ZC._[7]],"bottom-in"),s.plot[ZC._[17]].align=ZC._c_(s.plot[ZC._[17]].align,"left"),s.plot[ZC._[17]].color=ZC._c_(s.plot[ZC._[17]].color,"#000000"),s.plot[ZC._[17]]["font-size"]=ZC._c_(s.plot[ZC._[17]]["font-size"],11),s.plot[ZC._[17]]["font-weight"]=ZC._c_(s.plot[ZC._[17]]["font-weight"],"normal"),s.plot[ZC._[17]].tolerance=[0,0,0,0],s.plot[ZC._[17]].angle=ZC._c_(s.plot[ZC._[17]].angle,"flame"===f?0:90),delete s.options,delete s[ZC._[11]],s[ZC._[11]]=[],_=0;_<=M;_++){var S=0,U=-1;for(n=0;n<D[_].length;n++){var q=F[D[_][n]].text,H=q,Q=F[D[_][n]].id;h=F[D[_][n]]["up-parent"]||F[D[_][n]].parent,0===_&&(""!==h||1===Y&&o[i.id].length>1&&-1!==ZC.AV(o[i.id],Q))&&(H="\u25b2 "+H),c={"data-l0items":Y,"data-parent":h,"data-uid":Q,"data-level":F[D[_][n]].level,"data-plottype":f,"data-vbtext":H,"data-vbfontsize":s.plot[ZC._[17]]["font-size"],"data-value":F[D[_][n]][ZC._[9]],"data-percent":(F[D[_][n]][ZC._[9]]/P*100).toFixed(2),"data-local-value":F[D[_][n]][ZC._[9]],"data-local-percent":(F[D[_][n]][ZC._[9]]/P*100).toFixed(2),"data-offset":S,"-tooltip-text":'<span style="font-size:19px">%data-vbtext</span><br>Value:%data-value (%data-percent%)',"tooltip-text":'<span style="font-size:19px">%data-vbtext</span><br>Value:%data-local-value (%data-local-percent%)',text:q,"offset-values":[S],values:[[F[D[_][n]].level,F[D[_][n]][ZC._[9]]]],"background-color":F[D[_][n]].color,"hover-state":{"background-color":ZC.AR.JU(F[D[_][n]].color,20)}},S+=F[D[_][n]][ZC._[9]],F[D[_][n]].fake&&(c.visible=!1),F[D[_][n]].fake?-1===U?(s[ZC._[11]].push(c),U=s[ZC._[11]].length-1):s[ZC._[11]][U][ZC._[5]][0][1]+=c[ZC._[5]][0][1]:(U=-1,s[ZC._[11]].push(c))}}}return r}),zingchart.plugins.flame.onNodeClick=function(t){var e=zingchart.getLoader(t.id);if(e&&0===t.ev.button){var a=zingchart.getGraph(e,t.graphid);if(a&&("flame"===a.o["plugin-type"]||"vflame"===a.o["plugin-type"])){for(var l=0;l<a.AZ.A3.length;l++)a.AZ.A3[l].K7["local-value"]=Math.min(t[ZC._[9]],a.AZ.A3[l].K7[ZC._[9]]),a.AZ.A3[l].K7["local-percent"]=Math.min(100,100*a.AZ.A3[l].K7[ZC._[9]]/t[ZC._[9]]).toFixed(2);zingchart.exec(t.id,"zoomto",{graphid:t.graphid,ymin:t["data-offset"],ymax:t["data-offset"]+t[ZC._[9]]})}}},zingchart.bind(null,"node_click",zingchart.plugins.flame.onNodeClick),zingchart.plugins.flame.valueBoxJsRule=function(t){var e=zingchart.getLoader(t.id),a=zingchart.getGraph(e,t.graphid).P,l={visible:!1},o=t.width,i=t.height;o=t.x<=a.iX?t.x+t.width>=a.iX+a.I?a.I:t.width-(a.iX-t.x):t.x+t.width<=a.iX+a.I?t.width:a.iX-a.I-t.x,i=t.y<=a.iY?t.y+t.height>=a.iY+a.F?a.F:t.height-(a.iY-t.y):t.y+t.height<=a.iY+a.F?t.height:a.iY-a.F-t.y;var r="flame"===t["data-plottype"]?o:i;if(r>=40){l.visible=!0,t["data-vbtext"]=t["data-vbtext"]||"";var n=Math.round(r/(.7*t["data-vbfontsize"]));n>=t["data-vbtext"].length?l.text=t["data-vbtext"]:l.text=t["data-vbtext"].substring(0,n-3)+"..."}return l}}();