8 lines
16 KiB
JavaScript
8 lines
16 KiB
JavaScript
import{c as Ct,S as ht,C as ct,u as gt,a as kt,b as Et,d as bt,e as Ft,f as At,Z as Pt,g as Rt,r as Wt,h as Ot,j as zt,k as vt,l as Dt,m as Lt,n as Bt}from"./index-bf67ebd5.js";function nt(s,r){return r=r||{},Ct(s,null,null,r.state!=="normal")}function Xt(s){var r=ht.extend(s);return ht.registerClass(r),r}function Yt(s){var r=ct.extend(s);return ct.registerClass(r),r}gt([kt,Et]);gt(bt);Xt({type:"series.wordCloud",visualStyleAccessPath:"textStyle",visualStyleMapper:function(s){return{fill:s.get("color")}},visualDrawType:"fill",optionUpdated:function(){var s=this.option;s.gridSize=Math.max(Math.floor(s.gridSize),4)},getInitialData:function(s,r){var a=Ft(s.data,{coordDimensions:["value"]}),l=new At(a,this);return l.initData(s.data),l},defaultOption:{maskImage:null,shape:"circle",keepAspect:!1,left:"center",top:"center",width:"70%",height:"80%",sizeRange:[12,60],rotationRange:[-90,90],rotationStep:45,gridSize:8,drawOutOfBound:!1,shrinkToFit:!1,textStyle:{fontWeight:"normal"}}});Yt({type:"wordCloud",render:function(s,r,a){var l=this.group;l.removeAll();var t=s.getData(),x=s.get("gridSize");s.layoutInstance.ondraw=function(d,i,T,P){var D=t.getItemModel(T),Y=D.getModel("textStyle"),I=new Pt({style:nt(Y),scaleX:1/P.info.mu,scaleY:1/P.info.mu,x:(P.gx+P.info.gw/2)*x,y:(P.gy+P.info.gh/2)*x,rotation:P.rot});I.setStyle({x:P.info.fillTextOffsetX,y:P.info.fillTextOffsetY+i*.5,text:d,verticalAlign:"middle",fill:t.getItemVisual(T,"style").fill,fontSize:i}),l.add(I),t.setItemGraphicEl(T,I),I.ensureState("emphasis").style=nt(D.getModel(["emphasis","textStyle"]),{state:"emphasis"}),I.ensureState("blur").style=nt(D.getModel(["blur","textStyle"]),{state:"blur"}),Rt(I,D.get(["emphasis","focus"]),D.get(["emphasis","blurScope"])),I.stateTransition={duration:s.get("animation")?s.get(["stateAnimation","duration"]):0,easing:s.get(["stateAnimation","easing"])},I.__highDownDispatcher=!0},this._model=s},remove:function(){this.group.removeAll(),this._model.layoutInstance.dispose()},dispose:function(){this._model.layoutInstance.dispose()}});/*!
|
||
* wordcloud2.js
|
||
* http://timdream.org/wordcloud2.js/
|
||
*
|
||
* Copyright 2011 - 2019 Tim Guan-tin Chien and contributors.
|
||
* Released under the MIT license
|
||
*/window.setImmediate||(window.setImmediate=function(){return window.msSetImmediate||window.webkitSetImmediate||window.mozSetImmediate||window.oSetImmediate||function(){if(!window.postMessage||!window.addEventListener)return null;var a=[void 0],l="zero-timeout-message",t=function(d){var i=a.length;return a.push(d),window.postMessage(l+i.toString(36),"*"),i};return window.addEventListener("message",function(d){if(!(typeof d.data!="string"||d.data.substr(0,l.length)!==l)){d.stopImmediatePropagation();var i=parseInt(d.data.substr(l.length),36);a[i]&&(a[i](),a[i]=void 0)}},!0),window.clearImmediate=function(d){a[d]&&(a[d]=void 0)},t}()||function(a){window.setTimeout(a,0)}}());window.clearImmediate||(window.clearImmediate=function(){return window.msClearImmediate||window.webkitClearImmediate||window.mozClearImmediate||window.oClearImmediate||function(a){window.clearTimeout(a)}}());var lt=function(){var r=document.createElement("canvas");if(!r||!r.getContext)return!1;var a=r.getContext("2d");return!(!a||!a.getImageData||!a.fillText||!Array.prototype.some||!Array.prototype.push)}(),ot=function(){if(lt){for(var r=document.createElement("canvas").getContext("2d"),a=20,l,t;a;){if(r.font=a.toString(10)+"px sans-serif",r.measureText("W").width===l&&r.measureText("m").width===t)return a+1;l=r.measureText("W").width,t=r.measureText("m").width,a--}return 0}}(),Gt=function(s){if(Array.isArray(s)){var r=s.slice();return r.splice(0,2),r}else return[]},Ht=function(r){for(var a,l,t=r.length;t;)a=Math.floor(Math.random()*t),l=r[--t],r[t]=r[a],r[a]=l;return r},Z={},$=function(r,a){if(!lt)return;var l=Math.floor(Math.random()*Date.now());Array.isArray(r)||(r=[r]),r.forEach(function(c,e){if(typeof c=="string"){if(r[e]=document.getElementById(c),!r[e])throw new Error("The element id specified is not found.")}else if(!c.tagName&&!c.appendChild)throw new Error("You must pass valid HTML elements, or ID of the element.")});var t={list:[],fontFamily:'"Trebuchet MS", "Heiti TC", "微軟正黑體", "Arial Unicode MS", "Droid Fallback Sans", sans-serif',fontWeight:"normal",color:"random-dark",minSize:0,weightFactor:1,clearCanvas:!0,backgroundColor:"#fff",gridSize:8,drawOutOfBound:!1,shrinkToFit:!1,origin:null,drawMask:!1,maskColor:"rgba(255,0,0,0.3)",maskGapWidth:.3,layoutAnimation:!0,wait:0,abortThreshold:0,abort:function(){},minRotation:-Math.PI/2,maxRotation:Math.PI/2,rotationStep:.1,shuffle:!0,rotateRatio:.1,shape:"circle",ellipticity:.65,classes:null,hover:null,click:null};if(a)for(var x in a)x in t&&(t[x]=a[x]);if(typeof t.weightFactor!="function"){var d=t.weightFactor;t.weightFactor=function(e){return e*d}}if(typeof t.shape!="function")switch(t.shape){case"circle":default:t.shape="circle";break;case"cardioid":t.shape=function(e){return 1-Math.sin(e)};break;case"diamond":t.shape=function(e){var n=e%(2*Math.PI/4);return 1/(Math.cos(n)+Math.sin(n))};break;case"square":t.shape=function(e){return Math.min(1/Math.abs(Math.cos(e)),1/Math.abs(Math.sin(e)))};break;case"triangle-forward":t.shape=function(e){var n=e%(2*Math.PI/3);return 1/(Math.cos(n)+Math.sqrt(3)*Math.sin(n))};break;case"triangle":case"triangle-upright":t.shape=function(e){var n=(e+Math.PI*3/2)%(2*Math.PI/3);return 1/(Math.cos(n)+Math.sqrt(3)*Math.sin(n))};break;case"pentagon":t.shape=function(e){var n=(e+.955)%(2*Math.PI/5);return 1/(Math.cos(n)+.726543*Math.sin(n))};break;case"star":t.shape=function(e){var n=(e+.955)%(2*Math.PI/10);return(e+.955)%(2*Math.PI/5)-2*Math.PI/10>=0?1/(Math.cos(2*Math.PI/10-n)+3.07768*Math.sin(2*Math.PI/10-n)):1/(Math.cos(n)+3.07768*Math.sin(n))};break}t.gridSize=Math.max(Math.floor(t.gridSize),4);var i=t.gridSize,T=i-t.maskGapWidth,P=Math.abs(t.maxRotation-t.minRotation),D=Math.min(t.maxRotation,t.minRotation),Y=t.rotationStep,I,C,b,B,F,O,G;function st(c,e){return"hsl("+(Math.random()*360).toFixed()+","+(Math.random()*30+70).toFixed()+"%,"+(Math.random()*(e-c)+c).toFixed()+"%)"}switch(t.color){case"random-dark":G=function(){return st(10,50)};break;case"random-light":G=function(){return st(50,90)};break;default:typeof t.color=="function"&&(G=t.color);break}var _;typeof t.fontWeight=="function"&&(_=t.fontWeight);var j=null;typeof t.classes=="function"&&(j=t.classes);var J=!1,N=[],K,ft=function(e){var n=e.currentTarget,o=n.getBoundingClientRect(),u,f;e.touches?(u=e.touches[0].clientX,f=e.touches[0].clientY):(u=e.clientX,f=e.clientY);var h=u-o.left,S=f-o.top,g=Math.floor(h*(n.width/o.width||1)/i),m=Math.floor(S*(n.height/o.height||1)/i);return N[g]?N[g][m]:null},ut=function(e){var n=ft(e);if(K!==n){if(K=n,!n){t.hover(void 0,void 0,e);return}t.hover(n.item,n.dimension,e)}},Q=function(e){var n=ft(e);n&&(t.click(n.item,n.dimension,e),e.preventDefault())},tt=[],mt=function(e){if(tt[e])return tt[e];var n=e*8,o=n,u=[];for(e===0&&u.push([B[0],B[1],0]);o--;){var f=1;t.shape!=="circle"&&(f=t.shape(o/n*2*Math.PI)),u.push([B[0]+e*f*Math.cos(-o/n*2*Math.PI),B[1]+e*f*Math.sin(-o/n*2*Math.PI)*t.ellipticity,o/n*2*Math.PI])}return tt[e]=u,u},et=function(){return t.abortThreshold>0&&new Date().getTime()-O>t.abortThreshold},wt=function(){return t.rotateRatio===0||Math.random()>t.rotateRatio?0:P===0?D:D+Math.round(Math.random()*P/Y)*Y},pt=function(e,n,o,u){var f=t.weightFactor(n);if(f<=t.minSize)return!1;var h=1;f<ot&&(h=function(){for(var it=2;it*f<ot;)it+=2;return it}());var S;_?S=_(e,n,f,u):S=t.fontWeight;var g=document.createElement("canvas"),m=g.getContext("2d",{willReadFrequently:!0});m.font=S+" "+(f*h).toString(10)+"px "+t.fontFamily;var A=m.measureText(e).width/h,w=Math.max(f*h,m.measureText("m").width,m.measureText("W").width)/h,p=A+w*2,k=w*3,R=Math.ceil(p/i),W=Math.ceil(k/i);p=R*i,k=W*i;var M=-A/2,v=-w*.4,y=Math.ceil((p*Math.abs(Math.sin(o))+k*Math.abs(Math.cos(o)))/i),E=Math.ceil((p*Math.abs(Math.cos(o))+k*Math.abs(Math.sin(o)))/i),z=E*i,q=y*i;g.setAttribute("width",z),g.setAttribute("height",q),m.scale(1/h,1/h),m.translate(z*h/2,q*h/2),m.rotate(-o),m.font=S+" "+(f*h).toString(10)+"px "+t.fontFamily,m.fillStyle="#000",m.textBaseline="middle",m.fillText(e,M*h,(v+f*.5)*h);var U=m.getImageData(0,0,z,q).data;if(et())return!1;for(var dt=[],H=E,X,at,rt,L=[y/2,E/2,y/2,E/2];H--;)for(X=y;X--;){rt=i;t:for(;rt--;)for(at=i;at--;)if(U[((X*i+rt)*z+(H*i+at))*4+3]){dt.push([H,X]),H<L[3]&&(L[3]=H),H>L[1]&&(L[1]=H),X<L[0]&&(L[0]=X),X>L[2]&&(L[2]=X);break t}}return{mu:h,occupied:dt,bounds:L,gw:E,gh:y,fillTextOffsetX:M,fillTextOffsetY:v,fillTextWidth:A,fillTextHeight:w,fontSize:f}},xt=function(e,n,o,u,f){for(var h=f.length;h--;){var S=e+f[h][0],g=n+f[h][1];if(S>=C||g>=b||S<0||g<0){if(!t.drawOutOfBound)return!1;continue}if(!I[S][g])return!1}return!0},yt=function(e,n,o,u,f,h,S,g,m,A){var w=o.fontSize,p;G?p=G(u,f,w,h,S,A):p=t.color;var k;_?k=_(u,f,w,A):k=t.fontWeight;var R;j?R=j(u,f,w,A):R=t.classes,r.forEach(function(W){if(W.getContext){var M=W.getContext("2d"),v=o.mu;M.save(),M.scale(1/v,1/v),M.font=k+" "+(w*v).toString(10)+"px "+t.fontFamily,M.fillStyle=p,M.translate((e+o.gw/2)*i*v,(n+o.gh/2)*i*v),g!==0&&M.rotate(-g),M.textBaseline="middle",M.fillText(u,o.fillTextOffsetX*v,(o.fillTextOffsetY+w*.5)*v),M.restore()}else{var y=document.createElement("span"),E="";E="rotate("+-g/Math.PI*180+"deg) ",o.mu!==1&&(E+="translateX(-"+o.fillTextWidth/4+"px) scale("+1/o.mu+")");var z={position:"absolute",display:"block",font:k+" "+w*o.mu+"px "+t.fontFamily,left:(e+o.gw/2)*i+o.fillTextOffsetX+"px",top:(n+o.gh/2)*i+o.fillTextOffsetY+"px",width:o.fillTextWidth+"px",height:o.fillTextHeight+"px",lineHeight:w+"px",whiteSpace:"nowrap",transform:E,webkitTransform:E,msTransform:E,transformOrigin:"50% 40%",webkitTransformOrigin:"50% 40%",msTransformOrigin:"50% 40%"};p&&(z.color=p),y.textContent=u;for(var q in z)y.style[q]=z[q];if(m)for(var U in m)y.setAttribute(U,m[U]);R&&(y.className+=R),W.appendChild(y)}})},St=function(e,n,o,u,f){if(!(e>=C||n>=b||e<0||n<0)){if(I[e][n]=!1,o){var h=r[0].getContext("2d");h.fillRect(e*i,n*i,T,T)}J&&(N[e][n]={item:f,dimension:u})}},Tt=function(e,n,o,u,f,h){var S=f.occupied,g=t.drawMask,m;g&&(m=r[0].getContext("2d"),m.save(),m.fillStyle=t.maskColor);var A;if(J){var w=f.bounds;A={x:(e+w[3])*i,y:(n+w[0])*i,w:(w[1]-w[3]+1)*i,h:(w[2]-w[0]+1)*i}}for(var p=S.length;p--;){var k=e+S[p][0],R=n+S[p][1];k>=C||R>=b||k<0||R<0||St(k,R,g,A,h)}g&&m.restore()},Mt=function c(e,n){if(n>20)return null;var o,u,f;Array.isArray(e)?(o=e[0],u=e[1]):(o=e.word,u=e.weight,f=e.attributes);var h=wt(),S=Gt(e),g=pt(o,u,h,S);if(!g||et())return!1;if(!t.drawOutOfBound&&!t.shrinkToFit){var m=g.bounds;if(m[1]-m[3]+1>C||m[2]-m[0]+1>b)return!1}for(var A=F+1,w=function(W){var M=Math.floor(W[0]-g.gw/2),v=Math.floor(W[1]-g.gh/2),y=g.gw,E=g.gh;return xt(M,v,y,E,g.occupied)?(yt(M,v,g,o,u,F-A,W[2],h,f,S),Tt(M,v,y,E,g,e),{gx:M,gy:v,rot:h,info:g}):!1};A--;){var p=mt(F-A);t.shuffle&&(p=[].concat(p),Ht(p));for(var k=0;k<p.length;k++){var R=w(p[k]);if(R)return R}}return t.shrinkToFit?(Array.isArray(e)?e[1]=e[1]*3/4:e.weight=e.weight*3/4,c(e,n+1)):null},V=function(e,n,o){if(n)return!r.some(function(u){var f=new CustomEvent(e,{detail:o||{}});return!u.dispatchEvent(f)},this);r.forEach(function(u){var f=new CustomEvent(e,{detail:o||{}});u.dispatchEvent(f)},this)},It=function(){var e=r[0];if(e.getContext)C=Math.ceil(e.width/i),b=Math.ceil(e.height/i);else{var n=e.getBoundingClientRect();C=Math.ceil(n.width/i),b=Math.ceil(n.height/i)}if(V("wordcloudstart",!0)){B=t.origin?[t.origin[0]/i,t.origin[1]/i]:[C/2,b/2],F=Math.floor(Math.sqrt(C*C+b*b)),I=[];var o,u,f;if(!e.getContext||t.clearCanvas)for(r.forEach(function(v){if(v.getContext){var y=v.getContext("2d");y.fillStyle=t.backgroundColor,y.clearRect(0,0,C*(i+1),b*(i+1)),y.fillRect(0,0,C*(i+1),b*(i+1))}else v.textContent="",v.style.backgroundColor=t.backgroundColor,v.style.position="relative"}),o=C;o--;)for(I[o]=[],u=b;u--;)I[o][u]=!0;else{var h=document.createElement("canvas").getContext("2d");h.fillStyle=t.backgroundColor,h.fillRect(0,0,1,1);var S=h.getImageData(0,0,1,1).data,g=e.getContext("2d").getImageData(0,0,C*i,b*i).data;o=C;for(var m,A;o--;)for(I[o]=[],u=b;u--;){A=i;t:for(;A--;)for(m=i;m--;)for(f=4;f--;)if(g[((u*i+A)*C*i+(o*i+m))*4+f]!==S[f]){I[o][u]=!1;break t}I[o][u]!==!1&&(I[o][u]=!0)}g=h=S=void 0}if(t.hover||t.click){for(J=!0,o=C+1;o--;)N[o]=[];t.hover&&e.addEventListener("mousemove",ut),t.click&&(e.addEventListener("click",Q),e.addEventListener("touchstart",Q),e.addEventListener("touchend",function(v){v.preventDefault()}),e.style.webkitTapHighlightColor="rgba(0, 0, 0, 0)"),e.addEventListener("wordcloudstart",function v(){e.removeEventListener("wordcloudstart",v),e.removeEventListener("mousemove",ut),e.removeEventListener("click",Q),K=void 0})}f=0;var w,p,k=!0;t.layoutAnimation?t.wait!==0?(w=window.setTimeout,p=window.clearTimeout):(w=window.setImmediate,p=window.clearImmediate):(w=function(v){v()},p=function(){k=!1});var R=function(y,E){r.forEach(function(z){z.addEventListener(y,E)},this)},W=function(y,E){r.forEach(function(z){z.removeEventListener(y,E)},this)},M=function v(){W("wordcloudstart",v),p(Z[l])};R("wordcloudstart",M),Z[l]=(t.layoutAnimation?w:setTimeout)(function v(){if(k){if(f>=t.list.length){p(Z[l]),V("wordcloudstop",!1),W("wordcloudstart",M),delete Z[l];return}O=new Date().getTime();var y=Mt(t.list[f],0),E=!V("wordclouddrawn",!0,{item:t.list[f],drawn:y});if(et()||E){p(Z[l]),t.abort(),V("wordcloudabort",!1),V("wordcloudstop",!1),W("wordcloudstart",M);return}f++,Z[l]=w(v,t.wait)}},t.wait)}};It()};$.isSupported=lt;$.minFontSize=ot;if(!$.isSupported)throw new Error("Sorry your browser not support wordCloud");function qt(s){for(var r=s.getContext("2d"),a=r.getImageData(0,0,s.width,s.height),l=r.createImageData(a),t=0,x=0,d=0;d<a.data.length;d+=4){var i=a.data[d+3];if(i>128){var T=a.data[d]+a.data[d+1]+a.data[d+2];t+=T,++x}}for(var P=t/x,d=0;d<a.data.length;d+=4){var T=a.data[d]+a.data[d+1]+a.data[d+2],i=a.data[d+3];i<128||T>P?(l.data[d]=0,l.data[d+1]=0,l.data[d+2]=0,l.data[d+3]=0):(l.data[d]=255,l.data[d+1]=255,l.data[d+2]=255,l.data[d+3]=255)}r.putImageData(l,0,0)}Wt(function(s,r){s.eachSeriesByType("wordCloud",function(a){var l=Dt(a.getBoxLayoutParams(),{width:r.getWidth(),height:r.getHeight()}),t=a.get("keepAspect"),x=a.get("maskImage"),d=x?x.width/x.height:1;t&&Zt(l,d);var i=a.getData(),T=document.createElement("canvas");T.width=l.width,T.height=l.height;var P=T.getContext("2d");if(x)try{P.drawImage(x,0,0,T.width,T.height),qt(T)}catch(F){console.error("Invalid mask image"),console.error(F.toString())}var D=a.get("sizeRange"),Y=a.get("rotationRange"),I=i.getDataExtent("value"),C=Math.PI/180,b=a.get("gridSize");$(T,{list:i.mapArray("value",function(F,O){var G=i.getItemModel(O);return[i.getName(O),G.get("textStyle.fontSize",!0)||Lt(F,I,D),O]}).sort(function(F,O){return O[1]-F[1]}),fontFamily:a.get("textStyle.fontFamily")||a.get("emphasis.textStyle.fontFamily")||s.get("textStyle.fontFamily"),fontWeight:a.get("textStyle.fontWeight")||a.get("emphasis.textStyle.fontWeight")||s.get("textStyle.fontWeight"),gridSize:b,ellipticity:l.height/l.width,minRotation:Y[0]*C,maxRotation:Y[1]*C,clearCanvas:!x,rotateRatio:1,rotationStep:a.get("rotationStep")*C,drawOutOfBound:a.get("drawOutOfBound"),shrinkToFit:a.get("shrinkToFit"),layoutAnimation:a.get("layoutAnimation"),shuffle:!1,shape:a.get("shape")});function B(F){var O=F.detail.item;F.detail.drawn&&a.layoutInstance.ondraw&&(F.detail.drawn.gx+=l.x/b,F.detail.drawn.gy+=l.y/b,a.layoutInstance.ondraw(O[0],O[1],O[2],F.detail.drawn))}T.addEventListener("wordclouddrawn",B),a.layoutInstance&&a.layoutInstance.dispose(),a.layoutInstance={ondraw:null,dispose:function(){T.removeEventListener("wordclouddrawn",B),T.addEventListener("wordclouddrawn",function(F){F.preventDefault()})}}})});Ot(function(s){var r=(s||{}).series;!zt(r)&&(r=r?[r]:[]);var a=["shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY"];vt(r,function(t){if(t&&t.type==="wordCloud"){var x=t.textStyle||{};l(x.normal),l(x.emphasis)}});function l(t){t&&vt(a,function(x){t.hasOwnProperty(x)&&(t["text"+Bt(x)]=t[x])})}});function Zt(s,r){var a=s.width,l=s.height;a>l*r?(s.x+=(a-l*r)/2,s.width=l*r):(s.y+=(l-a/r)/2,s.height=a/r)}
|