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) 6.46 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("sunburst"),function(){var e={},t={},a={},r={},l={},i={},n={};zingchart.bind(null,"dataparse",function(o,d){var s,p,h,u,v,g,c,f,x,_=zingchart.getLoader(o.id);for(n[o.id]?n[o.id]!==_.I+"/"+_.F&&(d=JSON.parse(_.E.source),n[o.id]=_.I+"/"+_.F):n[o.id]=_.I+"/"+_.F,u=0,v=d.graphset.length;u<v;u++)if(d.graphset[u].type&&"sunburst"===d.graphset[u].type){e[o.id]=!0,r[o.id]||(r[o.id]={}),l[o.id]||(l[o.id]=-1),i[o.id]=[],t[o.id]||(t[o.id]=JSON.stringify(d));var b=d.graphset[u].type;d.graphset[u]["plugin-type"]=b;var z=d.graphset[u];zingchart.normalize(z),z.type="pie";var C=zingchart.getGraphInfo(_,d,u),y={};z.options&&(y=z.options[b]||z.options),ZC._todash_(y);var Z=y.root||"";a[o.id]=Z;var m=ZC._i_(y.slice||"0"),A=ZC._f_(y["size-factor"]||"0.95"),w=ZC._i_(y.space||"0"),F=y.widths||[],k=y.palette||["#6A921F","#007FA3","#A62B02","#B79007","#563D02","#0B32A0","#00BAF2","#E80C60","#E2D51A","#9B26AF","#FB301E","#00AE4D","#20398B"],B=y["text-attr"]||"text",D=y["value-attr"]||"value";if(z.series=z.series||[],!(z.series instanceof Array)){var O=[],E={},I=function(e,t){var a=(e.text||e.name||e[B]).toLowerCase().replace(/[^a-z0-9_]+/gi,"");E[a]?a+=E[a]++:E[a]=1;var r={id:a,text:e.text||e.name||e[B]||a,value:e.value||e.size||e[D],parent:t||""};if(O.push(r),e.children)for(var l=0;l<e.children.length;l++)I(e.children[l],a)};I(z.series,""),z.series=O}for(var J,L={},M=[].concat(z.series).reverse(),N=0,S=M.length,T=0;M.length&&S-- >=0;)for(s=M.length-1;s>=0;s--)for(J in g=(c=M[s]).id||"id"+N++,""===(x=c.parent||"")?(L[g]={id:g,level:0,parent:"",text:c.text||c.name||c[B]||g,value:c.value||c.size||c[D],children:[]},i[o.id].push(g),M.splice(s,1)):L[x]&&(L[x].children.push(g),L[g]={id:g,level:L[x].level+1,parent:x,text:c.text||c.name||c[B]||g,value:c.value||c.size||c[D],children:[]},M.splice(s,1),T=Math.max(T,L[g].level)),c)0===J.indexOf("data-")&&(L[g][J]=c[J]);var V=function(e,t){return t=t||[],L[e]&&""!==L[e].parent&&(t.push(L[e].parent),t=t.concat(V(L[e].parent))),t};if(""!==Z){for(g in L)g!==Z?(f=V(g),-1===ZC.AV(f,Z)&&delete L[g]):(L[g]["up-parent"]=L[g].parent,L[g].parent="");var j=L[Z].level;for(g in L)L[g].level-=j;T-=j}var G=0,Q=0;for(h=0;h<=T;h++){if(0===h)for(g in L)0===L[g].level&&Q++;for(g in L){var R="";r[o.id][g]?R=r[o.id][g]:(L[g].level===h&&(R=0===L[g].level||1===L[g].level&&1===Q?k[G++%k.length]:L[L[g].parent].color),r[o.id][g]=R),L[g].color=R}}var q=function(e){if(L[e]){if(null===ZC._n_(L[e].value))if(0===L[e].children.length)L[e].value=0;else{for(var t=0,a=0;a<L[e].children.length;a++)t+=q(L[e].children[a]);L[e].value=t}return parseFloat(L[e].value)}};for(g in L)L[g].value=q(g);if(-1===l[o.id]){for(g in L)if(0!==L[g].level&&(1!==L[g].level||1!==Q)&&r[o.id][g]){f=V(g);var H=1===Q?f[f.length-2]:f[f.length-1],K=1-L[g].value/L[H].value;r[o.id][g]=L[g].color=ZC.AQ.R0(L[g].color,40*K)}l[o.id]=1}var P=[],U=0;for(h=0;h<=T;h++){if(P[h]){var W=[];for(s=0;s<P[h].length;s++){var X=(c=L[P[h][s]]).children,Y=0;for(p=0;p<X.length;p++)W.push(X[p]),Y+=L[X[p]].value;if(Y<c.value){var $="sbfakeid"+U++;L[$]={id:$,parent:c.id,value:c.value-Y,level:c.level,children:[],fake:!0,color:c.color},W.push($)}}P[h]=[].concat(W)}else for(g in P[h]=[],L)L[g].level===h&&P[h].push(g);h<T&&(P[h+1]=[].concat(P[h]))}d.graphset.splice(u,1);var ee={};ZC._cp_(z,ee),delete ee.options,delete ee.series,delete ee["no-data"],ee["background-color"]="none",ee.x=C.graph.x,ee.y=C.graph.y,ee.width=C.graph.width,ee.height=C.graph.height,ee.plot=ee.plot||{},ee.plot["value-box"]=ee.plot["value-box"]||{},ee.plot["value-box"].placement=ee.plot["value-box"].placement||"radial",ee.plot.detach=!1;for(var te=["plotarea","legend","title","subtitle","source"],ae=0;ae<te.length;ae++)ee[te[ae]]&&delete ee[te[ae]]["adjust-layout"];var re=A*(Math.min(C.plotarea.width,C.plotarea.height)/2-m-T*w),le=ZC._i_(re/(T+1));for(h=0;h<=T;h++){var ie={};if(ZC._cp_(ee,ie),h>0&&(delete ie.title,delete ie.subtitle,delete ie.source,delete ie.legend,delete ie["no-data"]),ie.id="glvl"+h,0===F.length)ie.plot.size=m+le*(h+1)+w*h,ie.plot.slice=m+le*h+w*h;else{for(var ne=0,oe=0;oe<h;oe++)ne+=F[oe]||le;ie.plot.slice=m+ne+w*h,ne+=F[h]||le,ie.plot.size=m+ne+w*h}ie.series=[];var de=-1;for(s=0;s<P[h].length;s++){var se=L[P[h][s]].text,pe=se,he=L[P[h][s]].id;for(J in x=L[P[h][s]]["up-parent"]||L[P[h][s]].parent,0===h&&(""!==x||1===Q&&i[o.id].length>1&&-1!==ZC.AV(i[o.id],he))&&(pe="\u25b2 "+pe),c={"data-l0items":Q,"data-parent":x,"data-uid":he,"data-level":L[P[h][s]].level,"data-vbtext":pe,text:se,values:[L[P[h][s]].value],"background-color":L[P[h][s]].color,"hover-state":{"background-color":ZC.AQ.JO(L[P[h][s]].color,20)}},L[P[h][s]])0===J.indexOf("data-")&&(c[J]=L[P[h][s]][J]);L[P[h][s]].fake&&(c.visible=!1),L[P[h][s]].fake?-1===de?(ie.series.push(c),de=ie.series.length-1):ie.series[de].values[0]+=c.values[0]:(de=-1,ie.series.push(c))}d.graphset.splice(u,0,ie)}var ue={};ZC._cp_(z,ue),delete ue.options,delete ue.series,delete ue.legend,delete ue["no-data"],ue.type="pie";for(te=["plotarea","legend","title","subtitle","source"],ae=0;ae<te.length;ae++)ue[te[ae]]&&delete ue[te[ae]]["adjust-layout"];ue.x=C.graph.x,ue.y=C.graph.y,ue.width=C.graph.width,ue.height=C.graph.height,d.graphset.splice(u,0,ue)}return d});var o=null;zingchart.bind(null,"node_click",function(e){if("touchend"===e.ev.type){if(null===o)return void(o=(new Date).getTime());if((new Date).getTime()-o>=300)return void(o=(new Date).getTime());o=null}else if(0!==e.ev.button)return;var r=zingchart.getLoader(e.id);if(r){var l=zingchart.getGraph(r,e.graphid);if(l&&"sunburst"===l.o["plugin-type"]){var n=JSON.parse(t[e.id]);n.graphset[0].options=n.graphset[0].options||{},null!==ZC._n_(n.graphset[0].options.flat)&&ZC._b_(n.graphset[0].options.flat)||(""!==e["data-parent"]||e["data-l0items"]>1||i[e.id].length>1&&-1!==ZC.AV(i[e.id],e["data-uid"]))&&(a[e.id]===e["data-uid"]?n.graphset[0].options.root=e["data-parent"]:n.graphset[0].options.root=e["data-uid"],zingchart.exec(e.id,"setdata",{data:n}))}}});zingchart.bind(null,"destroy",function(o){e[o.id]&&(delete e[o.id],delete n[o.id],t={},a={},r={},l={},i={})})}();