UNPKG

highcharts

Version:
7 lines 9.08 kB
/** * Highcharts JS v11.3.0 (2024-01-10) * * (c) 2009-2024 Torstein Honsi * * License: www.highcharts.com/license */!function(t){"object"==typeof module&&module.exports?(t.default=t,module.exports=t):"function"==typeof define&&define.amd?define("highcharts/modules/series-label",["highcharts"],function(e){return t(e),t.Highcharts=e,t}):t("undefined"!=typeof Highcharts?Highcharts:void 0)}(function(t){"use strict";var e=t?t._modules:{};function o(t,e,o,r){t.hasOwnProperty(e)||(t[e]=r.apply(null,o),"function"==typeof CustomEvent&&window.dispatchEvent(new CustomEvent("HighchartsModuleLoaded",{detail:{path:e,module:t[e]}})))}o(e,"Extensions/SeriesLabel/SeriesLabelDefaults.js",[],function(){return{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:[]}}),o(e,"Extensions/SeriesLabel/SeriesLabelUtilities.js",[],function(){function t(t,e,o,r,i,a){let n=(a-e)*(o-t)-(r-e)*(i-t);return n>0||!(n<0)}function e(e,o,r,i,a,n,s,l){return t(e,o,a,n,s,l)!==t(r,i,a,n,s,l)&&t(e,o,r,i,a,n)!==t(e,o,r,i,s,l)}return{boxIntersectLine:function(t,o,r,i,a,n,s,l){return e(t,o,t+r,o,a,n,s,l)||e(t+r,o,t+r,o+i,a,n,s,l)||e(t,o+i,t+r,o+i,a,n,s,l)||e(t,o,t,o+i,a,n,s,l)},intersectRect:function(t,e){return!(e.left>t.right||e.right<t.left||e.top>t.bottom||e.bottom<t.top)}}}),o(e,"Extensions/SeriesLabel/SeriesLabel.js",[e["Core/Animation/AnimationUtilities.js"],e["Core/Templating.js"],e["Core/Defaults.js"],e["Core/Globals.js"],e["Extensions/SeriesLabel/SeriesLabelDefaults.js"],e["Extensions/SeriesLabel/SeriesLabelUtilities.js"],e["Core/Utilities.js"]],function(t,e,o,r,i,a,n){let{animObject:s}=t,{format:l}=e,{setOptions:h}=o,{composed:c}=r,{boxIntersectLine:p,intersectRect:d}=a,{addEvent:u,extend:f,fireEvent:x,isNumber:b,pick:m,pushUnique:g,syncTimeout:y}=n;function X(t,e,o,r,i){let a=t.chart,n=t.options.label||{},s=m(n.onArea,!!t.area),l=s||n.connectorAllowed,h=a.boxesToAvoid,c=Number.MAX_VALUE,u=Number.MAX_VALUE,f,x,b,g,y,X,M;for(X=0;h&&X<h.length;X+=1)if(d(h[X],{left:e,right:e+r.width,top:o,bottom:o+r.height}))return!1;for(X=0;X<a.series.length;X+=1){let h=a.series[X],d=h.interpolatedPoints&&[...h.interpolatedPoints];if(h.visible&&d){let m=a.plotHeight/10;for(let t=a.plotTop;t<=a.plotTop+a.plotHeight;t+=m)d.unshift({chartX:a.plotLeft,chartY:t}),d.push({chartX:a.plotLeft+a.plotWidth,chartY:t});for(M=1;M<d.length;M+=1){if(d[M].chartX>=e-16&&d[M-1].chartX<=e+r.width+16){if(p(e,o,r.width,r.height,d[M-1].chartX,d[M-1].chartY,d[M].chartX,d[M].chartY))return!1;t===h&&!b&&i&&(b=p(e-16,o-16,r.width+32,r.height+32,d[M-1].chartX,d[M-1].chartY,d[M].chartX,d[M].chartY))}(l||b)&&(t!==h||s)&&(c=Math.min(c,(g=e+r.width/2-d[M].chartX)*g+(y=o+r.height/2-d[M].chartY)*y))}if(!s&&l&&t===h&&(i&&!b||c<Math.pow(n.connectorNeighbourDistance||1,2))){for(M=1;M<d.length;M+=1)(f=Math.min(Math.pow(e+r.width/2-d[M].chartX,2)+Math.pow(o+r.height/2-d[M].chartY,2),Math.pow(e-d[M].chartX,2)+Math.pow(o-d[M].chartY,2),Math.pow(e+r.width-d[M].chartX,2)+Math.pow(o-d[M].chartY,2),Math.pow(e+r.width-d[M].chartX,2)+Math.pow(o+r.height-d[M].chartY,2),Math.pow(e-d[M].chartX,2)+Math.pow(o+r.height-d[M].chartY,2)))<u&&(u=f,x=d[M]);b=!0}}}return(!i||!!b)&&{x:e,y:o,weight:c-(x?u:0),connectorPoint:x}}function M(t){if(this.renderer){let e=this,o=s(e.renderer.globalAnimation).duration;e.labelSeries=[],e.labelSeriesMaxSum=0,e.seriesLabelTimer&&n.clearTimeout(e.seriesLabelTimer),e.series.forEach(function(r){let i=r.options.label||{},a=r.labelBySeries,n=a&&a.closest;i.enabled&&r.visible&&(r.graph||r.area)&&!r.boosted&&e.labelSeries&&(e.labelSeries.push(r),i.minFontSize&&i.maxFontSize&&r.yData&&(r.sum=r.yData.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)),n&&(void 0!==n[0].plotX?a.animate({x:n[0].plotX+n[1],y:n[0].plotY+n[2]}):a.attr({opacity:0})))}),e.seriesLabelTimer=y(function(){e.series&&e.labelSeries&&function(t){t.boxesToAvoid=[];let e=t.labelSeries||[],o=t.boxesToAvoid;t.series.forEach(t=>(t.points||[]).forEach(e=>(e.dataLabels||[]).forEach(e=>{let{width:r,height:i}=e.getBBox(),a=(e.translateX||0)+(t.xAxis?t.xAxis.pos:t.chart.plotLeft),n=(e.translateY||0)+(t.yAxis?t.yAxis.pos:t.chart.plotTop);o.push({left:a,top:n,right:a+r,bottom:n+i})}))),e.forEach(function(t){let e=t.options.label||{};t.interpolatedPoints=function(t){let e,o,r,i,a;if(!t.xAxis&&!t.yAxis)return;let n=t.points,s=[],l=t.graph||t.area,h=l&&l.element,c=t.chart.inverted,p=t.xAxis,d=t.yAxis,u=c?d.pos:p.pos,f=c?p.pos:d.pos,x=t.options.label||{},g=m(x.onArea,!!t.area),y=d.getThreshold(t.options.threshold),X={};function M(t){let e=Math.round((t.plotX||0)/8)+","+Math.round((t.plotY||0)/8);X[e]||(X[e]=1,s.push(t))}if(t.getPointSpline&&h&&h.getPointAtLength&&!g&&n.length<(t.chart.plotSizeX||0)/16){let t=l.toD&&l.attr("d");for(l.toD&&l.attr({d:l.toD}),r=h.getTotalLength(),e=0;e<r;e+=16){let t=h.getPointAtLength(e);M({chartX:u+t.x,chartY:f+t.y,plotX:t.x,plotY:t.y})}t&&l.attr({d:t});let o=n[n.length-1];M({chartX:u+(o.plotX||0),chartY:f+(o.plotY||0)})}else{let t;for(e=0,r=n.length;e<r;e+=1){let r=n[e],{plotX:s,plotY:l,plotHigh:h}=r;if(b(s)&&b(l)){let e={plotX:s,plotY:l,chartX:u+s,chartY:f+l};if(g&&(h&&(e.plotY=h,e.chartY=f+h),e.chartCenterY=f+((h||l)+m(r.yBottom,y))/2),t&&(o=Math.max(Math.abs(e.chartX-t.chartX),Math.abs(e.chartY-t.chartY)))>16)for(a=1,i=Math.ceil(o/16);a<i;a+=1)M({chartX:t.chartX+(e.chartX-t.chartX)*(a/i),chartY:t.chartY+(e.chartY-t.chartY)*(a/i),chartCenterY:(t.chartCenterY||0)+((e.chartCenterY||0)-(t.chartCenterY||0))*(a/i),plotX:(t.plotX||0)+(s-(t.plotX||0))*(a/i),plotY:(t.plotY||0)+(l-(t.plotY||0))*(a/i)});M(e),t=e}}}return s}(t),o.push(...e.boxesToAvoid||[])}),t.series.forEach(function(e){let o=e.options.label;if(!o||!e.xAxis&&!e.yAxis)return;let r="highcharts-color-"+m(e.colorIndex,"none"),i=!e.labelBySeries,a=o.minFontSize,n=o.maxFontSize,h=t.inverted,c=h?e.yAxis.pos:e.xAxis.pos,p=h?e.xAxis.pos:e.yAxis.pos,d=t.inverted?e.yAxis.len:e.xAxis.len,u=t.inverted?e.xAxis.len:e.yAxis.len,x=e.interpolatedPoints,b=m(o.onArea,!!e.area),g=[],y=e.xData||[],M,S,Y,w,A,L,v=e.labelBySeries,E,T,C;function P(t,e,o){let r=Math.max(c,m(T,-1/0)),i=Math.min(c+d,m(C,1/0));return t>r&&t<=i-o.width&&e>=p&&e<=p+u-o.height}function j(){v&&(e.labelBySeries=v.destroy())}if(b&&!h&&(E=[e.xAxis.toPixels(y[0]),e.xAxis.toPixels(y[y.length-1])],T=Math.min.apply(Math,E),C=Math.max.apply(Math,E)),e.visible&&!e.boosted&&x){if(!v){let i=e.name;if("string"==typeof o.format?i=l(o.format,e,t):o.formatter&&(i=o.formatter.call(e)),e.labelBySeries=v=t.renderer.label(i,0,0,"connector",0,0,o.useHTML).addClass("highcharts-series-label highcharts-series-label-"+e.index+" "+(e.options.className||"")+" "+r),!t.renderer.styledMode){let r="string"==typeof e.color?e.color:"#666666";v.css(f({color:b?t.renderer.getContrast(r):r},o.style||{})),v.attr({opacity:t.renderer.forExport?1:0,stroke:e.color,"stroke-width":1})}a&&n&&v.css({fontSize:a+(e.sum||0)/(e.chart.labelSeriesMaxSum||0)*(n-a)+"px"}),v.attr({padding:0,zIndex:3}).add()}for((M=v.getBBox()).width=Math.round(M.width),A=x.length-1;A>0;A-=1)b?P(S=x[A].chartX-M.width/2,Y=(x[A].chartCenterY||0)-M.height/2,M)&&(L=X(e,S,Y,M)):(P(S=x[A].chartX+3,Y=x[A].chartY-M.height-3,M)&&(L=X(e,S,Y,M,!0)),L&&g.push(L),P(S=x[A].chartX+3,Y=x[A].chartY+3,M)&&(L=X(e,S,Y,M,!0)),L&&g.push(L),P(S=x[A].chartX-M.width-3,Y=x[A].chartY+3,M)&&(L=X(e,S,Y,M,!0)),L&&g.push(L),P(S=x[A].chartX-M.width-3,Y=x[A].chartY-M.height-3,M)&&(L=X(e,S,Y,M,!0))),L&&g.push(L);if(o.connectorAllowed&&!g.length&&!b)for(S=c+d-M.width;S>=c;S-=16)for(Y=p;Y<p+u-M.height;Y+=16)(w=X(e,S,Y,M,!0))&&g.push(w);if(g.length){g.sort((t,e)=>e.weight-t.weight),L=g[0],(t.boxesToAvoid||[]).push({left:L.x,right:L.x+M.width,top:L.y,bottom:L.y+M.height});let o=Math.sqrt(Math.pow(Math.abs(L.x-(v.x||0)),2)+Math.pow(Math.abs(L.y-(v.y||0)),2));if(o&&e.labelBySeries){let r,a={opacity:t.renderer.forExport?1:0,x:L.x,y:L.y},n={opacity:1};o<=10&&(n={x:a.x,y:a.y},a={}),i&&(r=s(e.options.animation),r.duration*=.2),e.labelBySeries.attr(f(a,{anchorX:L.connectorPoint&&(L.connectorPoint.plotX||0)+c,anchorY:L.connectorPoint&&(L.connectorPoint.plotY||0)+p})).animate(n,r),e.options.kdNow=!0,e.buildKDTree();let l=e.searchPoint({chartX:L.x,chartY:L.y},!0);l&&(v.closest=[l,L.x-(l.plotX||0),L.y-(l.plotY||0)])}}else j()}else j()}),x(t,"afterDrawSeriesLabels")}(e)},e.renderer.forExport||!o?0:o)}}function S(t,e,o,r,i){let a=i&&i.anchorX,n=i&&i.anchorY,s,l,h=o/2;return b(a)&&b(n)&&(s=[["M",a,n]],(l=e-n)<0&&(l=-r-l),l<o&&(h=a<t+o/2?l:o-l),n>e+r?s.push(["L",t+h,e+r]):n<e?s.push(["L",t+h,e]):a<t?s.push(["L",t,e+r/2]):a>t+o&&s.push(["L",t+o,e+r/2])),s||[]}return{compose:function t(e,o){g(c,t)&&(u(e,"load",M),u(e,"redraw",M),o.prototype.symbols.connector=S,h({plotOptions:{series:{label:i}}}))}}}),o(e,"masters/modules/series-label.src.js",[e["Core/Globals.js"],e["Extensions/SeriesLabel/SeriesLabel.js"]],function(t,e){e.compose(t.Chart,t.SVGRenderer)})});