wordcloud.js 11 KB

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. Highcharts JS v9.1.1 (2021-06-03)
  3. (c) 2016-2021 Highsoft AS
  4. Authors: Jon Arild Nygard
  5. License: www.highcharts.com/license
  6. */
  7. 'use strict';(function(a){"object"===typeof module&&module.exports?(a["default"]=a,module.exports=a):"function"===typeof define&&define.amd?define("highcharts/modules/wordcloud",["highcharts"],function(l){a(l);a.Highcharts=l;return a}):a("undefined"!==typeof Highcharts?Highcharts:void 0)})(function(a){function l(a,d,h,z){a.hasOwnProperty(d)||(a[d]=z.apply(null,h))}a=a?a._modules:{};l(a,"Mixins/Polygon.js",[a["Core/Globals.js"],a["Core/Utilities.js"]],function(a,d){var h=d.find,z=d.isArray,k=d.isNumber,
  8. p=a.deg2rad,g=function(e,b){b=k(b)?b:14;b=Math.pow(10,b);return Math.round(e*b)/b},t=function(e,b){var c=b[0]-e[0];e=b[1]-e[1];return[[-e,c],[e,-c]]},u=function(e,b){e=e.map(function(c){return c[0]*b[0]+c[1]*b[1]});return{min:Math.min.apply(this,e),max:Math.max.apply(this,e)}},m=function(e,b){var c=e[0];e=e[1];var f=p*-b;b=Math.cos(f);f=Math.sin(f);return[g(c*b-e*f),g(c*f+e*b)]},A=function(e,b,c){e=m([e[0]-b[0],e[1]-b[1]],c);return[e[0]+b[0],e[1]+b[1]]},y=function(e){var b=e.axes;if(!z(b)){b=[];var c=
  9. c=e.concat([e[0]]);c.reduce(function(c,B){var f=t(c,B)[0];h(b,function(c){return c[0]===f[0]&&c[1]===f[1]})||b.push(f);return B});e.axes=b}return b},l=function(e,b){e=y(e);b=y(b);return e.concat(b)};return{getBoundingBoxFromPolygon:function(e){return e.reduce(function(b,c){var f=c[0];c=c[1];b.left=Math.min(f,b.left);b.right=Math.max(f,b.right);b.bottom=Math.max(c,b.bottom);b.top=Math.min(c,b.top);return b},{left:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE,top:Number.MAX_VALUE})},
  10. getPolygon:function(e,b,c,f,B){var g=[e,b],C=e-c/2;e+=c/2;c=b-f/2;b+=f/2;return[[C,c],[e,c],[e,b],[C,b]].map(function(c){return A(c,g,-B)})},isPolygonsColliding:function(e,b){var c=l(e,b);return!h(c,function(c){var f=u(e,c);c=u(b,c);return!!(c.min>f.max||c.max<f.min)})},movePolygon:function(e,b,c){return c.map(function(c){return[c[0]+e,c[1]+b]})},rotate2DToOrigin:m,rotate2DToPoint:A}});l(a,"Mixins/DrawPoint.js",[],function(){var a=function(a){return"function"===typeof a},d=function(d){var h=this,
  11. k=d.animatableAttribs,p=d.onComplete,g=d.css,t=d.renderer,u=this.series&&this.series.chart.hasRendered?void 0:this.series&&this.series.options.animation,m=this.graphic;if(this.shouldDraw())m||(this.graphic=m=t[d.shapeType](d.shapeArgs).add(d.group)),m.css(g).attr(d.attribs).animate(k,d.isNew?!1:u,p);else if(m){var A=function(){h.graphic=m=m&&m.destroy();a(p)&&p()};Object.keys(k).length?m.animate(k,void 0,function(){A()}):A()}};return{draw:d,drawPoint:function(a){(a.attribs=a.attribs||{})["class"]=
  12. this.getClassName();d.call(this,a)},isFn:a}});l(a,"Series/Wordcloud/WordcloudPoint.js",[a["Mixins/DrawPoint.js"],a["Core/Series/SeriesRegistry.js"],a["Core/Utilities.js"]],function(a,d,h){var l=this&&this.__extends||function(){var a=function(d,g){a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,g){a.__proto__=g}||function(a,g){for(var d in g)g.hasOwnProperty(d)&&(a[d]=g[d])};return a(d,g)};return function(d,g){function k(){this.constructor=d}a(d,g);d.prototype=null===g?Object.create(g):
  13. (k.prototype=g.prototype,new k)}}();h=h.extend;d=function(a){function d(){var d=null!==a&&a.apply(this,arguments)||this;d.dimensions=void 0;d.options=void 0;d.polygon=void 0;d.rect=void 0;d.series=void 0;return d}l(d,a);d.prototype.shouldDraw=function(){return!this.isNull};d.prototype.isValid=function(){return!0};return d}(d.seriesTypes.column.prototype.pointClass);h(d.prototype,{draw:a.drawPoint,weight:1});return d});l(a,"Series/Wordcloud/WordcloudUtils.js",[a["Mixins/Polygon.js"],a["Core/Utilities.js"]],
  14. function(a,d){var h=a.isPolygonsColliding,l=a.movePolygon,k=d.extend,p=d.find,g=d.isNumber,t=d.isObject,u=d.merge,m;(function(a){function d(c,f){return!(f.left>c.right||f.right<c.left||f.top>c.bottom||f.bottom<c.top)}function m(c,f){var a=!1,b=c.rect,e=c.polygon,r=c.lastCollidedWith,q=function(f){var a=d(b,f.rect);a&&(c.rotation%90||f.rotation%90)&&(a=h(e,f.polygon));return a};r&&((a=q(r))||delete c.lastCollidedWith);a||(a=!!p(f,function(f){var a=q(f);a&&(c.lastCollidedWith=f);return a}));return a}
  15. function e(c,f){f=4*c;var a=Math.ceil((Math.sqrt(f)-1)/2),b=2*a+1,d=Math.pow(b,2),e=!1;--b;1E4>=c&&("boolean"===typeof e&&f>=d-b&&(e={x:a-(d-f),y:-a}),d-=b,"boolean"===typeof e&&f>=d-b&&(e={x:-a,y:-a+(d-f)}),d-=b,"boolean"===typeof e&&(e=f>=d-b?{x:-a+(d-f),y:a}:{x:a,y:a-(d-f-b)}),e.x*=5,e.y*=5);return e}function b(c,f){var a=f.width/2,b=-(f.height/2),d=f.height/2;return!(-(f.width/2)<c.left&&a>c.right&&b<c.top&&d>c.bottom)}a.isRectanglesIntersecting=d;a.intersectsAnyWord=m;a.archimedeanSpiral=function(c,
  16. f){var a=f.field;f=!1;a=a.width*a.width+a.height*a.height;var b=.8*c;1E4>=c&&(f={x:b*Math.cos(b),y:b*Math.sin(b)},Math.min(Math.abs(f.x),Math.abs(f.y))<a||(f=!1));return f};a.squareSpiral=e;a.rectangularSpiral=function(c,a){c=e(c,a);a=a.field;c&&(c.x*=a.ratioX,c.y*=a.ratioY);return c};a.getRandomPosition=function(c){return Math.round(c*(Math.random()+.5)/2)};a.getScale=function(c,a,b){var f=2*Math.max(Math.abs(b.top),Math.abs(b.bottom));b=2*Math.max(Math.abs(b.left),Math.abs(b.right));return Math.min(0<
  17. b?1/b*c:1,0<f?1/f*a:1)};a.getPlayingField=function(c,a,b){b=b.reduce(function(c,a){a=a.dimensions;var b=Math.max(a.width,a.height);c.maxHeight=Math.max(c.maxHeight,a.height);c.maxWidth=Math.max(c.maxWidth,a.width);c.area+=b*b;return c},{maxHeight:0,maxWidth:0,area:0});b=Math.max(b.maxHeight,b.maxWidth,.85*Math.sqrt(b.area));var f=c>a?c/a:1;c=a>c?a/c:1;return{width:b*f,height:b*c,ratioX:f,ratioY:c}};a.getRotation=function(c,a,b,d){var f=!1;g(c)&&g(a)&&g(b)&&g(d)&&0<c&&-1<a&&d>b&&(f=b+a%c*((d-b)/(c-
  18. 1||1)));return f};a.getSpiral=function(c,a){var b,f=[];for(b=1;1E4>b;b++)f.push(c(b,a));return function(c){return 1E4>=c?f[c-1]:!1}};a.outsidePlayingField=b;a.intersectionTesting=function(c,a){var f=a.placed,d=a.field,e=a.rectangle,g=a.polygon,q=a.spiral,v=1,n={x:0,y:0},h=c.rect=k({},e);c.polygon=g;for(c.rotation=a.rotation;!1!==n&&(m(c,f)||b(h,d));)n=q(v),t(n)&&(h.left=e.left+n.x,h.right=e.right+n.x,h.top=e.top+n.y,h.bottom=e.bottom+n.y,c.polygon=l(n.x,n.y,g)),v++;return n};a.extendPlayingField=
  19. function(a,b){if(t(a)&&t(b)){var c=b.bottom-b.top;var f=b.right-b.left;b=a.ratioX;var d=a.ratioY;c=f*b>c*d?f:c;a=u(a,{width:a.width+c*b*2,height:a.height+c*d*2})}return a};a.updateFieldBoundaries=function(a,b){if(!g(a.left)||a.left>b.left)a.left=b.left;if(!g(a.right)||a.right<b.right)a.right=b.right;if(!g(a.top)||a.top>b.top)a.top=b.top;if(!g(a.bottom)||a.bottom<b.bottom)a.bottom=b.bottom;return a}})(m||(m={}));return m});l(a,"Series/Wordcloud/WordcloudSeries.js",[a["Core/Globals.js"],a["Mixins/Polygon.js"],
  20. a["Core/Series/Series.js"],a["Core/Series/SeriesRegistry.js"],a["Core/Utilities.js"],a["Series/Wordcloud/WordcloudPoint.js"],a["Series/Wordcloud/WordcloudUtils.js"]],function(a,d,h,l,k,p,g){var t=this&&this.__extends||function(){var a=function(b,c){a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,b){a.__proto__=b}||function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])};return a(b,c)};return function(b,c){function d(){this.constructor=b}a(b,c);b.prototype=null===c?Object.create(c):
  21. (d.prototype=c.prototype,new d)}}(),u=a.noop,m=d.getBoundingBoxFromPolygon,A=d.getPolygon,z=d.isPolygonsColliding,y=d.rotate2DToOrigin;d=d.rotate2DToPoint;var e=l.seriesTypes.column,b=k.extend,c=k.isArray,f=k.isNumber,B=k.isObject,G=k.merge;k=function(d){function r(){var a=null!==d&&d.apply(this,arguments)||this;a.data=void 0;a.options=void 0;a.points=void 0;return a}t(r,d);r.prototype.bindAxes=function(){var a={endOnTick:!1,gridLineWidth:0,lineWidth:0,maxPadding:0,startOnTick:!1,title:void 0,tickPositions:[]};
  22. h.prototype.bindAxes.call(this);b(this.yAxis.options,a);b(this.xAxis.options,a)};r.prototype.pointAttribs=function(b,c){b=a.seriesTypes.column.prototype.pointAttribs.call(this,b,c);delete b.stroke;delete b["stroke-width"];return b};r.prototype.deriveFontSize=function(a,b,c){a=f(a)?a:0;b=f(b)?b:1;c=f(c)?c:1;return Math.floor(Math.max(c,a*b))};r.prototype.drawPoints=function(){var a=this,c=a.hasRendered,d=a.xAxis,e=a.yAxis,r=a.group,h=a.options,k=h.animation,l=h.allowExtendPlayingField,u=a.chart.renderer,
  23. p=u.text().add(r),t=[],C=a.placementStrategy[h.placementStrategy],z=h.rotation,y=a.points.map(function(a){return a.weight}),E=Math.max.apply(null,y),D=a.points.concat().sort(function(a,b){return b.weight-a.weight});a.group.attr({scaleX:1,scaleY:1});D.forEach(function(c){var d=a.deriveFontSize(1/E*c.weight,h.maxFontSize,h.minFontSize);d=b({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 x=g.getPlayingField(d.len,e.len,
  24. D);var F=g.getSpiral(a.spirals[h.spiral],{field:x});D.forEach(function(d){var e=a.deriveFontSize(1/E*d.weight,h.maxFontSize,h.minFontSize);e=b({fontSize:e+"px"},h.style);var n=C(d,{data:D,field:x,placed:t,rotation:z}),q=b(a.pointAttribs(d,d.selected&&"select"),{align:"center","alignment-baseline":"middle",x:n.x,y:n.y,text:d.name,rotation:f(n.rotation)?n.rotation:void 0}),p=A(n.x,n.y,d.dimensions.width,d.dimensions.height,n.rotation),w=m(p),v=g.intersectionTesting(d,{rectangle:w,polygon:p,field:x,
  25. placed:t,spiral:F,rotation:n.rotation});!v&&l&&(x=g.extendPlayingField(x,w),v=g.intersectionTesting(d,{rectangle:w,polygon:p,field:x,placed:t,spiral:F,rotation:n.rotation}));B(v)?(q.x=(q.x||0)+v.x,q.y=(q.y||0)+v.y,w.left+=v.x,w.right+=v.x,w.top+=v.y,w.bottom+=v.y,x=g.updateFieldBoundaries(x,w),t.push(d),d.isNull=!1,d.isInside=!0):d.isNull=!0;if(k){var y={x:q.x,y:q.y};c?(delete q.x,delete q.y):(q.x=0,q.y=0)}d.draw({animatableAttribs:y,attribs:q,css:e,group:r,renderer:u,shapeArgs:void 0,shapeType:"text"})});
  26. p=p.destroy();d=g.getScale(d.len,e.len,x);a.group.attr({scaleX:d,scaleY:d})};r.prototype.hasData=function(){return B(this)&&!0===this.visible&&c(this.points)&&0<this.points.length};r.prototype.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}};r.defaultOptions=G(e.defaultOptions,{allowExtendPlayingField:!0,
  27. 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/>'}});return r}(e);b(k.prototype,{animate:h.prototype.animate,animateDrilldown:u,animateDrillupFrom:u,pointClass:p,
  28. setClip:u,placementStrategy:{random:function(a,b){var c=b.field;b=b.rotation;return{x:g.getRandomPosition(c.width)-c.width/2,y:g.getRandomPosition(c.height)-c.height/2,rotation:g.getRotation(b.orientations,a.index,b.from,b.to)}},center:function(a,b){b=b.rotation;return{x:0,y:0,rotation:g.getRotation(b.orientations,a.index,b.from,b.to)}}},pointArrayMap:["weight"],spirals:{archimedean:g.archimedeanSpiral,rectangular:g.rectangularSpiral,square:g.squareSpiral},utils:{extendPlayingField:g.extendPlayingField,
  29. getRotation:g.getRotation,isPolygonsColliding:z,rotate2DToOrigin:y,rotate2DToPoint:d}});l.registerSeriesType("wordcloud",k);"";return k});l(a,"masters/modules/wordcloud.src.js",[],function(){})});
  30. //# sourceMappingURL=wordcloud.js.map