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.85 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.16-hf1_ES6 */ zingchart.setModule("wordcloud"),function(){var t;ZC.AFW=((t=function(){this.AFD=9,this.AFE=99,this.AFF=2,this.EJ=100,this.AFG=15,this.AFH=5,this.A01=!1,this.DP="word",this.ACG=[],this.AK="",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.EY=function(){var t,e,a={};if(""!==this.AK){if("word"===this.DP)t=this.AK.replace(/[\:\;\,\.\{\}\[\]\(\)\?\!\/\=\+\-]/g," ").split(" ");else if("character"===this.DP)for(this.AFF=0,t=[],e=0;e<this.AK.length;e++)" "!==this.AK[e]&&t.push(this.AK[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.B6,a),t.O5[e]&&ZC._cp_(t.O5[e],a),a},t.B6={palette:["#6a921f","#007fa3","#a62b02","#b79007","#563d02","#0b32a0"]},t.O5={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),A={};for(s.options&&(A=s.options[h]||s.options),ZC._todash_(A,!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 Z=new ZC.AFW;null!==ZC._n_(a=A.text)&&(Z.AK=a),null!==ZC._n_(a=A.words)&&(Z.aWords=a),null!==ZC._n_(a=A.aspect)&&(Z.CV=a),null!==ZC._n_(a=A.ignore)&&(Z.ACG=a),null!==ZC._n_(a=A.token)&&(Z.DP=a),null!==ZC._n_(a=A["min-length"])&&(Z.AFF=ZC._i_(a)),null!==ZC._n_(a=A["min-font-size"])&&(Z.AFD=ZC._i_(a)),null!==ZC._n_(a=A["max-font-size"])&&(Z.AFE=ZC._i_(a)),null!==ZC._n_(a=A["max-items"])&&(Z.EJ=ZC._i_(a)),null!==ZC._n_(a=A["color-type"])&&(Z.AF9=a),null!==ZC._n_(a=A.color)&&(Z.C2=ZC.AP.GF(a)),null!==ZC._n_(a=A.palette)?Z.BP=a:Z.BP=p.palette,null!==ZC._n_(a=A["step-angle"])&&(Z.AFG=ZC._i_(a)),null!==ZC._n_(a=A["step-radius"])&&(Z.AFH=ZC._i_(a)),null!==ZC._n_(a=A.rotate)&&(Z.A01=ZC._b_(a)),null!==ZC._n_(a=A.normalize)&&(Z.bNormalize=ZC._b_(a));var f={};null!==ZC._n_(a=A.style)&&ZC._cp_(a,f);var u=zingchart.getInstance(n,"textbox");u.append(f),u.parse(),Z.AFD=ZC.BR(4,Z.AFD),Z.AFE=ZC.BR(4,Z.AFE),Z.AFD>=Z.AFE&&(Z.AFE=Z.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"===Z.CV?E=Z.A01?.65:.55:"flow-top"!==Z.CV&&"flow-center"!==Z.CV||(Z.A01=!1,E=.75);var w=F.plotarea.width*F.plotarea.height*E,x=Z.EY(),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!==Z.EJ&&v.splice(Z.EJ,v.length-Z.EJ),o=0;o<v.length;o++)D=ZC.BR(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(Z.AFD,ZC._i_(Z.AFD+v[o].count/100*(Z.AFE-Z.AFD))-t),v[o].width=ZC.Q.A4Y(n.K,v[o].text,u.GL,v[o].fontSize,u.sFontWeight,u.FN)+u.EN+u.FO,v[o].height=1.1*v[o].fontSize+u.FK+u.FT};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,Z.AFE--,Z.AFE<=Z.AFD+4&&Z.AFD--,m(0),(Z.AFD<5||Z.AFE<5)&&(y=!0))}null===ZC._n_(A["step-radius"])&&(Z.AFH=(Z.AFE-Z.AFD+.25*Z.AFD*Z.AFF+1)/10);for(var W=!0,B=-1;W&&B<Z.AFE-Z.AFD;){c=[],s[ZC._[10]]=[],m(B+=1),W=!1;var M,G=0,K=0,X=Z.AFE/2,Y=Z.AFE/2,L=[];for(o=0,l=v.length;o<l;o++){var P=!0,k=d,N=g,I=Z.C2;switch(Z.AF9){case"random":I=Z.AGQ();break;case"palette":I=Z.BP[o%Z.BP.length]}var H=Z.A01?o%4==0||o%4==3?0:90:0,R=!1,S=v[o].text,J={padding:0,dataWordCloud:!0};ZC._cp_(f,J),ZC._cp_({angle:H,"font-size":Math.max(Z.AFD,v[o].fontSize-B),text:S,color:I},J),null!==ZC._n_(A.style)&&null!==ZC._n_(a=A.style[ZC._[71]])&&(J[ZC._[71]]={},ZC._cp_(a,J[ZC._[71]]));var O=S;J.tooltip={visible:!1,"background-color":"#fff",color:"#333","border-width":1,"border-color":"#999",padding:10,text:O},null!==ZC._n_(A.style)&&null!==ZC._n_(a=A.style.tooltip)&&ZC._cp_(a,J.tooltip),J.tooltip.text=J.tooltip.text.replace("%text",S).replace("%hits",v[o].hits),Z.oWordsMap&&null!==ZC._n_(Z.oWordsMap[S])&&(ZC._cp_(Z.oWordsMap[S],J),ZC._cp_(Z.oWordsMap[S].style,J));var Q=0,U=0,T=0,j=Z.AFD/2;for("flow-top"===Z.CV?T=1:"flow-center"===Z.CV&&(T=o%2==0?1:-1),L[o]=0;P&&!W;){var q=v[o].width,$=v[o].height;if("spiral"===Z.CV?(k=d+(0===o?0:X)*ZC.EE(G)-q/2,N=g+(0===o?0:Y)*ZC.EL(G)-$/2):"flow-center"===Z.CV?(k=0===o?d-q/2:F.plotarea.x+Q,N=g-$/2+U):"flow-top"===Z.CV&&(k=0===o?d-q/2:F.plotarea.x+Q,N=F.plotarea.y+U),90===H&&"flow-top"===Z.CV&&(N=ZC.BR(N,F.plotarea.y+$)),J.x=ZC._i_(k),J.y=ZC._i_(N),P=!1,90===H){var tt=q;k=ZC._i_(k+q/2-$/2),N=ZC._i_(N+$/2-q/2),q=$,$=tt}if(k<F.plotarea.x||k+q>F.plotarea.x+F.plotarea.width||N<F.plotarea.y||N+$>F.plotarea.y+F.plotarea.height)if("spiral"===Z.CV){if(!(L[o]<200)){R=!0,W=!0;break}L[o]++,P=!0}else if("flow-top"===Z.CV||"flow-center"===Z.CV){if(k+q>F.plotarea.x+F.plotarea.width&&(P=!0,Q=-j,U+=T*j),N+$>F.plotarea.y+F.plotarea.height){R=!0;break}if(N<F.plotarea.y){R=!0;break}}if(M={iX:k,iY:N,I:q,F:$,DH:Math.max(v[o].fontSize-B,Z.AFD),AK:v[o].text,GL:u.GL},!P)for(r=0,i=c.length;r<i;r++)if(Z.intersectRect(c[r],M)){Q+=c[r].I,P=!0;break}"spiral"===Z.CV?P?(G+=Z.AFG)>K+360&&(X+=Z.AFH,Y+=Z.AFH*(F.plotarea.height/F.plotarea.width),G=K=5*o%360):(X=Y=Z.AFE/2,G=K=5*o%360):"flow-top"!==Z.CV&&"flow-center"!==Z.CV||P&&(Q+=j)}R||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"!==Z.CV&&"flow-center"!==Z.CV||v.length>c.length&&(W=!0)}}return e})}();