window.setImmediate||(window.setImmediate=function(){return window.msSetImmediate||window.webkitSetImmediate||window.mozSetImmediate||window.oSetImmediate||function(){if(!window.postMessage||!window.addEventListener)return null;var t=[void 0],e="zero-timeout-message",a=function(a){var i=t.length;return t.push(a),window.postMessage(e+i.toString(36),"*"),i};return window.addEventListener("message",(function(a){if("string"===typeof a.data&&a.data.substr(0,e.length)===e){a.stopImmediatePropagation();var i=parseInt(a.data.substr(e.length),36);t[i]&&(t[i](),t[i]=void 0)}}),!0),window.clearImmediate=function(e){t[e]&&(t[e]=void 0)},a}()||function(t){window.setTimeout(t,0)}}()),window.clearImmediate||(window.clearImmediate=function(){return window.msClearImmediate||window.webkitClearImmediate||window.mozClearImmediate||window.oClearImmediate||function(t){window.clearTimeout(t)}}());var n=function(){var t=document.createElement("canvas");if(!t||!t.getContext)return!1;var e=t.getContext("2d");return!!e.getImageData&&(!!e.fillText&&(!!Array.prototype.some&&!!Array.prototype.push))}(),o=function(){if(n){var t,e,a=document.createElement("canvas").getContext("2d"),i=20;while(i){if(a.font=i.toString(10)+"px sans-serif",a.measureText("W").width===t&&a.measureText("m").width===e)return i+1;t=a.measureText("W").width,e=a.measureText("m").width,i--}return 0}}(),r=function(t){for(var e,a,i=t.length;i;e=Math.floor(Math.random()*i),a=t[--i],t[i]=t[e],t[e]=a);return t},l=function(t,e){if(n){Array.isArray(t)||(t=[t]),t.forEach((function(e,a){if("string"===typeof e){if(t[a]=document.getElementById(e),!t[a])throw"The element id specified is not found."}else if(!e.tagName&&!e.appendChild)throw"You must pass valid HTML elements, or ID of the element."}));var a={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,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(e)for(var i in e)i in a&&(a[i]=e[i]);if("function"!==typeof a.weightFactor){var l=a.weightFactor;a.weightFactor=function(t){return t*l}}if("function"!==typeof a.shape)switch(a.shape){case"circle":default:a.shape="circle";break;case"cardioid":a.shape=function(t){return 1-Math.sin(t)};break;case"diamond":case"square":a.shape=function(t){var e=t%(2*Math.PI/4);return 1/(Math.cos(e)+Math.sin(e))};break;case"triangle-forward":a.shape=function(t){var e=t%(2*Math.PI/3);return 1/(Math.cos(e)+Math.sqrt(3)*Math.sin(e))};break;case"triangle":case"triangle-upright":a.shape=function(t){var e=(t+3*Math.PI/2)%(2*Math.PI/3);return 1/(Math.cos(e)+Math.sqrt(3)*Math.sin(e))};break;case"pentagon":a.shape=function(t){var e=(t+.955)%(2*Math.PI/5);return 1/(Math.cos(e)+.726543*Math.sin(e))};break;case"star":a.shape=function(t){var e=(t+.955)%(2*Math.PI/10);return(t+.955)%(2*Math.PI/5)-2*Math.PI/10>=0?1/(Math.cos(2*Math.PI/10-e)+3.07768*Math.sin(2*Math.PI/10-e)):1/(Math.cos(e)+3.07768*Math.sin(e))};break}a.gridSize=Math.max(Math.floor(a.gridSize),4);var s,d,u,c,f,h,m,g=a.gridSize,w=g-a.maskGapWidth,v=Math.abs(a.maxRotation-a.minRotation),p=Math.min(a.maxRotation,a.minRotation),y=a.rotationStep;switch(a.color){case"random-dark":m=function(){return X(10,50)};break;case"random-light":m=function(){return X(50,90)};break;default:"function"===typeof a.color&&(m=a.color);break}var x=null;"function"===typeof a.classes&&(x=a.classes);var M,S=!1,b=[],I=function(t){var e,a,i=t.currentTarget,n=i.getBoundingClientRect();t.touches?(e=t.touches[0].clientX,a=t.touches[0].clientY):(e=t.clientX,a=t.clientY);var o=e-n.left,r=a-n.top,l=Math.floor(o*(i.width/n.width||1)/g),s=Math.floor(r*(i.height/n.height||1)/g);return b[l][s]},T=function(t){var e=I(t);M!==e&&(M=e,e?a.hover(e.item,e.dimension,t):a.hover(void 0,void 0,t))},C=function(t){var e=I(t);e&&(a.click(e.item,e.dimension,t),t.preventDefault())},k=[],E=function(t){if(k[t])return k[t];var e=8*t,i=e,n=[];0===t&&n.push([c[0],c[1],0]);while(i--){var o=1;"circle"!==a.shape&&(o=a.shape(i/e*2*Math.PI)),n.push([c[0]+t*o*Math.cos(-i/e*2*Math.PI),c[1]+t*o*Math.sin(-i/e*2*Math.PI)*a.ellipticity,i/e*2*Math.PI])}return k[t]=n,n},R=function(){return a.abortThreshold>0&&(new Date).getTime()-h>a.abortThreshold},O=function(){return 0===a.rotateRatio||Math.random()>a.rotateRatio?0:0===v?p:p+Math.round(Math.random()*v/y)*y},D=function(t,e,i){var n=!1,r=a.weightFactor(e);if(r<=a.minSize)return!1;var l=1;r<o&&(l=function(){var t=2;while(t*r<o)t+=2;return t}());var s=document.createElement("canvas"),d=s.getContext("2d",{willReadFrequently:!0});d.font=a.fontWeight+" "+(r*l).toString(10)+"px "+a.fontFamily;var u=d.measureText(t).width/l,c=Math.max(r*l,d.measureText("m").width,d.measureText("W").width)/l,f=u+2*c,h=3*c,m=Math.ceil(f/g),w=Math.ceil(h/g);f=m*g,h=w*g;var v=-u/2,p=.4*-c,y=Math.ceil((f*Math.abs(Math.sin(i))+h*Math.abs(Math.cos(i)))/g),x=Math.ceil((f*Math.abs(Math.cos(i))+h*Math.abs(Math.sin(i)))/g),M=x*g,S=y*g;s.setAttribute("width",M),s.setAttribute("height",S),n&&(document.body.appendChild(s),d.save()),d.scale(1/l,1/l),d.translate(M*l/2,S*l/2),d.rotate(-i),d.font=a.fontWeight+" "+(r*l).toString(10)+"px "+a.fontFamily,d.fillStyle="#000",d.textBaseline="middle",d.fillText(t,v*l,(p+.5*r)*l);var b=d.getImageData(0,0,M,S).data;if(R())return!1;n&&(d.strokeRect(v*l,p,u*l,c*l),d.restore());var I,T,C,k=[],E=x,O=[y/2,x/2,y/2,x/2];while(E--){I=y;while(I--){C=g;t:{while(C--){T=g;while(T--)if(b[4*((I*g+C)*M+(E*g+T))+3]){k.push([E,I]),E<O[3]&&(O[3]=E),E>O[1]&&(O[1]=E),I<O[0]&&(O[0]=I),I>O[2]&&(O[2]=I),n&&(d.fillStyle="rgba(255, 0, 0, 0.5)",d.fillRect(E*g,I*g,g-.5,g-.5));break t}}n&&(d.fillStyle="rgba(0, 0, 255, 0.5)",d.fillRect(E*g,I*g,g-.5,g-.5))}}}return n&&(d.fillStyle="rgba(0, 255, 0, 0.5)",d.fillRect(O[3]*g,O[0]*g,(O[1]-O[3]+1)*g,(O[2]-O[0]+1)*g)),{mu:l,occupied:k,bounds:O,gw:x,gh:y,fillTextOffsetX:v,fillTextOffsetY:p,fillTextWidth:u,fillTextHeight:c,fontSize:r}},A=function(t,e,i,n,o){var r=o.length;while(r--){var l=t+o[r][0],c=e+o[r][1];if(l>=d||c>=u||l<0||c<0){if(!a.drawOutOfBound)return!1}else if(!s[l][c])return!1}return!0},z=function(e,i,n,o,r,l,s,d,u){var c,f,h=n.fontSize;c=m?m(o,r,h,l,s):a.color,f=x?x(o,r,h,l,s):a.classes;var w=n.bounds;w[3],w[0],w[1],w[3],w[2],w[0],t.forEach((function(t){if(t.getContext){var r=t.getContext("2d"),l=n.mu;r.save(),r.scale(1/l,1/l),r.font=a.fontWeight+" "+(h*l).toString(10)+"px "+a.fontFamily,r.fillStyle=c,r.translate((e+n.gw/2)*g*l,(i+n.gh/2)*g*l),0!==d&&r.rotate(-d),r.textBaseline="middle",r.fillText(o,n.fillTextOffsetX*l,(n.fillTextOffsetY+.5*h)*l),r.restore()}else{var s=document.createElement("span"),m="";m="rotate("+-d/Math.PI*180+"deg) ",1!==n.mu&&(m+="translateX(-"+n.fillTextWidth/4+"px) scale("+1/n.mu+")");var w={position:"absolute",display:"block",font:a.fontWeight+" "+h*n.mu+"px "+a.fontFamily,left:(e+n.gw/2)*g+n.fillTextOffsetX+"px",top:(i+n.gh/2)*g+n.fillTextOffsetY+"px",width:n.fillTextWidth+"px",height:n.fillTextHeight+"px",lineHeight:h+"px",whiteSpace:"nowrap",transform:m,webkitTransform:m,msTransform:m,transformOrigin:"50% 40%",webkitTransformOrigin:"50% 40%",msTransformOrigin:"50% 40%"};for(var v in c&&(w.color=c),s.textContent=o,w)s.style[v]=w[v];if(u)for(var p in u)s.setAttribute(p,u[p]);f&&(s.className+=f),t.appendChild(s)}}))},P=function(e,a,i,n,o){if(!(e>=d||a>=u||e<0||a<0)){if(s[e][a]=!1,i){var r=t[0].getContext("2d");r.fillRect(e*g,a*g,w,w)}S&&(b[e][a]={item:o,dimension:n})}},F=function(e,i,n,o,r,l){var s,c,f=r.occupied,h=a.drawMask;if(h&&(s=t[0].getContext("2d"),s.save(),s.fillStyle=a.maskColor),S){var m=r.bounds;c={x:(e+m[3])*g,y:(i+m[0])*g,w:(m[1]-m[3]+1)*g,h:(m[2]-m[0]+1)*g}}var w=f.length;while(w--){var v=e+f[w][0],p=i+f[w][1];v>=d||p>=u||v<0||p<0||P(v,p,h,c,l)}h&&s.restore()},L=function(t){var e,i,n;Array.isArray(t)?(e=t[0],i=t[1]):(e=t.word,i=t.weight,n=t.attributes);var o=O(),l=D(e,i,o);if(!l)return!1;if(R())return!1;if(!a.drawOutOfBound){var s=l.bounds;if(s[1]-s[3]+1>d||s[2]-s[0]+1>u)return!1}var c=f+1,h=function(a){var r=Math.floor(a[0]-l.gw/2),s=Math.floor(a[1]-l.gh/2),d=l.gw,u=l.gh;return!!A(r,s,d,u,l.occupied)&&(z(r,s,l,e,i,f-c,a[2],o,n),F(r,s,d,u,l,t),{gx:r,gy:s,rot:o,info:l})};while(c--){var m=E(f-c);a.shuffle&&(m=[].concat(m),r(m));for(var g=0;g<m.length;g++){var w=h(m[g]);if(w)return w}}return null},W=function(e,a,i){if(a)return!t.some((function(t){var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,!0,a,i||{}),!t.dispatchEvent(n)}),this);t.forEach((function(t){var n=document.createEvent("CustomEvent");n.initCustomEvent(e,!0,a,i||{}),t.dispatchEvent(n)}),this)},B=function(){var e=t[0];if(e.getContext)d=Math.ceil(e.width/g),u=Math.ceil(e.height/g);else{var i=e.getBoundingClientRect();d=Math.ceil(i.width/g),u=Math.ceil(i.height/g)}if(W("wordcloudstart",!0)){var n,o,r,l,m;if(c=a.origin?[a.origin[0]/g,a.origin[1]/g]:[d/2,u/2],f=Math.floor(Math.sqrt(d*d+u*u)),s=[],!e.getContext||a.clearCanvas){t.forEach((function(t){if(t.getContext){var e=t.getContext("2d");e.fillStyle=a.backgroundColor,e.clearRect(0,0,d*(g+1),u*(g+1)),e.fillRect(0,0,d*(g+1),u*(g+1))}else t.textContent="",t.style.backgroundColor=a.backgroundColor,t.style.position="relative"})),n=d;while(n--){s[n]=[],o=u;while(o--)s[n][o]=!0}}else{var w=document.createElement("canvas").getContext("2d");w.fillStyle=a.backgroundColor,w.fillRect(0,0,1,1);var v,p,y=w.getImageData(0,0,1,1).data,x=e.getContext("2d").getImageData(0,0,d*g,u*g).data;n=d;while(n--){s[n]=[],o=u;while(o--){p=g;t:while(p--){v=g;while(v--){r=4;while(r--)if(x[4*((o*g+p)*d*g+(n*g+v))+r]!==y[r]){s[n][o]=!1;break t}}}!1!==s[n][o]&&(s[n][o]=!0)}}x=w=y=void 0}if(a.hover||a.click){S=!0,n=d+1;while(n--)b[n]=[];a.hover&&e.addEventListener("mousemove",T),a.click&&(e.addEventListener("click",C),e.addEventListener("touchstart",C),e.addEventListener("touchend",(function(t){t.preventDefault()})),e.style.webkitTapHighlightColor="rgba(0, 0, 0, 0)"),e.addEventListener("wordcloudstart",(function t(){e.removeEventListener("wordcloudstart",t),e.removeEventListener("mousemove",T),e.removeEventListener("click",C),M=void 0}))}r=0;var I=!0;a.layoutAnimation?0!==a.wait?(l=window.setTimeout,m=window.clearTimeout):(l=window.setImmediate,m=window.clearImmediate):(l=function(t){t()},m=function(){I=!1});var k=function(e,a){t.forEach((function(t){t.addEventListener(e,a)}),this)},E=function(e,a){t.forEach((function(t){t.removeEventListener(e,a)}),this)},O=function t(){E("wordcloudstart",t),m(D)};k("wordcloudstart",O);var D=(a.layoutAnimation?l:setTimeout)((function t(){if(I){if(r>=a.list.length)return m(D),W("wordcloudstop",!1),void E("wordcloudstart",O);h=(new Date).getTime();var e=L(a.list[r]),i=!W("wordclouddrawn",!0,{item:a.list[r],drawn:e});if(R()||i)return m(D),a.abort(),W("wordcloudabort",!1),W("wordcloudstop",!1),void E("wordcloudstart",O);r++,D=l(t,a.wait)}}),a.wait)}};B()}function X(t,e){return"hsl("+(360*Math.random()).toFixed()+","+(30*Math.random()+70).toFixed()+"%,"+(Math.random()*(e-t)+t).toFixed()+"%)"}};l.isSupported=n,l.minFontSize=o;var s=l;if(!s.isSupported)throw new Error("Sorry your browser not support wordCloud");function d(t){for(var e=t.getContext("2d"),a=e.getImageData(0,0,t.width,t.height),i=e.createImageData(a),n=0,o=0,r=0;r<a.data.length;r+=4){var l=a.data[r+3];if(l>128){var s=a.data[r]+a.data[r+1]+a.data[r+2];n+=s,++o}}var d=n/o;for(r=0;r<a.data.length;r+=4){s=a.data[r]+a.data[r+1]+a.data[r+2],l=a.data[r+3];l<128||s>d?(i.data[r]=0,i.data[r+1]=0,i.data[r+2]=0,i.data[r+3]=0):(i.data[r]=255,i.data[r+1]=255,i.data[r+2]=255,i.data[r+3]=255)}e.putImageData(i,0,0)}i["h"]((function(t,e){t.eachSeriesByType("wordCloud",(function(a){var n=i["f"].getLayoutRect(a.getBoxLayoutParams(),{width:e.getWidth(),height:e.getHeight()}),o=a.getData(),r=document.createElement("canvas");r.width=n.width,r.height=n.height;var l=r.getContext("2d"),u=a.get("maskImage");if(u)try{l.drawImage(u,0,0,r.width,r.height),d(r)}catch(v){console.error("Invalid mask image"),console.error(v.toString())}var c=a.get("sizeRange"),f=a.get("rotationRange"),h=o.getDataExtent("value"),m=Math.PI/180,g=a.get("gridSize");function w(t){var e=t.detail.item;t.detail.drawn&&a.layoutInstance.ondraw&&(t.detail.drawn.gx+=n.x/g,t.detail.drawn.gy+=n.y/g,a.layoutInstance.ondraw(e[0],e[1],e[2],t.detail.drawn))}s(r,{list:o.mapArray("value",(function(t,e){var a=o.getItemModel(e);return[o.getName(e),a.get("textStyle.fontSize",!0)||i["g"].linearMap(t,h,c),e]})).sort((function(t,e){return e[1]-t[1]})),fontFamily:a.get("textStyle.fontFamily")||a.get("emphasis.textStyle.fontFamily")||t.get("textStyle.fontFamily"),fontWeight:a.get("textStyle.fontWeight")||a.get("emphasis.textStyle.fontWeight")||t.get("textStyle.fontWeight"),gridSize:g,ellipticity:n.height/n.width,minRotation:f[0]*m,maxRotation:f[1]*m,clearCanvas:!u,rotateRatio:1,rotationStep:a.get("rotationStep")*m,drawOutOfBound:a.get("drawOutOfBound"),layoutAnimation:a.get("layoutAnimation"),shuffle:!1,shape:a.get("shape")}),r.addEventListener("wordclouddrawn",w),a.layoutInstance&&a.layoutInstance.dispose(),a.layoutInstance={ondraw:null,dispose:function(){r.removeEventListener("wordclouddrawn",w),r.addEventListener("wordclouddrawn",(function(t){t.preventDefault()}))}}}))})),i["i"]((function(t){var e=(t||{}).series;!i["j"].isArray(e)&&(e=e?[e]:[]);var a=["shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY"];function n(t){t&&i["j"].each(a,(function(e){t.hasOwnProperty(e)&&(t["text"+i["d"].capitalFirst(e)]=t[e])}))}i["j"].each(e,(function(t){if(t&&"wordCloud"===t.type){var e=t.textStyle||{};n(e.normal),n(e.emphasis)}}))}))}}]);
|