highcharts
Version:
JavaScript charting framework
11 lines • 10.8 kB
JavaScript
/**
* Highcharts JS v12.6.0 (2026-04-13)
* @module highcharts/modules/wordcloud
* @requires highcharts
*
* (c) 2016-2026 Highsoft AS
* Authors: Jon Arild Nygård
*
* A commercial license may be required depending on use.
* See www.highcharts.com/license
*/import*as t from"../highcharts.js";var e={};e.n=t=>{var i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},e.d=(t,i)=>{for(var o in i)e.o(i,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:i[o]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=t.default;var o=e.n(i);let n=function(t,e){let{animatableAttribs:i,onComplete:o,css:n,renderer:a}=e,r=t.series&&t.series.chart.hasRendered?void 0:t.series&&t.series.options.animation,l=t.graphic;if(e.attribs={...e.attribs,class:t.getClassName()},t.shouldDraw())l||(t.graphic=l="text"===e.shapeType?a.text():"image"===e.shapeType?a.image(e.imageUrl||"").attr(e.shapeArgs||{}):a[e.shapeType](e.shapeArgs||{}),l.add(e.group)),n&&l.css(n),l.attr(e.attribs).animate(i,!e.isNew&&r,o);else if(l){let e=()=>{t.graphic=l=l&&l.destroy(),"function"==typeof o&&o()};Object.keys(i).length?l.animate(i,void 0,()=>e()):e()}},a=t.default.SeriesRegistry;var r=e.n(a);let{doc:l,win:s}=o();function h(t,e){let i;for(i in t||(t={}),e)t[i]=e[i];return t}let p=Array.prototype.find?function(t,e){return t.find(e)}:function(t,e){let i,o=t.length;for(i=0;i<o;i++)if(e(t[i],i))return t[i]};function u(t){return g(t)&&"number"==typeof t.nodeType}function c(t){return"number"==typeof t&&!isNaN(t)&&t<1/0&&t>-1/0}function d(t){let e=Object.prototype.toString.call(t);return"[object Array]"===e||"[object Array Iterator]"===e}function g(t,e){return!!t&&"object"==typeof t&&(!e||!d(t))}function m(t,...e){let i,o=[t,...e],n={},a=function(t,e){return"object"!=typeof t&&(t={}),function(t,e,i){for(let i in t)Object.hasOwnProperty.call(t,i)&&e.call((0,t[i]),t[i],i,t)}(e,function(i,o){if("__proto__"!==o&&"constructor"!==o){let n;!g(i,!0)||(n=i?.constructor,g(i,!0)&&!u(i)&&n?.name&&"Object"!==n.name)||u(i)?t[o]=e[o]:t[o]=a(t[o]||{},i)}}),t};!0===t&&(n=o[1],o=Array.prototype.slice.call(o,2));let r=o.length;for(i=0;i<r;i++)n=a(n,o[i]);return n}let{column:{prototype:{pointClass:f}}}=r().seriesTypes;class y extends f{isValid(){return!0}}h(y.prototype,{weight:1});let{deg2rad:x}=o();function b(t,e){return!(e.left>t.right||e.right<t.left||e.top>t.bottom||e.bottom<t.top)}function M(t){let e,i=t.axes||[];return i.length||(i=[],(e=t.concat([t[0]])).reduce((t,e)=>{let o,n,a=(o=e[0]-t[0],[[-(n=e[1]-t[1]),o],[n,-o]])[0];return p(i,t=>t[0]===a[0]&&t[1]===a[1])||i.push(a),e}),t.axes=i),i}function w(t,e){let i=t.map(t=>{let i=t[0],o=t[1];return i*e[0]+o*e[1]});return{min:Math.min.apply(this,i),max:Math.max.apply(this,i)}}function S(t,e){let i=M(t),o=M(e);return!p(i.concat(o),i=>{let o,n;return o=w(t,i),!!((n=w(e,i)).min>o.max||n.max<o.min)})}function A(t,e){let i=4*t,o=Math.ceil((Math.sqrt(i)-1)/2),n=2*o+1,a=Math.pow(n,2),r=!1;return n-=1,t<=1e4&&("boolean"==typeof r&&i>=a-n&&(r={x:o-(a-i),y:-o}),a-=n,"boolean"==typeof r&&i>=a-n&&(r={x:-o,y:-o+(a-i)}),a-=n,"boolean"==typeof r&&(r=i>=a-n?{x:-o+(a-i),y:o}:{x:o,y:o-(a-i-n)}),r.x*=5,r.y*=5),r}function P(t,e){let i=Math.pow(10,c(e)?e:14);return Math.round(t*i)/i}function F(t,e){let i=t[0],o=t[1],n=-(x*e),a=Math.cos(n),r=Math.sin(n);return[P(i*a-o*r),P(i*r+o*a)]}function X(t,e,i){let o=F([t[0]-e[0],t[1]-e[1]],i);return[o[0]+e[0],o[1]+e[1]]}let{noop:T}=o(),{column:z}=r().seriesTypes,{archimedeanSpiral:v,extendPlayingField:Y,getBoundingBoxFromPolygon:O,getPlayingField:j,getPolygon:_,getRandomPosition:B,getRotation:C,getScale:N,getSpiral:W,intersectionTesting:D,isPolygonsColliding:R,rectangularSpiral:E,rotate2DToOrigin:L,rotate2DToPoint:H,squareSpiral:U,updateFieldBoundaries:V}={archimedeanSpiral:function(t,e){let i=e.field,o=i.width*i.width+i.height*i.height,n=.8*t,a=!1;return t<=1e4&&(Math.min(Math.abs((a={x:n*Math.cos(n),y:n*Math.sin(n)}).x),Math.abs(a.y))<o||(a=!1)),a},extendPlayingField:function(t,e){let i,o,n,a,r,l;return g(t)&&g(e)?(i=e.bottom-e.top,o=e.right-e.left,r=o*(n=t.ratioX)>i*(a=t.ratioY)?o:i,l=m(t,{width:t.width+r*n*2,height:t.height+r*a*2})):l=t,l},getBoundingBoxFromPolygon:function(t){return t.reduce(function(t,e){let i=e[0],o=e[1];return t.left=Math.min(i,t.left),t.right=Math.max(i,t.right),t.bottom=Math.max(o,t.bottom),t.top=Math.min(o,t.top),t},{left:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE,top:Number.MAX_VALUE})},getPlayingField:function(t,e,i){let o=i.reduce(function(t,e){let i=e.dimensions,o=Math.max(i.width,i.height);return t.maxHeight=Math.max(t.maxHeight,i.height),t.maxWidth=Math.max(t.maxWidth,i.width),t.area+=o*o,t},{maxHeight:0,maxWidth:0,area:0}),n=Math.max(o.maxHeight,o.maxWidth,.85*Math.sqrt(o.area)),a=t>e?t/e:1,r=e>t?e/t:1;return{width:n*a,height:n*r,ratioX:a,ratioY:r}},getPolygon:function(t,e,i,o,n){let a=[t,e],r=t-i/2,l=t+i/2,s=e-o/2,h=e+o/2;return[[r,s],[l,s],[l,h],[r,h]].map(function(t){return X(t,a,-n)})},getRandomPosition:function(t){return Math.round(t*(Math.random()+.5)/2)},getRotation:function(t,e,i,o){let n=!1,a;return c(t)&&c(e)&&c(i)&&c(o)&&t>0&&e>-1&&o>i&&(a=(o-i)/(t-1||1),n=i+e%t*a),n},getScale:function(t,e,i){let o=2*Math.max(Math.abs(i.top),Math.abs(i.bottom)),n=2*Math.max(Math.abs(i.left),Math.abs(i.right));return Math.min(n>0?1/n*t:1,o>0?1/o*e:1)},getSpiral:function(t,e){let i=[];for(let o=1;o<1e4;o++)i.push(t(o,e));return t=>t<=1e4&&i[t-1]},intersectionTesting:function(t,e){let i,o,n,a,r,l,s=e.placed,u=e.field,c=e.rectangle,d=e.polygon,m=e.spiral,f=t.rect=h({},c),y=1,x={x:0,y:0};for(t.polygon=d,t.rotation=e.rotation;!1!==x&&(i=t.rect,o=t.polygon,n=t.lastCollidedWith,a=function(e){let n=b(i,e.rect);return n&&(t.rotation%90||e.rotation%90)&&(n=S(o,e.polygon)),n},r=!1,n&&!(r=a(n))&&delete t.lastCollidedWith,!r&&(r=!!p(s,function(e){let i=a(e);return i&&(t.lastCollidedWith=e),i})),r||!((l={left:-(u.width/2),right:u.width/2,top:-(u.height/2),bottom:u.height/2}).left<f.left&&l.right>f.right&&l.top<f.top&&l.bottom>f.bottom));)g(x=m(y))&&(f.left=c.left+x.x,f.right=c.right+x.x,f.top=c.top+x.y,f.bottom=c.bottom+x.y,t.polygon=function(t,e,i){return i.map(function(i){return[i[0]+t,i[1]+e]})}(x.x,x.y,d)),y++;return x},isPolygonsColliding:S,isRectanglesIntersecting:b,rectangularSpiral:function(t,e){let i=A(t,e),o=e.field;return i&&(i.x*=o.ratioX,i.y*=o.ratioY),i},rotate2DToOrigin:F,rotate2DToPoint:X,squareSpiral:A,updateFieldBoundaries:function(t,e){return(!c(t.left)||t.left>e.left)&&(t.left=e.left),(!c(t.right)||t.right<e.right)&&(t.right=e.right),(!c(t.top)||t.top>e.top)&&(t.top=e.top),(!c(t.bottom)||t.bottom<e.bottom)&&(t.bottom=e.bottom),t}};class q extends z{pointAttribs(t,e){let i=o().seriesTypes.column.prototype.pointAttribs.call(this,t,e);return delete i.stroke,delete i["stroke-width"],i}deriveFontSize(t,e,i){let o=c(t)?t:0,n=c(e)?e:1;return Math.floor(Math.max(c(i)?i:1,o*n))}drawPoints(){if(this.zooming||this.defaultScale&&this.group.scaleX!==this.defaultScale)return;let t=this.hasRendered,e=this.xAxis,i=this.yAxis,o=this.chart,a=this.group,r=this.options,l=r.animation,s=r.allowExtendPlayingField,p=o.renderer,u=[],d=this.placementStrategy[r.placementStrategy],m=r.rotation,f=this.points.map(function(t){return t.weight}),y=Math.max.apply(null,f),x=this.points.concat().sort((t,e)=>e.weight-t.weight),b=p.text().add(a),M;for(let t of(this.group.attr({scaleX:1,scaleY:1}),x)){let e=1/y*t.weight,i=h({fontSize:this.deriveFontSize(e,r.maxFontSize,r.minFontSize)+"px"},r.style);b.css(i).attr({x:0,y:0,text:t.name});let o=b.getBBox(!0);t.dimensions={height:o.height,width:o.width}}M=j(e.len,i.len,x);let w=W(this.spirals[r.spiral],{field:M});for(let e of x){let i=1/y*e.weight,o=h({fontSize:this.deriveFontSize(i,r.maxFontSize,r.minFontSize)+"px"},r.style),f=d(e,{data:x,field:M,placed:u,rotation:m}),b=h(this.pointAttribs(e,e.selected&&"select"),{align:"center","alignment-baseline":"middle","dominant-baseline":"middle",x:f.x,y:f.y,text:e.name,rotation:c(f.rotation)?f.rotation:void 0}),S=_(f.x,f.y,e.dimensions.width,e.dimensions.height,f.rotation),A=O(S),P=D(e,{rectangle:A,polygon:S,field:M,placed:u,spiral:w,rotation:f.rotation}),F;!P&&s&&(M=Y(M,A),P=D(e,{rectangle:A,polygon:S,field:M,placed:u,spiral:w,rotation:f.rotation})),g(P)?(b.x=(b.x||0)+P.x,b.y=(b.y||0)+P.y,A.left+=P.x,A.right+=P.x,A.top+=P.y,A.bottom+=P.y,M=V(M,A),u.push(e),e.isNull=!1,e.isInside=!0):e.isNull=!0,l&&(F={x:b.x,y:b.y},t?(delete b.x,delete b.y):(b.x=0,b.y=0)),n(e,{animatableAttribs:F,attribs:b,css:o,group:a,renderer:p,shapeArgs:void 0,shapeType:"text"})}b=b.destroy(),this.defaultScale=N(e.len,i.len,M),this.field=M,this.group.attr({scaleX:this.defaultScale,scaleY:this.defaultScale})}hasData(){return g(this)&&!0===this.visible&&d(this.points)&&this.points.length>0}getPlotBox(t){let{chart:e,group:i,zooming:o}=this,{plotSizeX:n=0,plotSizeY:a=0,inverted:r}=e,l=this[r?"yAxis":"xAxis"],s=this[r?"xAxis":"yAxis"],h=l?l.len:e.plotWidth,p=s?s.len:e.plotHeight,u=l?l.left:e.plotLeft,d=s?s.top:e.plotTop,g=this.field,m=0,f=0,y=u+h/2,x=d+p/2,b=y,M=x,w=this.defaultScale||1,S=0,A=0;if(g&&(S=2*Math.max(Math.abs(g.top),Math.abs(g.bottom)),A=2*Math.max(Math.abs(g.left),Math.abs(g.right))),r&&([A,S]=[S,A]),i&&o){let e=u+Math.max(A*(w=Math.max(o.scale,this.defaultScale||1)),h)/2,r=d+Math.max(S*w,p)/2,l=w-(i.scaleX||1);m=l*((n-A)/2+o.zoomX*n-h/2),f=l*((a-S)/2+o.zoomY*a-p/2),"series"===t&&(o.x=Math.max(0,Math.min(1-o.width,o.x+o.panX/o.scale)),m+=o.panX*n,o.panX=0,o.y=Math.max(0,Math.min(1-o.height,o.y+o.panY/o.scale)),f+=o.panY*a,o.panY=0),c(i.translateX)&&c(i.translateY)&&(b=i.translateX,M=i.translateY),y=b-m,(x=M-f)>r?x=r:x<2*d+p-r&&(x=2*d+p-r),y>e?y=e:y<2*u+h-e&&(y=2*u+h-e)}return{translateX:y,translateY:x,scaleX:w,scaleY:w}}}q.defaultOptions=m(z.defaultOptions,{allowExtendPlayingField:!0,animation:{duration:500},borderWidth:0,clip:!1,colorByPoint:!0,cropThreshold:1/0,colorKey:"weight",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}">●</span> {series.name}: <b>{point.weight}</b><br/>'}}),h(q.prototype,{animate:T,animateDrilldown:T,animateDrillupFrom:T,isCartesian:!1,pointClass:y,setClip:T,placementStrategy:{random:function(t,e){let i=e.field,o=e.rotation;return{x:B(i.width)-i.width/2,y:B(i.height)-i.height/2,rotation:C(o.orientations,t.index,o.from,o.to)}},center:function(t,e){let i=e.rotation;return{x:0,y:0,rotation:C(i.orientations,t.index,i.from,i.to)}}},pointArrayMap:["weight"],spirals:{archimedean:v,rectangular:E,square:U},utils:{extendPlayingField:Y,getRotation:C,isPolygonsColliding:R,rotate2DToOrigin:L,rotate2DToPoint:H}}),r().registerSeriesType("wordcloud",q);let k=o();export{k as default};