/**
 * Highcharts JS v13.0.0 (2026-06-11)
 * @module highcharts/modules/series-label
 * @requires highcharts
 *
 * (c) 2009-2026 Highsoft AS
 * Author: Torstein Hønsi
 *
 * 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 r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let r=t.default;var o=e.n(r);let a=t.default.Templating;var i=e.n(a);let h={enabled:!0,connectorAllowed:!1,connectorNeighbourDistance:24,format:void 0,formatter:void 0,minFontSize:null,maxFontSize:null,onArea:null,style:{fontSize:"0.8em",fontWeight:"bold"},useHTML:!1,boxesToAvoid:[]};function n(t,e,r,o,a,i){let h=(i-e)*(r-t)-(o-e)*(a-t);return h>0||!(h<0)}function l(t,e,r,o,a,i,h,l){return n(t,e,a,i,h,l)!==n(r,o,a,i,h,l)&&n(t,e,r,o,a,i)!==n(t,e,r,o,h,l)}let{animObject:s}=o(),{format:c}=i(),{setOptions:p}=o(),{composed:d}=o(),{boxIntersectLine:u,intersectRect:f}={boxIntersectLine:function(t,e,r,o,a,i,h,n){return l(t,e,t+r,e,a,i,h,n)||l(t+r,e,t+r,e+o,a,i,h,n)||l(t,e+o,t+r,e+o,a,i,h,n)||l(t,e,t,e+o,a,i,h,n)},intersectRect:function(t,e){return!(e.left>t.right||e.right<t.left||e.top>t.bottom||e.bottom<t.top)}};function x(t,e,o,a,i){let h=t.chart,n=t.options.label||{},l=(0,r.pick)(n.onArea,!!t.area),s=l||n.connectorAllowed,c=h.boxesToAvoid,p=Number.MAX_VALUE,d=Number.MAX_VALUE,x,b,g,m,y,X,M;for(X=0;c&&X<c.length;X+=1)if(f(c[X],{left:e,right:e+a.width,top:o,bottom:o+a.height}))return!1;for(X=0;X<h.series.length;X+=1){let r=h.series[X],c=r.interpolatedPoints&&[...r.interpolatedPoints];if(r.visible&&c){let f=h.plotHeight/10;for(let t=h.plotTop;t<=h.plotTop+h.plotHeight;t+=f)c.unshift({chartX:h.plotLeft,chartY:t}),c.push({chartX:h.plotLeft+h.plotWidth,chartY:t});for(M=1;M<c.length;M+=1){if(c[M].chartX>=e-16&&c[M-1].chartX<=e+a.width+16){if(u(e,o,a.width,a.height,c[M-1].chartX,c[M-1].chartY,c[M].chartX,c[M].chartY))return!1;t===r&&!g&&i&&(g=u(e-16,o-16,a.width+32,a.height+32,c[M-1].chartX,c[M-1].chartY,c[M].chartX,c[M].chartY))}(s||g)&&(t!==r||l)&&(p=Math.min(p,(m=e+a.width/2-c[M].chartX)*m+(y=o+a.height/2-c[M].chartY)*y))}if(!l&&s&&t===r&&(i&&!g||p<Math.pow(n.connectorNeighbourDistance||1,2))){for(M=1;M<c.length;M+=1)(x=Math.min(Math.pow(e+a.width/2-c[M].chartX,2)+Math.pow(o+a.height/2-c[M].chartY,2),Math.pow(e-c[M].chartX,2)+Math.pow(o-c[M].chartY,2),Math.pow(e+a.width-c[M].chartX,2)+Math.pow(o-c[M].chartY,2),Math.pow(e+a.width-c[M].chartX,2)+Math.pow(o+a.height-c[M].chartY,2),Math.pow(e-c[M].chartX,2)+Math.pow(o+a.height-c[M].chartY,2)))<d&&(d=x,b=c[M]);g=!0}}}return(!i||!!g)&&{x:e,y:o,weight:p-(b?d:0),connectorPoint:b}}function b(t){if(this.renderer){let e=this,o=s(e.renderer.globalAnimation).duration;e.labelSeries=[],e.labelSeriesMaxSum=0,e.seriesLabelTimer&&(0,r.internalClearTimeout)(e.seriesLabelTimer),e.series.forEach(function(r){let a=r.options.label||{},i=r.labelBySeries,h=i&&i.closest,n=r.getColumn("y");a.enabled&&r.visible&&(r.graph||r.area)&&!r.boosted&&e.labelSeries&&(e.labelSeries.push(r),a.minFontSize&&a.maxFontSize&&n.length&&(r.sum=n.reduce((t,e)=>(t||0)+(e||0),0),e.labelSeriesMaxSum=Math.max(e.labelSeriesMaxSum||0,r.sum||0)),"load"===t.type&&(o=Math.max(o,s(r.options.animation).duration)),h&&(void 0!==h[0].plotX?i.animate({x:h[0].plotX+h[1],y:h[0].plotY+h[2]}):i.attr({opacity:0})))}),e.seriesLabelTimer=(0,r.syncTimeout)(function(){let t,o;e.series&&e.labelSeries&&(e.boxesToAvoid=[],t=e.labelSeries||[],o=e.boxesToAvoid,e.series.forEach(t=>(t.points||[]).forEach(e=>(e.dataLabels||[]).forEach(e=>{let{width:r,height:a}=e.getBBox(),i=(e.translateX||0)+(t.xAxis?t.xAxis.pos:t.chart.plotLeft),h=(e.translateY||0)+(t.yAxis?t.yAxis.pos:t.chart.plotTop);o.push({left:i,top:h,right:i+r,bottom:h+a})}))),t.forEach(function(t){let e=t.options.label||{};t.interpolatedPoints=function(t){let e,o,a,i,h;if(!t.xAxis&&!t.yAxis)return;let n=t.points,l=[],s=t.graph||t.area,c=s&&s.element,p=t.chart.inverted,d=t.xAxis,u=t.yAxis,f=p?u.pos:d.pos,x=p?d.pos:u.pos,b=p?d.len:u.len,g=p?u.len:d.len,m=t.options.label||{},y=(0,r.pick)(m.onArea,!!t.area),X=u.getThreshold(t.options.threshold),M={},Y=p?"chartCenterX":"chartCenterY";function w(t){let e=Math.round((t.plotX||0)/8)+","+Math.round((t.plotY||0)/8);M[e]||(M[e]=1,l.push(t))}if(t.getPointSpline&&c&&c.getPointAtLength&&!y&&n.length<(t.chart.plotSizeX||0)/16){let t=s.toD&&s.attr("d");for(s.toD&&s.attr({d:s.toD}),a=c.getTotalLength(),e=0;e<a;e+=16){let t=c.getPointAtLength(e),r=p?g-t.y:t.x,o=p?b-t.x:t.y;w({chartX:f+r,chartY:x+o,plotX:r,plotY:o})}t&&s.attr({d:t});let r=n[n.length-1].pos();w({chartX:f+(r?.[0]||0),chartY:x+(r?.[1]||0)})}else{let t;for(e=0,a=n.length;e<a;e+=1){let a=n[e],[l,s]=a.pos()||[],{plotHigh:c}=a;if((0,r.isNumber)(l)&&(0,r.isNumber)(s)){let e={plotX:l,plotY:s,chartX:f+l,chartY:x+s};if(y&&(c&&(e.plotY=c,e.chartY=x+c),p?e.chartCenterX=f+g-((c||a.plotY||0)+(0,r.pick)(a.yBottom,X))/2:e.chartCenterY=x+((c||s)+(0,r.pick)(a.yBottom,X))/2),t&&(o=Math.max(Math.abs(e.chartX-t.chartX),Math.abs(e.chartY-t.chartY)))>16&&o<999)for(h=1,i=Math.ceil(o/16);h<i;h+=1)w({chartX:t.chartX+(e.chartX-t.chartX)*(h/i),chartY:t.chartY+(e.chartY-t.chartY)*(h/i),[Y]:(t[Y]||0)+((e[Y]||0)-(t[Y]||0))*(h/i),plotX:(t.plotX||0)+(l-(t.plotX||0))*(h/i),plotY:(t.plotY||0)+(s-(t.plotY||0))*(h/i)});w(e),t=e}}}return l}(t),o.push(...e.boxesToAvoid||[])}),e.series.forEach(function(t){let o=t.options.label;if(!o||!t.xAxis&&!t.yAxis)return;let a="highcharts-color-"+(0,r.pick)(t.colorIndex,"none"),i=!t.labelBySeries,h=o.minFontSize,n=o.maxFontSize,l=e.inverted,p=l?t.yAxis.pos:t.xAxis.pos,d=l?t.xAxis.pos:t.yAxis.pos,u=e.inverted?t.yAxis.len:t.xAxis.len,f=e.inverted?t.xAxis.len:t.yAxis.len,b=t.interpolatedPoints,g=(0,r.pick)(o.onArea,!!t.area),m=[],y=t.getColumn("x"),X,M,Y,w,A,S,v=t.labelBySeries,L,T,P;function E(t,e,o){let a=Math.max(p,(0,r.pick)(T,-1/0)),i=Math.min(p+u,(0,r.pick)(P,1/0));return t>a&&t<=i-o.width&&e>=d&&e<=d+f-o.height}function B(){v&&(t.labelBySeries=v.destroy())}if(g&&!l&&(L=[t.xAxis.toPixels(y[0]),t.xAxis.toPixels(y[y.length-1])],T=Math.min.apply(Math,L),P=Math.max.apply(Math,L)),t.visible&&!t.boosted&&b){if(!v){var C,k,z;let i=t.name;if("string"==typeof o.format?i=c(o.format,t,e):o.formatter&&(i=o.formatter.call(t,t)),t.labelBySeries=v=e.renderer.label(i,0,0,"connector",0,0,o.useHTML).addClass("highcharts-series-label highcharts-series-label-"+t.index+" "+(t.options.className||"")+" "+a),!e.renderer.styledMode){let a="string"==typeof t.color?t.color:"var(--highcharts-neutral-color-60)";v.css((0,r.extend)({color:g?e.renderer.getContrast(a):a},o.style||{})),v.attr({opacity:+!!e.renderer.forExport,stroke:t.color,"stroke-width":1})}h&&n&&v.css({fontSize:(C=t,k=h,z=n,k+(C.sum||0)/(C.chart.labelSeriesMaxSum||0)*(z-k)+"px")}),v.attr({padding:0,zIndex:3}).add()}for((X=v.getBBox()).width=Math.round(X.width),A=b.length-1;A>0;A-=1)g?E(M=(b[A].chartCenterX??b[A].chartX)-X.width/2,Y=(b[A].chartCenterY??b[A].chartY)-X.height/2,X)&&(S=x(t,M,Y,X)):(E(M=b[A].chartX+3,Y=b[A].chartY-X.height-3,X)&&(S=x(t,M,Y,X,!0)),S&&m.push(S),E(M=b[A].chartX+3,Y=b[A].chartY+3,X)&&(S=x(t,M,Y,X,!0)),S&&m.push(S),E(M=b[A].chartX-X.width-3,Y=b[A].chartY+3,X)&&(S=x(t,M,Y,X,!0)),S&&m.push(S),E(M=b[A].chartX-X.width-3,Y=b[A].chartY-X.height-3,X)&&(S=x(t,M,Y,X,!0))),S&&m.push(S);if(o.connectorAllowed&&!m.length&&!g)for(M=p+u-X.width;M>=p;M-=16)for(Y=d;Y<d+f-X.height;Y+=16)(w=x(t,M,Y,X,!0))&&m.push(w);if(m.length){m.sort((t,e)=>e.weight-t.weight),S=m[0],(e.boxesToAvoid||[]).push({left:S.x,right:S.x+X.width,top:S.y,bottom:S.y+X.height});let o=Math.sqrt(Math.pow(Math.abs(S.x-(v.x||0)),2)+Math.pow(Math.abs(S.y-(v.y||0)),2));if(o&&t.labelBySeries){let a,h={opacity:+!!e.renderer.forExport,x:S.x,y:S.y},n={opacity:1};o<=10&&(n={x:h.x,y:h.y},h={}),i&&(a=s(t.options.animation),a.duration*=.2),t.labelBySeries.attr((0,r.extend)(h,{anchorX:S.connectorPoint&&(S.connectorPoint.plotX||0)+p,anchorY:S.connectorPoint&&(S.connectorPoint.plotY||0)+d})).animate(n,a),t.options.kdNow=!0,t.buildKDTree();let l=t.searchPoint({chartX:S.x,chartY:S.y},!0);l&&(v.closest=[l,S.x-(l.plotX||0),S.y-(l.plotY||0)])}}else B()}else B()}),(0,r.fireEvent)(e,"afterDrawSeriesLabels"))},e.renderer.forExport||!o?0:o)}}function g(t,e,o,a,i){let h=i&&i.anchorX,n=i&&i.anchorY,l,s,c=o/2;return(0,r.isNumber)(h)&&(0,r.isNumber)(n)&&(l=[["M",h,n]],(s=e-n)<0&&(s=-a-s),s<o&&(c=h<t+o/2?s:o-s),n>e+a?l.push(["L",t+c,e+a]):n<e?l.push(["L",t+c,e]):h<t?l.push(["L",t,e+a/2]):h>t+o&&l.push(["L",t+o,e+a/2])),l||[]}let m=o();({compose:function(t,e){(0,r.pushUnique)(d,"SeriesLabel")&&((0,r.addEvent)(t,"load",b),(0,r.addEvent)(t,"redraw",b),e.prototype.symbols.connector=g,p({plotOptions:{series:{label:h}}}))}}).compose(m.Chart,m.SVGRenderer);let y=o();export{y as default};