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.48 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 */ zingchart.setModule("flame"),function(){zingchart.plugins.flame=zingchart.plugins.flame||{};var e={},a={},t={},l={},o={};zingchart.bind(null,"dataparse",function(i,r){var n,p,v,s,c,u,d,h,f;for(s=0,c=r.graphset.length;s<c;s++)if(r.graphset[s].type&&("flame"===r.graphset[s].type||"vflame"===r.graphset[s].type)){t[i.id]||(t[i.id]={}),l[i.id]||(l[i.id]=-1),o[i.id]=[],e[i.id]||(e[i.id]=JSON.stringify(r));var g=r.graphset[s].type;r.graphset[s]["plugin-type"]=g;var x=r.graphset[s];zingchart.normalize(x),x.type="flame"===g?"hbar":"vbar";var b={};x.options&&(b=x.options[g]||x.options),ZC._todash_(b);var m=b.root||"";a[i.id]=m;var z=b.palette||["#6A921F","#007FA3","#A62B02","#B79007","#563D02","#0B32A0","#00BAF2","#E80C60","#E2D51A","#9B26AF","#FB301E","#00AE4D","#20398B"],_=b["text-attr"]||"text",y=b["value-attr"]||"value";if(x.series=x.series||[],!(x.series instanceof Array)){var Z=[],A={},C=function(e,a){var t=(e.text||e.name||e[_]).toLowerCase().replace(/[^a-z0-9_]+/gi,"");A[t]?t+=A[t]++:A[t]=1;var l={id:t,text:e.text||e.name||e[_]||t,value:e.value||e.size||e[y],parent:a||""};if(Z.push(l),e.children)for(var o=0;o<e.children.length;o++)C(e.children[o],t)};C(x.series),x.series=Z}for(var F={},k=[].concat(x.series).reverse(),w=0,B=k.length,M=0;k.length&&B-- >=0;)for(n=k.length-1;n>=0;n--)u=(d=k[n]).id||"id"+w++,""===(f=d.parent||"")?(F[u]={id:u,level:0,parent:"",text:d.text||d.name||d[_]||u,value:d.value||d.size||d[y],children:[]},o[i.id].push(u),k.splice(n,1)):F[f]&&(F[f].children.push(u),F[u]={id:u,level:F[f].level+1,parent:f,text:d.text||d.name||d[_]||u,value:d.value||d.size||d[y],children:[]},k.splice(n,1),M=Math.max(M,F[u].level));var V=function(e,a){return a=a||[],F[e]&&""!==F[e].parent&&(a.push(F[e].parent),a=a.concat(V(F[e].parent))),a};if(""!==m){for(u in F)u!==m?(h=V(u),-1===ZC.AV(h,m)&&delete F[u]):(F[u]["up-parent"]=F[u].parent,F[u].parent="");var X=F[m].level;for(u in F)F[u].level-=X;M-=X}var Y=0,E=0;for(v=0;v<=M;v++){if(0===v)for(u in F)0===F[u].level&&E++;for(u in F){var I="";t[i.id][u]?I=t[i.id][u]:(F[u].level===v&&(I=0===F[u].level||1===F[u].level&&1===E?z[Y++%z.length]:F[F[u].parent].color),t[i.id][u]=I),F[u].color=I}}var J=function(e){if(F[e]){if(null===ZC._n_(F[e].value))if(0===F[e].children.length)F[e].value=0;else{for(var a=0,t=0;t<F[e].children.length;t++)a+=J(F[e].children[t]);F[e].value=a}return parseFloat(F[e].value)}};for(u in F)F[u].value=J(u);if(-1===l[i.id]){for(u in F)if(0!==F[u].level&&(1!==F[u].level||1!==E)&&t[i.id][u]){h=V(u);var K=1===E?h[h.length-2]:h[h.length-1],D=1-F[u].value/F[K].value;t[i.id][u]=F[u].color=ZC.AQ.R0(F[u].color,40*D)}l[i.id]=1}var L=[],N=0;for(v=0;v<=M;v++){if(L[v]){var R=[];for(n=0;n<L[v].length;n++){var G=(d=F[L[v][n]]).children,O=0;for(p=0;p<G.length;p++)R.push(G[p]),O+=F[G[p]].value;if(O<d.value){var Q="sbfakeid"+N++;F[Q]={id:Q,parent:d.id,value:d.value-O,level:d.level,children:[],fake:!0,color:d.color},R.push(Q)}}L[v]=[].concat(R)}else for(u in L[v]=[],F)F[u].level===v&&L[v].push(u);v<M&&(L[v+1]=[].concat(L[v]))}var j=0;for(n=0;n<L[0].length;n++)j+=F[L[0][n]].value;for(x.flat=!0,x.plotarea=x.plotarea||{},x.plotarea["mask-tolerance"]=x.plotarea["mask-tolerance"]||[0,0],x["scale-x"]=x["scale-x"]||{},x["scale-x"].visible=!1,x["scale-y"]=x["scale-y"]||{},x["scale-y"].visible=!1,x["scale-y"].zooming=!0,x["scale-y"]["min-value"]=0,x["scale-y"]["max-value"]=j,x["scale-y"].step=j/100,x["scale-y"].normalize=!1,x.zoom=x.zoom||{},x.tooltip=x.tooltip||{},x.tooltip.align=ZC._c_(x.tooltip.align,"left"),x.plot=x.plot||{},x.plot.aspect="histogram",x.plot["bar-width"]="100%",x.plot["bars-overlap"]="100%",x.plot.tolerance=-5,x.plot["fast-rules"]=!0,x.plot.alpha=ZC._c_(x.plot.alpha,1),x.plot["border-width"]=ZC._c_(x.plot["border-width"],1),x.plot["border-color"]=ZC._c_(x.plot["border-color"],"#cccccc"),x.plot["border-alpha"]=ZC._c_(x.plot["border-alpha"],.2),x.plot["value-box"]=x.plot["value-box"]||{},x.plot["value-box"]["js-rule"]="zingchart.plugins.flame.valueBoxJsRule()",x.plot["value-box"]["tooltip-text"]=ZC._c_(x.plot["value-box"]["tooltip-text"],'<span style="font-size:13px">%plot-text</span><br/>Value:%node-value (%data-pc-value%)'),x.plot["value-box"].text=ZC._c_(x.plot["value-box"].text,"%data-vbtext"),x.plot["value-box"].placement=ZC._c_(x.plot["value-box"].placement,"bottom-in"),x.plot["value-box"].align=ZC._c_(x.plot["value-box"].align,"left"),x.plot["value-box"].color=ZC._c_(x.plot["value-box"].color,"#000000"),x.plot["value-box"]["font-size"]=ZC._c_(x.plot["value-box"]["font-size"],11),x.plot["value-box"]["font-weight"]=ZC._c_(x.plot["value-box"]["font-weight"],"normal"),x.plot["value-box"].tolerance=[0,0,0,0],x.plot["value-box"].angle=ZC._c_(x.plot["value-box"].angle,"flame"===g?0:90),delete x.options,delete x.series,x.series=[],v=0;v<=M;v++){var P=0,S=-1;for(n=0;n<L[v].length;n++){var q=F[L[v][n]].text,H=q,T=F[L[v][n]].id;f=F[L[v][n]]["up-parent"]||F[L[v][n]].parent,0===v&&(""!==f||1===E&&o[i.id].length>1&&-1!==ZC.AV(o[i.id],T))&&(H="\u25b2 "+H),d={"data-l0items":E,"data-parent":f,"data-uid":T,"data-level":F[L[v][n]].level,"data-plottype":g,"data-vbtext":H,"data-vbfontsize":x.plot["value-box"]["font-size"],"data-value":F[L[v][n]].value,"data-percent":(F[L[v][n]].value/j*100).toFixed(2),"data-local-value":F[L[v][n]].value,"data-local-percent":(F[L[v][n]].value/j*100).toFixed(2),"data-offset":P,"-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":[P],values:[[F[L[v][n]].level,F[L[v][n]].value]],"background-color":F[L[v][n]].color,"hover-state":{"background-color":ZC.AQ.JO(F[L[v][n]].color,20)}},P+=F[L[v][n]].value,F[L[v][n]].fake&&(d.visible=!1),F[L[v][n]].fake?-1===S?(x.series.push(d),S=x.series.length-1):x.series[S].values[0][1]+=d.values[0][1]:(S=-1,x.series.push(d))}}}return r}),zingchart.plugins.flame.onNodeClick=function(e){var a=zingchart.getLoader(e.id);if(a&&0===e.ev.button){var t=zingchart.getGraph(a,e.graphid);if(t&&("flame"===t.o["plugin-type"]||"vflame"===t.o["plugin-type"])){for(var l=0;l<t.AZ.A3.length;l++)t.AZ.A3[l].K0["local-value"]=Math.min(e.value,t.AZ.A3[l].K0.value),t.AZ.A3[l].K0["local-percent"]=Math.min(100,100*t.AZ.A3[l].K0.value/e.value).toFixed(2);zingchart.exec(e.id,"zoomto",{graphid:e.graphid,ymin:e["data-offset"],ymax:e["data-offset"]+e.value})}}},zingchart.bind(null,"node_click",zingchart.plugins.flame.onNodeClick),zingchart.plugins.flame.valueBoxJsRule=function(e){var a=zingchart.getLoader(e.id),t=zingchart.getGraph(a,e.graphid).P,l={visible:!1},o=e.width,i=e.height;o=e.x<=t.iX?e.x+e.width>=t.iX+t.I?t.I:e.width-(t.iX-e.x):e.x+e.width<=t.iX+t.I?e.width:t.iX-t.I-e.x,i=e.y<=t.iY?e.y+e.height>=t.iY+t.F?t.F:e.height-(t.iY-e.y):e.y+e.height<=t.iY+t.F?e.height:t.iY-t.F-e.y;var r="flame"===e["data-plottype"]?o:i;if(r>=40){l.visible=!0,e["data-vbtext"]=e["data-vbtext"]||"";var n=Math.round(r/(.7*e["data-vbfontsize"]));n>=e["data-vbtext"].length?l.text=e["data-vbtext"]:l.text=e["data-vbtext"].substring(0,n-3)+"..."}return l}}();