tupali_fork/librerias/gantt/code/modules/pathfinder.js
2020-05-23 15:45:54 -05:00

36 lines
13 KiB
JavaScript

/*
Highcharts Gantt JS v8.1.0 (2020-05-05)
Pathfinder
(c) 2016-2019 ystein Moseng
License: www.highcharts.com/license
*/
(function(d){"object"===typeof module&&module.exports?(d["default"]=d,module.exports=d):"function"===typeof define&&define.amd?define("highcharts/modules/pathfinder",["highcharts"],function(l){d(l);d.Highcharts=l;return d}):d("undefined"!==typeof Highcharts?Highcharts:void 0)})(function(d){function l(C,p,h,d){C.hasOwnProperty(p)||(C[p]=d.apply(null,h))}d=d?d._modules:{};l(d,"parts-gantt/PathfinderAlgorithms.js",[d["parts/Utilities.js"]],function(d){function p(e,c,f){f=f||0;var h=e.length-1;c-=1e-7;
for(var d,p;f<=h;)if(d=h+f>>1,p=c-e[d].xMin,0<p)f=d+1;else if(0>p)h=d-1;else return d;return 0<f?f-1:0}function h(e,c){for(var f=p(e,c.x+1)+1;f--;){var h;if(h=e[f].xMax>=c.x)h=e[f],h=c.x<=h.xMax&&c.x>=h.xMin&&c.y<=h.yMax&&c.y>=h.yMin;if(h)return f}return-1}function C(e){var c=[];if(e.length){c.push(["M",e[0].start.x,e[0].start.y]);for(var f=0;f<e.length;++f)c.push(["L",e[f].end.x,e[f].end.y])}return c}function n(e,c){e.yMin=y(e.yMin,c.yMin);e.yMax=t(e.yMax,c.yMax);e.xMin=y(e.xMin,c.xMin);e.xMax=t(e.xMax,
c.xMax)}var l=d.extend,F=d.pick,t=Math.min,y=Math.max,w=Math.abs;return{straight:function(e,c){return{path:[["M",e.x,e.y],["L",c.x,c.y]],obstacles:[{start:e,end:c}]}},simpleConnect:l(function(e,c,f){function d(b,a,u,z,e){b={x:b.x,y:b.y};b[a]=u[z||a]+(e||0);return b}function p(a,g,u){var b=w(g[u]-a[u+"Min"])>w(g[u]-a[u+"Max"]);return d(g,u,a,u+(b?"Max":"Min"),b?1:-1)}var n=[],r=F(f.startDirectionX,w(c.x-e.x)>w(c.y-e.y))?"x":"y",t=f.chartObstacles,x=h(t,e);f=h(t,c);if(-1<f){var l=t[f];f=p(l,c,r);l=
{start:f,end:c};var a=f}else a=c;-1<x&&(t=t[x],f=p(t,e,r),n.push({start:e,end:f}),f[r]>=e[r]===f[r]>=a[r]&&(r="y"===r?"x":"y",c=e[r]<c[r],n.push({start:f,end:d(f,r,t,r+(c?"Max":"Min"),c?1:-1)}),r="y"===r?"x":"y"));e=n.length?n[n.length-1].end:e;f=d(e,r,a);n.push({start:e,end:f});r=d(f,"y"===r?"x":"y",a);n.push({start:f,end:r});n.push(l);return{path:C(n),obstacles:n}},{requiresObstacles:!0}),fastAvoid:l(function(e,c,f){function d(a,b,g){var k,u=a.x<b.x?1:-1;if(a.x<b.x){var z=a;var e=b}else z=b,e=a;
if(a.y<b.y){var c=a;var v=b}else c=b,v=a;for(k=0>u?t(p(m,e.x),m.length-1):0;m[k]&&(0<u&&m[k].xMin<=e.x||0>u&&m[k].xMax>=z.x);){if(m[k].xMin<=e.x&&m[k].xMax>=z.x&&m[k].yMin<=v.y&&m[k].yMax>=c.y)return g?{y:a.y,x:a.x<b.x?m[k].xMin-1:m[k].xMax+1,obstacle:m[k]}:{x:a.x,y:a.y<b.y?m[k].yMin-1:m[k].yMax+1,obstacle:m[k]};k+=u}return b}function l(a,b,g,u,z){var k=z.soft,e=z.hard,c=u?"x":"y",m={x:b.x,y:b.y},f={x:b.x,y:b.y};z=a[c+"Max"]>=k[c+"Max"];k=a[c+"Min"]<=k[c+"Min"];var H=a[c+"Max"]>=e[c+"Max"];e=a[c+
"Min"]<=e[c+"Min"];var h=w(a[c+"Min"]-b[c]),v=w(a[c+"Max"]-b[c]);g=10>w(h-v)?b[c]<g[c]:v<h;f[c]=a[c+"Min"];m[c]=a[c+"Max"];a=d(b,f,u)[c]!==f[c];b=d(b,m,u)[c]!==m[c];g=a?b?g:!0:b?!1:g;g=k?z?g:!0:z?!1:g;return e?H?g:!0:H?!1:g}function x(b,c,e){if(b.x===c.x&&b.y===c.y)return[];var k=e?"x":"y",E=f.obstacleOptions.margin;var v={soft:{xMin:g,xMax:u,yMin:z,yMax:H},hard:f.hardBounds};var q=h(m,b);if(-1<q){q=m[q];v=l(q,b,c,e,v);n(q,f.hardBounds);var p=e?{y:b.y,x:q[v?"xMax":"xMin"]+(v?1:-1)}:{x:b.x,y:q[v?"yMax":
"yMin"]+(v?1:-1)};var B=h(m,p);-1<B&&(B=m[B],n(B,f.hardBounds),p[k]=v?y(q[k+"Max"]-E+1,(B[k+"Min"]+q[k+"Max"])/2):t(q[k+"Min"]+E-1,(B[k+"Max"]+q[k+"Min"])/2),b.x===p.x&&b.y===p.y?(a&&(p[k]=v?y(q[k+"Max"],B[k+"Max"])+1:t(q[k+"Min"],B[k+"Min"])-1),a=!a):a=!1);b=[{start:b,end:p}]}else k=d(b,{x:e?c.x:b.x,y:e?b.y:c.y},e),b=[{start:b,end:{x:k.x,y:k.y}}],k[e?"x":"y"]!==c[e?"x":"y"]&&(v=l(k.obstacle,k,c,!e,v),n(k.obstacle,f.hardBounds),v={x:e?k.x:k.obstacle[v?"xMax":"xMin"]+(v?1:-1),y:e?k.obstacle[v?"yMax":
"yMin"]+(v?1:-1):k.y},e=!e,b=b.concat(x({x:k.x,y:k.y},v,e)));return b=b.concat(x(b[b.length-1].end,c,!e))}function r(b,a,g){var c=t(b.xMax-a.x,a.x-b.xMin)<t(b.yMax-a.y,a.y-b.yMin);g=l(b,a,g,c,{soft:f.hardBounds,hard:f.hardBounds});return c?{y:a.y,x:b[g?"xMax":"xMin"]+(g?1:-1)}:{x:a.x,y:b[g?"yMax":"yMin"]+(g?1:-1)}}var I=F(f.startDirectionX,w(c.x-e.x)>w(c.y-e.y)),A=I?"x":"y",G=[],a=!1,b=f.obstacleMetrics,g=t(e.x,c.x)-b.maxWidth-10,u=y(e.x,c.x)+b.maxWidth+10,z=t(e.y,c.y)-b.maxHeight-10,H=y(e.y,c.y)+
b.maxHeight+10,m=f.chartObstacles;var E=p(m,g);b=p(m,u);m=m.slice(E,b+1);if(-1<(b=h(m,c))){var q=r(m[b],c,e);G.push({end:c,start:q});c=q}for(;-1<(b=h(m,c));)E=0>c[A]-e[A],q={x:c.x,y:c.y},q[A]=m[b][E?A+"Max":A+"Min"]+(E?1:-1),G.push({end:c,start:q}),c=q;e=x(e,c,I);e=e.concat(G.reverse());return{path:C(e),obstacles:e}},{requiresObstacles:!0})}});l(d,"parts-gantt/ArrowSymbols.js",[d["parts/Globals.js"]],function(d){d.SVGRenderer.prototype.symbols.arrow=function(d,h,l,n){return[["M",d,h+n/2],["L",d+l,
h],["L",d,h+n/2],["L",d+l,h+n]]};d.SVGRenderer.prototype.symbols["arrow-half"]=function(p,h,l,n){return d.SVGRenderer.prototype.symbols.arrow(p,h,l/2,n)};d.SVGRenderer.prototype.symbols["triangle-left"]=function(d,h,l,n){return[["M",d+l,h],["L",d,h+n/2],["L",d+l,h+n],["Z"]]};d.SVGRenderer.prototype.symbols["arrow-filled"]=d.SVGRenderer.prototype.symbols["triangle-left"];d.SVGRenderer.prototype.symbols["triangle-left-half"]=function(p,h,l,n){return d.SVGRenderer.prototype.symbols["triangle-left"](p,
h,l/2,n)};d.SVGRenderer.prototype.symbols["arrow-filled-half"]=d.SVGRenderer.prototype.symbols["triangle-left-half"]});l(d,"parts-gantt/Pathfinder.js",[d["parts/Globals.js"],d["parts/Point.js"],d["parts/Utilities.js"],d["parts-gantt/PathfinderAlgorithms.js"]],function(d,l,h,x){function n(a){var b=a.shapeArgs;return b?{xMin:b.x,xMax:b.x+b.width,yMin:b.y,yMax:b.y+b.height}:(b=a.graphic&&a.graphic.getBBox())?{xMin:a.plotX-b.width/2,xMax:a.plotX+b.width/2,yMin:a.plotY-b.height/2,yMax:a.plotY+b.height/
2}:null}function p(a){for(var b=a.length,g=0,c,e,d=[],m=function(b,a,g){g=J(g,10);var c=b.yMax+g>a.yMin-g&&b.yMin-g<a.yMax+g,e=b.xMax+g>a.xMin-g&&b.xMin-g<a.xMax+g,d=c?b.xMin>a.xMax?b.xMin-a.xMax:a.xMin-b.xMax:Infinity,u=e?b.yMin>a.yMax?b.yMin-a.yMax:a.yMin-b.yMax:Infinity;return e&&c?g?m(b,a,Math.floor(g/2)):Infinity:G(d,u)};g<b;++g)for(c=g+1;c<b;++c)e=m(a[g],a[c]),80>e&&d.push(e);d.push(80);return A(Math.floor(d.sort(function(b,a){return b-a})[Math.floor(d.length/10)]/2-1),1)}function F(a,b,g){this.init(a,
b,g)}function t(a){this.init(a)}function y(a){if(a.options.pathfinder||a.series.reduce(function(b,a){a.options&&D(!0,a.options.connectors=a.options.connectors||{},a.options.pathfinder);return b||a.options&&a.options.pathfinder},!1))D(!0,a.options.connectors=a.options.connectors||{},a.options.pathfinder),c('WARNING: Pathfinder options have been renamed. Use "chart.connectors" or "series.connectors" instead.')}"";var w=h.addEvent,e=h.defined,c=h.error,f=h.extend,D=h.merge,C=h.objectEach,J=h.pick,r=
h.splat,I=d.deg2rad,A=Math.max,G=Math.min;f(d.defaultOptions,{connectors:{type:"straight",lineWidth:1,marker:{enabled:!1,align:"center",verticalAlign:"middle",inside:!1,lineWidth:1},startMarker:{symbol:"diamond"},endMarker:{symbol:"arrow-filled"}}});F.prototype={init:function(a,b,g){this.fromPoint=a;this.toPoint=b;this.options=g;this.chart=a.series.chart;this.pathfinder=this.chart.pathfinder},renderPath:function(a,b,g){var c=this.chart,e=c.styledMode,d=c.pathfinder,m=!c.options.chart.forExport&&!1!==
g,f=this.graphics&&this.graphics.path;d.group||(d.group=c.renderer.g().addClass("highcharts-pathfinder-group").attr({zIndex:-1}).add(c.seriesGroup));d.group.translate(c.plotLeft,c.plotTop);f&&f.renderer||(f=c.renderer.path().add(d.group),e||f.attr({opacity:0}));f.attr(b);a={d:a};e||(a.opacity=1);f[m?"animate":"attr"](a,g);this.graphics=this.graphics||{};this.graphics.path=f},addMarker:function(a,b,g){var c=this.fromPoint.series.chart,e=c.pathfinder;c=c.renderer;var d="start"===a?this.fromPoint:this.toPoint,
f=d.getPathfinderAnchorPoint(b);if(b.enabled&&((g="start"===a?g[1]:g[g.length-2])&&"M"===g[0]||"L"===g[0])){g={x:g[1],y:g[2]};g=d.getRadiansToVector(g,f);f=d.getMarkerVector(g,b.radius,f);g=-g/I;if(b.width&&b.height){var h=b.width;var q=b.height}else h=q=2*b.radius;this.graphics=this.graphics||{};f={x:f.x-h/2,y:f.y-q/2,width:h,height:q,rotation:g,rotationOriginX:f.x,rotationOriginY:f.y};this.graphics[a]?this.graphics[a].animate(f):(this.graphics[a]=c.symbol(b.symbol).addClass("highcharts-point-connecting-path-"+
a+"-marker").attr(f).add(e.group),c.styledMode||this.graphics[a].attr({fill:b.color||this.fromPoint.color,stroke:b.lineColor,"stroke-width":b.lineWidth,opacity:0}).animate({opacity:1},d.series.options.animation))}},getPath:function(a){var b=this.pathfinder,g=this.chart,e=b.algorithms[a.type],d=b.chartObstacles;if("function"!==typeof e)c('"'+a.type+'" is not a Pathfinder algorithm.');else return e.requiresObstacles&&!d&&(d=b.chartObstacles=b.getChartObstacles(a),g.options.connectors.algorithmMargin=
a.algorithmMargin,b.chartObstacleMetrics=b.getObstacleMetrics(d)),e(this.fromPoint.getPathfinderAnchorPoint(a.startMarker),this.toPoint.getPathfinderAnchorPoint(a.endMarker),D({chartObstacles:d,lineObstacles:b.lineObstacles||[],obstacleMetrics:b.chartObstacleMetrics,hardBounds:{xMin:0,xMax:g.plotWidth,yMin:0,yMax:g.plotHeight},obstacleOptions:{margin:a.algorithmMargin},startDirectionX:b.getAlgorithmStartDirection(a.startMarker)},a))},render:function(){var a=this.fromPoint,b=a.series,g=b.chart,c=g.pathfinder,
d=D(g.options.connectors,b.options.connectors,a.options.connectors,this.options),f={};g.styledMode||(f.stroke=d.lineColor||a.color,f["stroke-width"]=d.lineWidth,d.dashStyle&&(f.dashstyle=d.dashStyle));f["class"]="highcharts-point-connecting-path highcharts-color-"+a.colorIndex;d=D(f,d);e(d.marker.radius)||(d.marker.radius=G(A(Math.ceil((d.algorithmMargin||8)/2)-1,1),5));a=this.getPath(d);g=a.path;a.obstacles&&(c.lineObstacles=c.lineObstacles||[],c.lineObstacles=c.lineObstacles.concat(a.obstacles));
this.renderPath(g,f,b.options.animation);this.addMarker("start",D(d.marker,d.startMarker),g);this.addMarker("end",D(d.marker,d.endMarker),g)},destroy:function(){this.graphics&&(C(this.graphics,function(a){a.destroy()}),delete this.graphics)}};t.prototype={algorithms:x,init:function(a){this.chart=a;this.connections=[];w(a,"redraw",function(){this.pathfinder.update()})},update:function(a){var b=this.chart,c=this,d=c.connections;c.connections=[];b.series.forEach(function(a){a.visible&&!a.options.isInternal&&
a.points.forEach(function(a){var d,e=a.options&&a.options.connect&&r(a.options.connect);a.visible&&!1!==a.isInside&&e&&e.forEach(function(e){d=b.get("string"===typeof e?e:e.to);d instanceof l&&d.series.visible&&d.visible&&!1!==d.isInside&&c.connections.push(new F(a,d,"string"===typeof e?{}:e))})})});for(var e=0,f,h,n=d.length,q=c.connections.length;e<n;++e){h=!1;for(f=0;f<q;++f)if(d[e].fromPoint===c.connections[f].fromPoint&&d[e].toPoint===c.connections[f].toPoint){c.connections[f].graphics=d[e].graphics;
h=!0;break}h||d[e].destroy()}delete this.chartObstacles;delete this.lineObstacles;c.renderConnections(a)},renderConnections:function(a){a?this.chart.series.forEach(function(a){var b=function(){var b=a.chart.pathfinder;(b&&b.connections||[]).forEach(function(b){b.fromPoint&&b.fromPoint.series===a&&b.render()});a.pathfinderRemoveRenderEvent&&(a.pathfinderRemoveRenderEvent(),delete a.pathfinderRemoveRenderEvent)};!1===a.options.animation?b():a.pathfinderRemoveRenderEvent=w(a,"afterAnimate",b)}):this.connections.forEach(function(a){a.render()})},
getChartObstacles:function(a){for(var b=[],c=this.chart.series,d=J(a.algorithmMargin,0),f,h=0,m=c.length;h<m;++h)if(c[h].visible&&!c[h].options.isInternal)for(var l=0,q=c[h].points.length,k;l<q;++l)k=c[h].points[l],k.visible&&(k=n(k))&&b.push({xMin:k.xMin-d,xMax:k.xMax+d,yMin:k.yMin-d,yMax:k.yMax+d});b=b.sort(function(a,b){return a.xMin-b.xMin});e(a.algorithmMargin)||(f=a.algorithmMargin=p(b),b.forEach(function(a){a.xMin-=f;a.xMax+=f;a.yMin-=f;a.yMax+=f}));return b},getObstacleMetrics:function(a){for(var b=
0,c=0,d,e,f=a.length;f--;)d=a[f].xMax-a[f].xMin,e=a[f].yMax-a[f].yMin,b<d&&(b=d),c<e&&(c=e);return{maxHeight:c,maxWidth:b}},getAlgorithmStartDirection:function(a){var b="top"!==a.verticalAlign&&"bottom"!==a.verticalAlign;return"left"!==a.align&&"right"!==a.align?b?void 0:!1:b?!0:void 0}};d.Connection=F;d.Pathfinder=t;f(l.prototype,{getPathfinderAnchorPoint:function(a){var b=n(this);switch(a.align){case "right":var c="xMax";break;case "left":c="xMin"}switch(a.verticalAlign){case "top":var d="yMin";
break;case "bottom":d="yMax"}return{x:c?b[c]:(b.xMin+b.xMax)/2,y:d?b[d]:(b.yMin+b.yMax)/2}},getRadiansToVector:function(a,b){var c;e(b)||(c=n(this))&&(b={x:(c.xMin+c.xMax)/2,y:(c.yMin+c.yMax)/2});return Math.atan2(b.y-a.y,a.x-b.x)},getMarkerVector:function(a,b,c){var d=2*Math.PI,e=n(this),f=e.xMax-e.xMin,g=e.yMax-e.yMin,h=Math.atan2(g,f),l=!1;f/=2;var k=g/2,p=e.xMin+f;e=e.yMin+k;for(var r=p,t=e,w={},x=1,y=1;a<-Math.PI;)a+=d;for(;a>Math.PI;)a-=d;d=Math.tan(a);a>-h&&a<=h?(y=-1,l=!0):a>h&&a<=Math.PI-
h?y=-1:a>Math.PI-h||a<=-(Math.PI-h)?(x=-1,l=!0):x=-1;l?(r+=x*f,t+=y*f*d):(r+=g/(2*d)*x,t+=y*k);c.x!==p&&(r=c.x);c.y!==e&&(t=c.y);w.x=r+b*Math.cos(a);w.y=t-b*Math.sin(a);return w}});d.Chart.prototype.callbacks.push(function(a){!1!==a.options.connectors.enabled&&(y(a),this.pathfinder=new t(this),this.pathfinder.update(!0))})});l(d,"masters/modules/pathfinder.src.js",[],function(){})});
//# sourceMappingURL=pathfinder.js.map