wordcloud.js
8.68 KB
/*
Highcharts JS v7.2.0 (2019-09-03)
(c) 2016-2019 Highsoft AS
Authors: Jon Arild Nygard
License: www.highcharts.com/license
*/
(function(a){"object"===typeof module&&module.exports?(a["default"]=a,module.exports=a):"function"===typeof define&&define.amd?define("highcharts/modules/wordcloud",["highcharts"],function(h){a(h);a.Highcharts=h;return a}):a("undefined"!==typeof Highcharts?Highcharts:void 0)})(function(a){function h(a,f,z,k){a.hasOwnProperty(f)||(a[f]=k.apply(null,z))}a=a?a._modules:{};h(a,"mixins/draw-point.js",[],function(){var a=function(f){var a=this,k=a.graphic,r=f.animatableAttribs,t=f.onComplete,h=f.css,x=
f.renderer;if(a.shouldDraw())k||(a.graphic=k=x[f.shapeType](f.shapeArgs).add(f.group)),k.css(h).attr(f.attribs).animate(r,f.isNew?!1:void 0,t);else if(k){var m=function(){a.graphic=k=k.destroy();"function"===typeof t&&t()};Object.keys(r).length?k.animate(r,void 0,function(){m()}):m()}};return function(f){(f.attribs=f.attribs||{})["class"]=this.getClassName();a.call(this,f)}});h(a,"mixins/polygon.js",[a["parts/Globals.js"],a["parts/Utilities.js"]],function(a,f){var r=f.isArray,k=f.isNumber,h=a.deg2rad,
t=a.find,C=function(b,c){c=k(c)?c:14;c=Math.pow(10,c);return Math.round(b*c)/c},x=function(b,c){var w=c[0]-b[0];b=c[1]-b[1];return[[-b,w],[b,-w]]},m=function(b,c){b=b.map(function(b){return b[0]*c[0]+b[1]*c[1]});return{min:Math.min.apply(this,b),max:Math.max.apply(this,b)}},D=function(b,c){var a=b[0];b=b[1];var n=h*-c;c=Math.cos(n);n=Math.sin(n);return[C(a*c-b*n),C(a*n+b*c)]},y=function(b,c,a){b=D([b[0]-c[0],b[1]-c[1]],a);return[b[0]+c[0],b[1]+c[1]]},A=function(b){var c=b.axes;if(!r(c)){c=[];var a=
a=b.concat([b[0]]);a.reduce(function(b,a){var f=x(b,a)[0];t(c,function(c){return c[0]===f[0]&&c[1]===f[1]})||c.push(f);return a});b.axes=c}return c},E=function(b,c){b=A(b);c=A(c);return b.concat(c)};return{getBoundingBoxFromPolygon:function(b){return b.reduce(function(c,b){var a=b[0];b=b[1];c.left=Math.min(a,c.left);c.right=Math.max(a,c.right);c.bottom=Math.max(b,c.bottom);c.top=Math.min(b,c.top);return c},{left:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE,top:Number.MAX_VALUE})},
getPolygon:function(b,c,a,f,k){var n=[b,c],r=b-a/2;b+=a/2;a=c-f/2;c+=f/2;return[[r,a],[b,a],[b,c],[r,c]].map(function(c){return y(c,n,-k)})},isPolygonsColliding:function(b,c){var a=E(b,c);return!t(a,function(a){var f=m(b,a);a=m(c,a);return!!(a.min>f.max||a.max<f.min)})},movePolygon:function(a,c,f){return f.map(function(b){return[b[0]+a,b[1]+c]})},rotate2DToOrigin:D,rotate2DToPoint:y}});h(a,"modules/wordcloud.src.js",[a["parts/Globals.js"],a["parts/Utilities.js"],a["mixins/draw-point.js"],a["mixins/polygon.js"]],
function(a,f,h,k){function r(g,d){var e=!1,a=g.rect,c=g.polygon,b=g.lastCollidedWith,f=function(d){var e=d.rect;(e=!(e.left>a.right||e.right<a.left||e.top>a.bottom||e.bottom<a.top))&&(g.rotation%90||d.roation%90)&&(e=F(c,d.polygon));return e};b&&((e=f(b))||delete g.lastCollidedWith);e||(e=!!I(d,function(d){var e=f(d);e&&(g.lastCollidedWith=d);return e}));return e}function t(g){var d=4*g,e=Math.ceil((Math.sqrt(d)-1)/2),a=2*e+1,c=Math.pow(a,2),b=!1;--a;1E4>=g&&("boolean"===typeof b&&d>=c-a&&(b={x:e-
(c-d),y:-e}),c-=a,"boolean"===typeof b&&d>=c-a&&(b={x:-e,y:-e+(c-d)}),c-=a,"boolean"===typeof b&&(b=d>=c-a?{x:-e+(c-d),y:e}:{x:e,y:e-(c-d-a)}),b.x*=5,b.y*=5);return b}function C(g,d,e){var a=2*Math.max(Math.abs(e.top),Math.abs(e.bottom));e=2*Math.max(Math.abs(e.left),Math.abs(e.right));return Math.min(0<e?1/e*g:1,0<a?1/a*d:1)}function x(g,d,e){e=e.reduce(function(g,d){d=d.dimensions;var a=Math.max(d.width,d.height);g.maxHeight=Math.max(g.maxHeight,d.height);g.maxWidth=Math.max(g.maxWidth,d.width);
g.area+=a*a;return g},{maxHeight:0,maxWidth:0,area:0});e=Math.max(e.maxHeight,e.maxWidth,.85*Math.sqrt(e.area));var a=g>d?g/d:1;g=d>g?d/g:1;return{width:e*a,height:e*g,ratioX:a,ratioY:g}}function m(g,d,a,b){var e=!1;c(g)&&c(d)&&c(a)&&c(b)&&0<g&&-1<d&&b>a&&(e=a+d%g*((b-a)/(g-1||1)));return e}function D(g,d){var a,c=[];for(a=1;1E4>a;a++)c.push(g(a,d));return function(a){return 1E4>=a?c[a-1]:!1}}function y(a,d){var g=d.width/2,c=-(d.height/2),b=d.height/2;return!(-(d.width/2)<a.left&&g>a.right&&c<a.top&&
b>a.bottom)}function A(a,d){var g=d.placed,c=d.field,b=d.rectangle,f=d.polygon,k=d.spiral,h=1,q={x:0,y:0},p=a.rect=n({},b);a.polygon=f;for(a.rotation=d.rotation;!1!==q&&(r(a,g)||y(p,c));)q=k(h),w(q)&&(p.left=b.left+q.x,p.right=b.right+q.x,p.top=b.top+q.y,p.bottom=b.bottom+q.y,a.polygon=L(q.x,q.y,f)),h++;return q}function E(a,d){if(w(a)&&w(d)){var c=d.bottom-d.top;var g=d.right-d.left;d=a.ratioX;var b=a.ratioY;c=g*d>c*b?g:c;a=z(a,{width:a.width+c*d*2,height:a.height+c*b*2})}return a}var b=f.isArray,
c=f.isNumber,w=f.isObject,n=a.extend,z=a.merge;f=a.noop;var I=a.find,J=k.getBoundingBoxFromPolygon,K=k.getPolygon,F=k.isPolygonsColliding,L=k.movePolygon,B=a.Series;a.seriesType("wordcloud","column",{allowExtendPlayingField:!0,animation:{duration:500},borderWidth:0,clip:!1,colorByPoint:!0,minFontSize:1,maxFontSize:25,placementStrategy:"center",rotation:{from:0,orientations:2,to:90},showInLegend:!1,spiral:"rectangular",style:{fontFamily:"sans-serif",fontWeight:"900",whiteSpace:"nowrap"},tooltip:{followPointer:!0,
pointFormat:'<span style="color:{point.color}">\u25cf</span> {series.name}: <b>{point.weight}</b><br/>'}},{animate:B.prototype.animate,animateDrilldown:f,animateDrillupFrom:f,setClip:f,bindAxes:function(){var a={endOnTick:!1,gridLineWidth:0,lineWidth:0,maxPadding:0,startOnTick:!1,title:null,tickPositions:[]};B.prototype.bindAxes.call(this);n(this.yAxis.options,a);n(this.xAxis.options,a)},pointAttribs:function(c,d){c=a.seriesTypes.column.prototype.pointAttribs.call(this,c,d);delete c.stroke;delete c["stroke-width"];
return c},deriveFontSize:function(a,d,b){a=c(a)?a:0;d=c(d)?d:1;b=c(b)?b:1;return Math.floor(Math.max(b,a*d))},drawPoints:function(){var a=this,d=a.hasRendered,b=a.xAxis,f=a.yAxis,k=a.group,h=a.options,r=h.animation,t=h.allowExtendPlayingField,q=a.chart.renderer,p=q.text().add(k),m=[],y=a.placementStrategy[h.placementStrategy],z=h.rotation,F=a.points.map(function(a){return a.weight}),B=Math.max.apply(null,F),G=a.points.sort(function(a,c){return c.weight-a.weight});G.forEach(function(c){var d=a.deriveFontSize(1/
B*c.weight,h.maxFontSize,h.minFontSize);d=n({fontSize:d+"px"},h.style);p.css(d).attr({x:0,y:0,text:c.name});d=p.getBBox(!0);c.dimensions={height:d.height,width:d.width}});var u=x(b.len,f.len,G);var H=D(a.spirals[h.spiral],{field:u});G.forEach(function(b){var g=a.deriveFontSize(1/B*b.weight,h.maxFontSize,h.minFontSize);g=n({fontSize:g+"px"},h.style);var e=y(b,{data:G,field:u,placed:m,rotation:z}),f=n(a.pointAttribs(b,b.selected&&"select"),{align:"center","alignment-baseline":"middle",x:e.x,y:e.y,text:b.name,
rotation:e.rotation}),p=K(e.x,e.y,b.dimensions.width,b.dimensions.height,e.rotation),l=J(p),v=A(b,{rectangle:l,polygon:p,field:u,placed:m,spiral:H,rotation:e.rotation});!v&&t&&(u=E(u,l),v=A(b,{rectangle:l,polygon:p,field:u,placed:m,spiral:H,rotation:e.rotation}));if(w(v)){f.x+=v.x;f.y+=v.y;l.left+=v.x;l.right+=v.x;l.top+=v.y;l.bottom+=v.y;e=u;if(!c(e.left)||e.left>l.left)e.left=l.left;if(!c(e.right)||e.right<l.right)e.right=l.right;if(!c(e.top)||e.top>l.top)e.top=l.top;if(!c(e.bottom)||e.bottom<l.bottom)e.bottom=
l.bottom;u=e;m.push(b);b.isNull=!1}else b.isNull=!0;if(r){var x={x:f.x,y:f.y};d?(delete f.x,delete f.y):(f.x=0,f.y=0)}b.draw({animatableAttribs:x,attribs:f,css:g,group:k,renderer:q,shapeArgs:void 0,shapeType:"text"})});p=p.destroy();b=C(b.len,f.len,u);a.group.attr({scaleX:b,scaleY:b})},hasData:function(){return w(this)&&!0===this.visible&&b(this.points)&&0<this.points.length},placementStrategy:{random:function(a,b){var c=b.field;b=b.rotation;return{x:Math.round(c.width*(Math.random()+.5)/2)-c.width/
2,y:Math.round(c.height*(Math.random()+.5)/2)-c.height/2,rotation:m(b.orientations,a.index,b.from,b.to)}},center:function(a,b){b=b.rotation;return{x:0,y:0,rotation:m(b.orientations,a.index,b.from,b.to)}}},pointArrayMap:["weight"],spirals:{archimedean:function(a,b){var c=b.field;b=!1;c=c.width*c.width+c.height*c.height;var d=.8*a;1E4>=a&&(b={x:d*Math.cos(d),y:d*Math.sin(d)},Math.min(Math.abs(b.x),Math.abs(b.y))<c||(b=!1));return b},rectangular:function(a,b){a=t(a,b);b=b.field;a&&(a.x*=b.ratioX,a.y*=
b.ratioY);return a},square:t},utils:{extendPlayingField:E,getRotation:m,isPolygonsColliding:F,rotate2DToOrigin:k.rotate2DToOrigin,rotate2DToPoint:k.rotate2DToPoint},getPlotBox:function(){var a=this.chart,b=a.inverted,c=this[b?"yAxis":"xAxis"];b=this[b?"xAxis":"yAxis"];return{translateX:(c?c.left:a.plotLeft)+(c?c.len:a.plotWidth)/2,translateY:(b?b.top:a.plotTop)+(b?b.len:a.plotHeight)/2,scaleX:1,scaleY:1}}},{draw:h,shouldDraw:function(){return!this.isNull},isValid:function(){return!0},weight:1})});
h(a,"masters/modules/wordcloud.src.js",[],function(){})});
//# sourceMappingURL=wordcloud.js.map