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.84 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("wordcloud"),function(){var t;ZC.AFW=((t=function(){this.AFD=9,this.AFE=99,this.AFF=2,this.EH=100,this.AFG=15,this.AFH=5,this.ZY=!1,this.EQ="word",this.ACG=[],this.AN="",this.aWords=[],this.oWordsMap=null,this.CV="spiral",this.AF9="palette",this.C2="#000",this.bNormalize=!1,this.AGQ=function(){for(var t=(16777215*Math.random()+1<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},this.ET=function(){var t,e,a={};if(""!==this.AN){if("word"===this.EQ)t=this.AN.replace(/[\:\;\,\.\{\}\[\]\(\)\?\!\/\=\+\-]/g," ").split(" ");else if("character"===this.EQ)for(this.AFF=0,t=[],e=0;e<this.AN.length;e++)" "!==this.AN[e]&&t.push(this.AN[e]);for(e=0;e<t.length;e++){var o=this.bNormalize?t[e].toLowerCase():t[e];if(t[e].length>=this.AFF&&-1===ZC.AV(this.ACG,t[e]))if(this.bNormalize){var l=!1;for(var r in a)r.toLowerCase()===o&&(l=!0,a[r]++);l||(a[t[e]]=1)}else null===ZC._n_(a[t[e]])&&(a[t[e]]=0),a[t[e]]++}}if(this.aWords.length>0)for(this.oWordsMap={},e=0;e<this.aWords.length;e++){var i=this.aWords[e];null!==ZC._n_(i.text)&&(this.oWordsMap[i.text]=i,a[i.text]=i.count||0)}return a},this.intersectRect=function(t,e){return!(e.iX>t.iX+t.I||e.iX+e.I<t.iX||e.iY>t.iY+t.F||e.iY+e.F<t.iY)}}).getDefaults=function(e){var a={};return ZC._cp_(t.B8,a),t.O3[e]&&ZC._cp_(t.O3[e],a),a},t.B8={palette:["#6a921f","#007fa3","#a62b02","#b79007","#563d02","#0b32a0"]},t.O3={light:{palette:["#7CA82B","#29A2CC","#D31E1E","#EF8535","#A14BC9","#A05F18","#265E96","#6B7075"]},dark:{palette:["#7CA82B","#29A2CC","#D31E1E","#EF8535","#A14BC9","#A05F18","#265E96","#6B7075"]}},t),zingchart.bind(null,"dataparse",function(t,e){for(var a,o,l,r,i,n=zingchart.getLoader(t.id),C=0,_=e[ZC._[16]].length;C<_;C++)if(e[ZC._[16]][C].type&&"wordcloud"===e[ZC._[16]][C].type){var h=e[ZC._[16]][C].type,s=e[ZC._[16]][C],p=ZC.AFW.getDefaults(t.theme),Z={};for(s.options&&(Z=s.options[h]||s.options),ZC._todash_(Z,!0,["words"]),s[ZC._[10]]=s[ZC._[10]]||[],r=s[ZC._[10]].length-1;r>=0;r--)(s[ZC._[10]][r]["data-word-cloud"]||s[ZC._[10]][r].dataWordCloud)&&s[ZC._[10]].splice(r,1);s.plotarea=s.plotarea||{},null===ZC._n_(s.plotarea.margin)&&(s.plotarea.margin=5);var A=new ZC.AFW;null!==ZC._n_(a=Z.text)&&(A.AN=a),null!==ZC._n_(a=Z.words)&&(A.aWords=a),null!==ZC._n_(a=Z.aspect)&&(A.CV=a),null!==ZC._n_(a=Z.ignore)&&(A.ACG=a),null!==ZC._n_(a=Z.token)&&(A.EQ=a),null!==ZC._n_(a=Z["min-length"])&&(A.AFF=ZC._i_(a)),null!==ZC._n_(a=Z["min-font-size"])&&(A.AFD=ZC._i_(a)),null!==ZC._n_(a=Z["max-font-size"])&&(A.AFE=ZC._i_(a)),null!==ZC._n_(a=Z["max-items"])&&(A.EH=ZC._i_(a)),null!==ZC._n_(a=Z["color-type"])&&(A.AF9=a),null!==ZC._n_(a=Z.color)&&(A.C2=ZC.AR.GE(a)),null!==ZC._n_(a=Z.palette)?A.BP=a:A.BP=p.palette,null!==ZC._n_(a=Z["step-angle"])&&(A.AFG=ZC._i_(a)),null!==ZC._n_(a=Z["step-radius"])&&(A.AFH=ZC._i_(a)),null!==ZC._n_(a=Z.rotate)&&(A.ZY=ZC._b_(a)),null!==ZC._n_(a=Z.normalize)&&(A.bNormalize=ZC._b_(a));var f={};null!==ZC._n_(a=Z.style)&&ZC._cp_(a,f);var u=zingchart.getInstance(n,"textbox");u.append(f),u.parse(),A.AFD=ZC.BQ(4,A.AFD),A.AFE=ZC.BQ(4,A.AFE),A.AFD>=A.AFE&&(A.AFE=A.AFD+2);var F=zingchart.getGraphInfo(n,e,C),c=[],d=F.plotarea.x+F.plotarea.width/2,g=F.plotarea.y+F.plotarea.height/2,E=1;"spiral"===A.CV?E=A.ZY?.65:.55:"flow-top"!==A.CV&&"flow-center"!==A.CV||(A.ZY=!1,E=.75);var w=F.plotarea.width*F.plotarea.height*E,x=A.ET(),v=[],D=-Number.MAX_VALUE,b=Number.MAX_VALUE;for(var V in x)v.push({text:V,count:x[V],hits:x[V]});for(v.sort(function(t,e){return t.count<e.count?1:t.count>e.count?-1:0}),-1!==A.EH&&v.splice(A.EH,v.length-A.EH),o=0;o<v.length;o++)D=ZC.BQ(v[o].count,D),b=ZC.CX(v[o].count,b);for(o=0;o<v.length;o++)v[o].count=D===b?50:10+90*(v[o].count-b)/(D-b);var m=function(t){for(o=0;o<v.length;o++)v[o].fontSize=Math.max(A.AFD,ZC._i_(A.AFD+v[o].count/100*(A.AFE-A.AFD))-t),v[o].width=ZC.Q.A4Y(n.K,v[o].text,u.GJ,v[o].fontSize,u.sFontWeight,u.FM)+u.EP+u.FP,v[o].height=1.1*v[o].fontSize+u.FO+u.FX};m(0);for(var y=!1;!y;){y=!0;var z=0;for(o=0;o<v.length;o++)z+=v[o].width*v[o].height;z>w&&(y=!1,A.AFE--,A.AFE<=A.AFD+4&&A.AFD--,m(0),(A.AFD<5||A.AFE<5)&&(y=!0))}null===ZC._n_(Z["step-radius"])&&(A.AFH=(A.AFE-A.AFD+.25*A.AFD*A.AFF+1)/10);for(var W=!0,B=-1;W&&B<A.AFE-A.AFD;){c=[],s[ZC._[10]]=[],m(B+=1),W=!1;var M,G=0,N=0,Y=A.AFE/2,Q=A.AFE/2,X=[];for(o=0,l=v.length;o<l;o++){var H=!0,k=d,I=g,P=A.C2;switch(A.AF9){case"random":P=A.AGQ();break;case"palette":P=A.BP[o%A.BP.length]}var S=A.ZY?o%4==0||o%4==3?0:90:0,L=!1,O=v[o].text,J={padding:0,dataWordCloud:!0};ZC._cp_(f,J),ZC._cp_({angle:S,"font-size":Math.max(A.AFD,v[o].fontSize-B),text:O,color:P},J),null!==ZC._n_(Z.style)&&null!==ZC._n_(a=Z.style[ZC._[71]])&&(J[ZC._[71]]={},ZC._cp_(a,J[ZC._[71]]));var R=O;J.tooltip={visible:!1,"background-color":"#fff",color:"#333","border-width":1,"border-color":"#999",padding:10,text:R},null!==ZC._n_(Z.style)&&null!==ZC._n_(a=Z.style.tooltip)&&ZC._cp_(a,J.tooltip),J.tooltip.text=J.tooltip.text.replace("%text",O).replace("%hits",v[o].hits),A.oWordsMap&&null!==ZC._n_(A.oWordsMap[O])&&(ZC._cp_(A.oWordsMap[O],J),ZC._cp_(A.oWordsMap[O].style,J));var T=0,U=0,K=0,j=A.AFD/2;for("flow-top"===A.CV?K=1:"flow-center"===A.CV&&(K=o%2==0?1:-1),X[o]=0;H&&!W;){var q=v[o].width,$=v[o].height;if("spiral"===A.CV?(k=d+(0===o?0:Y)*ZC.EI(G)-q/2,I=g+(0===o?0:Q)*ZC.EO(G)-$/2):"flow-center"===A.CV?(k=0===o?d-q/2:F.plotarea.x+T,I=g-$/2+U):"flow-top"===A.CV&&(k=0===o?d-q/2:F.plotarea.x+T,I=F.plotarea.y+U),90===S&&"flow-top"===A.CV&&(I=ZC.BQ(I,F.plotarea.y+$)),J.x=ZC._i_(k),J.y=ZC._i_(I),H=!1,90===S){var tt=q;k=ZC._i_(k+q/2-$/2),I=ZC._i_(I+$/2-q/2),q=$,$=tt}if(k<F.plotarea.x||k+q>F.plotarea.x+F.plotarea.width||I<F.plotarea.y||I+$>F.plotarea.y+F.plotarea.height)if("spiral"===A.CV){if(!(X[o]<200)){L=!0,W=!0;break}X[o]++,H=!0}else if("flow-top"===A.CV||"flow-center"===A.CV){if(k+q>F.plotarea.x+F.plotarea.width&&(H=!0,T=-j,U+=K*j),I+$>F.plotarea.y+F.plotarea.height){L=!0;break}if(I<F.plotarea.y){L=!0;break}}if(M={iX:k,iY:I,I:q,F:$,DG:Math.max(v[o].fontSize-B,A.AFD),AN:v[o].text,GJ:u.GJ},!H)for(r=0,i=c.length;r<i;r++)if(A.intersectRect(c[r],M)){T+=c[r].I,H=!0;break}"spiral"===A.CV?H?(G+=A.AFG)>N+360&&(Y+=A.AFH,Q+=A.AFH*(F.plotarea.height/F.plotarea.width),G=N=5*o%360):(Y=Q=A.AFE/2,G=N=5*o%360):"flow-top"!==A.CV&&"flow-center"!==A.CV||H&&(T+=j)}L||M.iX<F.plotarea.x||M.iX+M.I>F.plotarea.x+F.plotarea.width||M.iY<F.plotarea.y||M.iY+M.F>F.plotarea.y+F.plotarea.height||(c.push(M),s[ZC._[10]].push(J))}"flow-top"!==A.CV&&"flow-center"!==A.CV||v.length>c.length&&(W=!0)}}return e})}();