UNPKG

highcharts

Version:
13 lines 14 kB
let t;/** * Highcharts Gantt JS v13.0.1 (2026-08-17) * @module highcharts/modules/pathfinder * @requires highcharts * * Pathfinder * * (c) 2016-2026 Highsoft AS * Author: Øystein Moseng * * A commercial license may be required depending on use, * see www.highcharts.com/license */import*as e from"../highcharts.js";let n={};n.n=t=>{let e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{if(Array.isArray(e))for(var i=0;i<e.length;){var r=e[i++],a=e[i++];n.o(t,r)?0===a&&i++:0===a?Object.defineProperty(t,r,{enumerable:!0,value:e[i++]}):Object.defineProperty(t,r,{enumerable:!0,get:a})}else for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=e.default;var r,a=n.n(i);let o=a().deg2rad,s=Math.max,h=Math.min,c=class{constructor(t,e,n){this.init(t,e,n)}init(t,e,n){this.fromPoint=t,this.toPoint=e,this.options=n,this.chart=t.series.chart,this.pathfinder=this.chart.pathfinder}renderPath(t,e){let n=this.chart,i=n.styledMode,r=this.pathfinder,a={},o=this.graphics&&this.graphics.path;r.group||(r.group=n.renderer.g().addClass("highcharts-pathfinder-group").attr({zIndex:-1}).add(n.seriesGroup)),r.group.translate(n.plotLeft,n.plotTop),!(o&&o.renderer)&&(o=n.renderer.path().add(r.group),i||o.attr({opacity:0})),o.attr(e),a.d=t,i||(a.opacity=1),o.animate(a),this.graphics=this.graphics||{},this.graphics.path=o}addMarker(t,e,n){let i,r,a,s,h,c,l,x=this.fromPoint.series.chart,M=x.pathfinder,d=x.renderer,y="start"===t?this.fromPoint:this.toPoint,p=y.getPathfinderAnchorPoint(e);e.enabled&&((l="start"===t?n[1]:n[n.length-2])&&"M"===l[0]||"L"===l[0])&&(c={x:l[1],y:l[2]},r=y.getRadiansToVector(c,p),i=y.getMarkerVector(r,e.radius,p),e.width&&e.height?(s=e.width,h=e.height):s=h=2*e.radius,this.graphics=this.graphics||{},a={x:i.x-s/2,y:i.y-h/2,width:s,height:h,rotation:-r/o,rotationOriginX:i.x,rotationOriginY:i.y},this.graphics[t]?this.graphics[t].animate(a):(this.graphics[t]=d.symbol(e.symbol).addClass("highcharts-point-connecting-path-"+t+"-marker highcharts-color-"+this.fromPoint.colorIndex).attr(a).add(M.group),d.styledMode||this.graphics[t].attr({fill:e.color||this.fromPoint.color,stroke:e.lineColor,"stroke-width":e.lineWidth,opacity:0}).animate({opacity:1},y.series.options.animation)))}getPath(t){let e=this.pathfinder,n=this.chart,r=e.algorithms[t.type],a=e.chartObstacles;return"function"!=typeof r?((0,i.error)('"'+t.type+'" is not a Pathfinder algorithm.'),{path:[],obstacles:[]}):(r.requiresObstacles&&!a&&(a=e.chartObstacles=e.getChartObstacles(t),n.options.connectors.algorithmMargin=t.algorithmMargin,e.chartObstacleMetrics=e.getObstacleMetrics(a)),r(this.fromPoint.getPathfinderAnchorPoint(t.startMarker),this.toPoint.getPathfinderAnchorPoint(t.endMarker),(0,i.merge)({chartObstacles:a,lineObstacles:e.lineObstacles||[],obstacleMetrics:e.chartObstacleMetrics,hardBounds:{xMin:0,xMax:n.plotWidth,yMin:0,yMax:n.plotHeight},obstacleOptions:{margin:t.algorithmMargin},startDirectionX:e.getAlgorithmStartDirection(t.startMarker)},t)))}render(){let t=this.fromPoint,e=t.series,n=e.chart,r=n.pathfinder,a={},o=(0,i.merge)(n.options.connectors,e.options.connectors,t.options.connectors,this.options);!n.styledMode&&(a.stroke=o.lineColor||t.color,a["stroke-width"]=o.lineWidth,o.dashStyle&&(a.dashstyle=o.dashStyle)),a.class="highcharts-point-connecting-path highcharts-color-"+t.colorIndex,o=(0,i.merge)(a,o),(0,i.defined)(o.marker.radius)||(o.marker.radius=h(s(Math.ceil((o.algorithmMargin||8)/2)-1,1),5));let c=this.getPath(o),l=c.path;c.obstacles&&(r.lineObstacles=r.lineObstacles||[],r.lineObstacles=r.lineObstacles.concat(c.obstacles)),this.renderPath(l,a),this.addMarker("start",(0,i.merge)(o.marker,o.startMarker),l),this.addMarker("end",(0,i.merge)(o.marker,o.endMarker),l)}destroy(){this.graphics&&((0,i.objectEach)(this.graphics,function(t){t.destroy()}),delete this.graphics)}};function l(t,e){let n=[];for(let i=0;i<t.length;i++){let r=t[i][1],a=t[i][2];if("number"==typeof r&&"number"==typeof a)if(0===i)n.push(["M",r,a]);else if(i===t.length-1)n.push(["L",r,a]);else if(e){let o=t[i-1],s=t[i+1];if(o&&s){let t=o[1],i=o[2],h=s[1],c=s[2];if("number"==typeof t&&"number"==typeof h&&"number"==typeof i&&"number"==typeof c&&t!==h&&i!==c){let o=t<h?1:-1,s=i<c?1:-1;n.push(["L",r-o*Math.min(Math.abs(r-t),e),a-s*Math.min(Math.abs(a-i),e)],["C",r,a,r,a,r+o*Math.min(Math.abs(r-h),e),a+s*Math.min(Math.abs(a-c),e)])}}}else n.push(["L",r,a])}return n}let{min:x,max:M,abs:d}=Math;function y(t,e,n){let i=e-1e-7,r=n||0,a=t.length-1,o,s;for(;r<=a;)if((s=i-t[o=a+r>>1].xMin)>0)r=o+1;else{if(!(s<0))return o;a=o-1}return r>0?r-1:0}function p(t,e){let n=y(t,e.x+1)+1;for(;n--;){var i;if(t[n].xMax>=e.x&&(i=t[n],e.x<=i.xMax&&e.x>=i.xMin&&e.y<=i.yMax&&e.y>=i.yMin))return n}return -1}function f(t){let e=[];if(t.length){e.push(["M",t[0].start.x,t[0].start.y]);for(let n=0;n<t.length;++n)e.push(["L",t[n].end.x,t[n].end.y])}return e}function u(t,e){t.yMin=M(t.yMin,e.yMin),t.yMax=x(t.yMax,e.yMax),t.xMin=M(t.xMin,e.xMin),t.xMax=x(t.xMax,e.xMax)}let g=function(t,e,n){let r=[],a=n.chartObstacles,o=p(a,t),s=p(a,e),h,c=(0,i.pick)(n.startDirectionX,d(e.x-t.x)>d(e.y-t.y))?"x":"y",x,M,y,u;function g(t,e,n,i,r){let a={x:t.x,y:t.y};return a[e]=n[i||e]+(r||0),a}function m(t,e,n){let i=d(e[n]-t[n+"Min"])>d(e[n]-t[n+"Max"]);return g(e,n,t,n+(i?"Max":"Min"),i?1:-1)}s>-1?(h={start:M=m(a[s],e,c),end:e},u=M):u=e,o>-1&&(M=m(x=a[o],t,c),r.push({start:t,end:M}),M[c]>=t[c]==M[c]>=u[c]&&(y=t[c="y"===c?"x":"y"]<e[c],r.push({start:M,end:g(M,c,x,c+(y?"Max":"Min"),y?1:-1)}),c="y"===c?"x":"y"));let b=r.length?r[r.length-1].end:t;M=g(b,c,u),r.push({start:b,end:M});let P=g(M,c="y"===c?"x":"y",u);return r.push({start:M,end:P}),h&&r.push(h),{path:l(f(r),n.radius),obstacles:r}};function m(t,e,n){let r=(0,i.pick)(n.startDirectionX,d(e.x-t.x)>d(e.y-t.y)),a=r?"x":"y",o=[],s=n.obstacleMetrics,h=x(t.x,e.x)-s.maxWidth-10,c=M(t.x,e.x)+s.maxWidth+10,l=x(t.y,e.y)-s.maxHeight-10,g=M(t.y,e.y)+s.maxHeight+10,m,b,P,O=!1,v=n.chartObstacles,k=y(v,c),w=y(v,h);function A(t,e,n){let i,r,a,o,s=t.x<e.x?1:-1;t.x<e.x?(i=t,r=e):(i=e,r=t),t.y<e.y?(o=t,a=e):(o=e,a=t);let h=s<0?x(y(v,r.x),v.length-1):0;for(;v[h]&&(s>0&&v[h].xMin<=r.x||s<0&&v[h].xMax>=i.x);){if(v[h].xMin<=r.x&&v[h].xMax>=i.x&&v[h].yMin<=a.y&&v[h].yMax>=o.y){if(n)return{y:t.y,x:t.x<e.x?v[h].xMin-1:v[h].xMax+1,obstacle:v[h]};return{x:t.x,y:t.y<e.y?v[h].yMin-1:v[h].yMax+1,obstacle:v[h]}}h+=s}return e}function E(t,e,n,i,r){let a=r.soft,o=r.hard,s=i?"x":"y",h={x:e.x,y:e.y},c={x:e.x,y:e.y},l=t[s+"Max"]>=a[s+"Max"],x=t[s+"Min"]<=a[s+"Min"],M=t[s+"Max"]>=o[s+"Max"],y=t[s+"Min"]<=o[s+"Min"],p=d(t[s+"Min"]-e[s]),f=d(t[s+"Max"]-e[s]),u=10>d(p-f)?e[s]<n[s]:f<p;c[s]=t[s+"Min"],h[s]=t[s+"Max"];let g=A(e,c,i)[s]!==c[s],m=A(e,h,i)[s]!==h[s];return u=g?!m||u:!m&&u,u=x?!l||u:!l&&u,u=y?!M||u:!M&&u}if((k=p(v=v.slice(w,k+1),e))>-1){var I,L;let i,r;I=v[k],L=e,i=x(I.xMax-L.x,L.x-I.xMin)<x(I.yMax-L.y,L.y-I.yMin),r=E(I,L,t,i,{soft:n.hardBounds,hard:n.hardBounds}),P=i?{y:L.y,x:I[r?"xMax":"xMin"]+(r?1:-1)}:{x:L.x,y:I[r?"yMax":"yMin"]+(r?1:-1)},o.push({end:e,start:P}),e=P}for(;(k=p(v,e))>-1;)b=e[a]-t[a]<0,(P={x:e.x,y:e.y})[a]=v[k][b?a+"Max":a+"Min"]+(b?1:-1),o.push({end:e,start:P}),e=P;return{path:f(m=(m=function t(e,i,r){let a,o,s,d,y,f,m;if(e.x===i.x&&e.y===i.y)return[];let b=r?"x":"y",P=n.obstacleOptions.margin,k={soft:{xMin:h,xMax:c,yMin:l,yMax:g},hard:n.hardBounds};return(y=p(v,e))>-1?(d=E(y=v[y],e,i,r,k),u(y,n.hardBounds),m=r?{y:e.y,x:y[d?"xMax":"xMin"]+(d?1:-1)}:{x:e.x,y:y[d?"yMax":"yMin"]+(d?1:-1)},(f=p(v,m))>-1&&(u(f=v[f],n.hardBounds),m[b]=d?M(y[b+"Max"]-P+1,(f[b+"Min"]+y[b+"Max"])/2):x(y[b+"Min"]+P-1,(f[b+"Max"]+y[b+"Min"])/2),e.x===m.x&&e.y===m.y?(O&&(m[b]=d?M(y[b+"Max"],f[b+"Max"])+1:x(y[b+"Min"],f[b+"Min"])-1),O=!O):O=!1),o=[{start:e,end:m}]):(a=A(e,{x:r?i.x:e.x,y:r?e.y:i.y},r),o=[{start:e,end:{x:a.x,y:a.y}}],a[r?"x":"y"]!==i[r?"x":"y"]&&(d=E(a.obstacle,a,i,!r,k),u(a.obstacle,n.hardBounds),s={x:r?a.x:a.obstacle[d?"xMax":"xMin"]+(d?1:-1),y:r?a.obstacle[d?"yMax":"yMin"]+(d?1:-1):a.y},r=!r,o=o.concat(t({x:a.x,y:a.y},s,r)))),o=o.concat(t(o[o.length-1].end,i,!r))}(t,e,r)).concat(o.reverse())),obstacles:m}}g.requiresObstacles=!0,m.requiresObstacles=!0;let b={connectors:{type:"straight",radius:0,lineWidth:1,marker:{enabled:!1,align:"center",verticalAlign:"middle",inside:!1,lineWidth:1},startMarker:{symbol:"diamond"},endMarker:{symbol:"arrow-filled"}}},{setOptions:P}=a();function O(t){let e=t.shapeArgs;if(e)return{xMin:e.x||0,xMax:(e.x||0)+(e.width||0),yMin:e.y||0,yMax:(e.y||0)+(e.height||0)};let n=t.graphic&&t.graphic.getBBox();return n?{xMin:t.plotX-n.width/2,xMax:t.plotX+n.width/2,yMin:t.plotY-n.height/2,yMax:t.plotY+n.height/2}:null}!function(t){function e(t){let e,n,i=O(this);switch(t.align){case"right":e="xMax";break;case"left":e="xMin"}switch(t.verticalAlign){case"top":n="yMin";break;case"bottom":n="yMax"}return e=e?i[e]:(i.xMin+i.xMax)/2,n=n?i[n]:(i.yMin+i.yMax)/2,{x:e+(t.xOffset||0),y:n+(t.yOffset||0)}}function n(t,e){let n;return!(0,i.defined)(e)&&(n=O(this))&&(e={x:(n.xMin+n.xMax)/2,y:(n.yMin+n.yMax)/2}),Math.atan2(e.y-t.y,t.x-e.x)}function r(t,e,n){let i=2*Math.PI,r=O(this),a=r.xMax-r.xMin,o=r.yMax-r.yMin,s=Math.atan2(o,a),h=a/2,c=o/2,l=r.xMin+h,x=r.yMin+c,M={x:l,y:x},d=t,y=1,p=!1,f=1,u=1;for(;d<-Math.PI;)d+=i;for(;d>Math.PI;)d-=i;return y=Math.tan(d),d>-s&&d<=s?(u=-1,p=!0):d>s&&d<=Math.PI-s?u=-1:d>Math.PI-s||d<=-(Math.PI-s)?(f=-1,p=!0):f=-1,p?(M.x+=f*h,M.y+=u*h*y):(M.x+=o/(2*y)*f,M.y+=u*c),n.x!==l&&(M.x=n.x),n.y!==x&&(M.y=n.y),{x:M.x+e*Math.cos(d),y:M.y-e*Math.sin(d)}}t.compose=function(t,a,o){let s=o.prototype;s.getPathfinderAnchorPoint||(t.prototype.callbacks.push(function(t){!1!==t.options.connectors.enabled&&((t.options.pathfinder||t.series.reduce(function(t,e){return e.options&&(0,i.merge)(!0,e.options.connectors=e.options.connectors||{},e.options.pathfinder),t||e.options&&e.options.pathfinder},!1))&&((0,i.merge)(!0,t.options.connectors=t.options.connectors||{},t.options.pathfinder),(0,i.error)('WARNING: Pathfinder options have been renamed. Use "chart.connectors" or "series.connectors" instead.')),this.pathfinder=new a(this),this.pathfinder.update(!0))}),s.getMarkerVector=r,s.getPathfinderAnchorPoint=e,s.getRadiansToVector=n,P(b))}}(r||(r={}));let v=r,k=e.default.Point;var w=n.n(k);let A=Math.max,E=Math.min;class I{static compose(t,e){v.compose(t,I,e)}constructor(t){this.init(t)}init(t){this.chart=t,this.connections=[],(0,i.addEvent)(t,"redraw",function(){this.pathfinder.update()})}update(t){let e=this.chart,n=this,r=n.connections;n.connections=[],e.series.forEach(function(t){t.visible&&!t.options.isInternal&&t.points.forEach(function(t){let r,a=t.options;a&&a.dependency&&(a.connect=a.dependency);let o=t.options?.connect?(0,i.splat)(t.options.connect):[];t.visible&&!1!==t.isInside&&o.forEach(i=>{let a="string"==typeof i?i:i.to;a&&(r=e.get(a)),r instanceof w()&&r.series.visible&&r.visible&&!1!==r.isInside&&n.connections.push(new c(t,r,"string"==typeof i?{}:i))})})});for(let t=0,e,i,a=r.length,o=n.connections.length;t<a;++t){i=!1;let a=r[t];for(e=0;e<o;++e){let t=n.connections[e];if((a.options&&a.options.type)===(t.options&&t.options.type)&&a.fromPoint===t.fromPoint&&a.toPoint===t.toPoint){t.graphics=a.graphics,i=!0;break}}i||a.destroy()}delete this.chartObstacles,delete this.lineObstacles,n.renderConnections(t)}renderConnections(t){t?this.chart.series.forEach(function(t){let e=function(){let e=t.chart.pathfinder;(e&&e.connections||[]).forEach(function(e){e.fromPoint&&e.fromPoint.series===t&&e.render()}),t.pathfinderRemoveRenderEvent&&(t.pathfinderRemoveRenderEvent(),delete t.pathfinderRemoveRenderEvent)};!1===t.options.animation?e():t.pathfinderRemoveRenderEvent=(0,i.addEvent)(t,"afterAnimate",e)}):this.connections.forEach(function(t){t.render()})}getChartObstacles(t){let e=this.chart.series,n=(0,i.pick)(t.algorithmMargin,0),r=[],a;for(let t=0,i=e.length;t<i;++t)if(e[t].visible&&!e[t].options.isInternal)for(let i=0,a=e[t].points.length,o,s;i<a;++i)(s=e[t].points[i]).visible&&(o=function(t){let e=t.shapeArgs;if(e)return{xMin:e.x||0,xMax:(e.x||0)+(e.width||0),yMin:e.y||0,yMax:(e.y||0)+(e.height||0)};let n=t.graphic&&t.graphic.getBBox();return n?{xMin:t.plotX-n.width/2,xMax:t.plotX+n.width/2,yMin:t.plotY-n.height/2,yMax:t.plotY+n.height/2}:null}(s))&&r.push({xMin:o.xMin-n,xMax:o.xMax+n,yMin:o.yMin-n,yMax:o.yMax+n});return r=r.sort(function(t,e){return t.xMin-e.xMin}),(0,i.defined)(t.algorithmMargin)||(a=t.algorithmMargin=function(t){let e,n=t.length,r=[];for(let a=0;a<n;++a)for(let o=a+1;o<n;++o)(e=function t(e,n,r){let a=(0,i.pick)(r,10),o=e.yMax+a>n.yMin-a&&e.yMin-a<n.yMax+a,s=e.xMax+a>n.xMin-a&&e.xMin-a<n.xMax+a,h=o?e.xMin>n.xMax?e.xMin-n.xMax:n.xMin-e.xMax:1/0,c=s?e.yMin>n.yMax?e.yMin-n.yMax:n.yMin-e.yMax:1/0;return s&&o?a?t(e,n,Math.floor(a/2)):1/0:E(h,c)}(t[a],t[o]))<80&&r.push(e);return r.push(80),A(Math.floor(r.sort(function(t,e){return t-e})[Math.floor(r.length/10)]/2-1),1)}(r),r.forEach(function(t){t.xMin-=a,t.xMax+=a,t.yMin-=a,t.yMax+=a})),r}getObstacleMetrics(t){let e=0,n=0,i,r,a=t.length;for(;a--;)i=t[a].xMax-t[a].xMin,r=t[a].yMax-t[a].yMin,e<i&&(e=i),n<r&&(n=r);return{maxHeight:n,maxWidth:e}}getAlgorithmStartDirection(t){let e="left"!==t.align&&"right"!==t.align,n="top"!==t.verticalAlign&&"bottom"!==t.verticalAlign;return e?!!n&&void 0:!!n||void 0}}function L(t,e,n,i){return[["M",t,e+i/2],["L",t+n,e],["L",t,e+i/2],["L",t+n,e+i]]}I.prototype.algorithms={fastAvoid:m,straight:function(t,e){return{path:[["M",t.x,t.y],["L",e.x,e.y]],obstacles:[{start:t,end:e}]}},simpleConnect:g};function R(t,e,n,i){return[["M",t+n,e],["L",t,e+i/2],["L",t+n,e+i],["Z"]]}function B(t,e,n,i){return R(t,e,n/2,i)}let C=a();C.Pathfinder=C.Pathfinder||I,(t=C.SVGRenderer.prototype.symbols).arrow=L,t["arrow-filled"]=R,t["arrow-filled-half"]=B,t["arrow-half"]=function(t,e,n,i){return L(t,e,n/2,i)},t["triangle-left"]=R,t["triangle-left-half"]=B,C.Pathfinder.compose(C.Chart,C.Point);let W=a();export{W as default};