zingchart
Version:
Our JavaScript charting library is a commercial product. But the full branded version is free to try, forever.
8 lines (7 loc) • 4.61 kB
JavaScript
/*
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("bubble-legend"),zingchart.plugins.bubblelegend={},zingchart.plugins.bubblelegend.info={},zingchart.bind(null,"complete",function(e){var n=zingchart.getLoader(e.id),i=zingchart.getModules(n);if(-1!==ZC.AV(i,"bubble-legend"))for(var t=0,a=n.AG.length;t<a;t++){var l=!1,r={},o=n.AG[t];if(o.o["bubble-legend"])for(var d=0,g=o.AZ.A3.length;d<g;d++){var b=o.AZ.A3[d];"bubble"!==b.AF&&"hbubble"!==b.AF||(l=!0,r["g"+b.A1W]=r["g"+b.A1W]||{min:Number.MAX_VALUE,max:-Number.MAX_VALUE,maxSize:0,graphid:t,plotindex:b.L,color:"-1"!==b.A2.A0?b.A2.A0:b.BP[1]},r["g"+b.A1W].max=Math.max(r["g"+b.A1W].max,b.XA),r["g"+b.A1W].min=Math.min(r["g"+b.A1W].min,b.RY))}if(l){var c=o.o["bubble-legend"]||{},h=c.layout||"v";null===ZC._n_(c.margin)&&(c.margin="v"===h?"auto 10 auto auto":"auto auto 10 auto");var u,p,s,x,z,_,m,f=[],A=0,v=Number.MAX_VALUE,Z=0,y=0,C=zingchart.getInstance(o,"textbox");for(p in r)for(Z++,s=r[p],z=(x=ZC.AP.X2(s.min,s.max))[3],A=Math.max(A,zingchart.exec(n.K,"getbubblesize",{graphid:s[ZC._[3]],plotindex:s.plotindex,value:x[1]})),v=Math.min(v,zingchart.exec(n.K,"getbubblesize",{graphid:s[ZC._[3]],plotindex:s.plotindex,value:0===x[0]?x[0]+x[2]:x[0]})),u=x[0];u<=x[1];u+=x[2])u>0&&(_={decimals:z,short:!0,"thousands-separator":",","decimals-separator":"."},ZC._cp_(c.item,_),m=zingchart.formatNumber(x[1],_),C.append({"font-size":10,text:m}),C.append(c.item),C.parse(),y=Math.max(y,C.I));var M=ZC._i_(c.padding||5),X=zingchart.getInstance(o,"box");X.append({id:o.K+"-bubblelegend-box"}),"v"===h?X.append({width:2*M+2*A+10+y,height:2*M+2*A*Z+10*(Z-1)+5}):X.append({width:2*M+2*A*Z+10*(Z-1)+Z*y,height:2*M+2*A+30}),X.append(o.o["bubble-legend"]),X.parse();var w={type:"rect",x:X.iX+X.I/2,y:X.iY+X.F/2,width:X.I,height:X.F,"background-color":"#fff"};ZC._cp_(o.o["bubble-legend"],w),f.push(w);var K=0;for(p in r){s=r[p],z=(x=ZC.AP.X2(s.min,s.max))[3];var L=[];for(u=x[0];u<=x[1];u+=x[2])u>0&&L.push(u);var V=[];for(A<15?V.push(L[L.length-1]):A>=15&&A<25?V.push(L[0],L[L.length-1]):A-v>=10?V.push(L[0],L[Math.floor(L.length/2.5)],L[L.length-1]):V.push(L[0],L[L.length-1]),u=0;u<V.length;u++){var W=zingchart.exec(n.K,"getbubblesize",{graphid:s[ZC._[3]],plotindex:s.plotindex,value:V[u]});_={decimals:z,short:!0,"thousands-separator":",","decimals-separator":"."},ZC._cp_(c.item,_),m=zingchart.formatNumber(V[u],_);var I,N,F=n.K+"_"+s[ZC._[3]];Z>1&&(F+="_"+s.plotindex),"h"===h?(I=X.iX+K*(10+2*A+y)+M,N=X.iY+A+M+15):(I=X.iX+A+M,N=X.iY+M+2*A+K*(10+2*A)+5),zingchart.plugins.bubblelegend.info[F]={x:I,y:N,layout:h};var Y={id:o.K+"-bubblelegend-circle_"+K+"_"+u,type:"circle",size:W,alpha:.25,"background-color":Z>1?s.color:"#999","line-style":"dotted","border-width":1,"border-alpha":1,"border-color":"#333"};if("h"===h){var j=N+(u%2==0?-1:1)*(A+10);u===V.length-1&&3===V.length&&(j=N-A/2-5),ZC._cp_({x:I+W,y:N,connector:{"line-width":1,"line-style":"dotted","line-color":"#333",anchor:"l",points:[[I+2*W,N],[I+2*W,j]]}},Y)}else ZC._cp_({x:I,y:N-W,connector:{"line-width":1,"line-style":"dotted","line-color":"#333",anchor:"l",points:[[I,N-2*W],[I+A+10,N-2*W]]}},Y);ZC._cp_({label:{color:"#666","font-size":10,align:"left",text:m}},Y),ZC._cp_(c.marker,Y),ZC._cp_(c.connector,Y.connector),ZC._cp_(c.item,Y.label),f.push(Y)}K++}zingchart.exec(n.K,"addobject",{type:"shape",data:f})}}}),zingchart.bind(null,"node_mouseout",function(e){var n=zingchart.getLoader(e.id),i=zingchart.getModules(n);-1!==ZC.AV(i,"bubble-legend")&&zingchart.exec(e.id,"removeobject",{type:"shape",dynamic:!0,id:e.id+"_"+e.graphindex+"-bubblelegend-circle"})}),zingchart.bind(null,"node_mouseover",function(e){var n=zingchart.getLoader(e.id),i=zingchart.getModules(n);if(-1!==ZC.AV(i,"bubble-legend")&&null!==ZC._n_(e.size)){var t=e.id+"_"+e.graphindex;zingchart.plugins.bubblelegend.info[t]||(t+="_"+e.plotindex);var a={id:e.id+"_"+e.graphindex+"-bubblelegend-circle",type:"circle",size:e.size,"border-width":1,"border-color":"#333"};"h"===zingchart.plugins.bubblelegend.info[t].layout?(a.x=zingchart.plugins.bubblelegend.info[t].x+e.size,a.y=zingchart.plugins.bubblelegend.info[t].y):(a.x=zingchart.plugins.bubblelegend.info[t].x,a.y=zingchart.plugins.bubblelegend.info[t].y-e.size),zingchart.exec(e.id,"addobject",{type:"shape",dynamic:!0,data:a})}});