UNPKG

highcharts

Version:
10 lines 6.16 kB
!/** * Highcharts JS v12.5.0 (2026-01-12) * @module highcharts/modules/flowmap * @requires highcharts * * (c) 2009-2026 * * A commercial license may be required depending on use. * See www.highcharts.com/license */function(t,o){"object"==typeof exports&&"object"==typeof module?module.exports=o(t._Highcharts,t._Highcharts.SeriesRegistry):"function"==typeof define&&define.amd?define("highcharts/modules/flowmap",["highcharts/highcharts"],function(t){return o(t,t.SeriesRegistry)}):"object"==typeof exports?exports["highcharts/modules/flowmap"]=o(t._Highcharts,t._Highcharts.SeriesRegistry):t.Highcharts=o(t.Highcharts,t.Highcharts.SeriesRegistry)}("u"<typeof window?this:window,(t,o)=>(()=>{"use strict";var e={512:t=>{t.exports=o},944:o=>{o.exports=t}},i={};function s(t){var o=i[t];if(void 0!==o)return o.exports;var r=i[t]={exports:{}};return e[t](r,r.exports,s),r.exports}s.n=t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return s.d(o,{a:o}),o},s.d=(t,o)=>{for(var e in o)s.o(o,e)&&!s.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:o[e]})},s.o=(t,o)=>Object.prototype.hasOwnProperty.call(t,o);var r={};s.d(r,{default:()=>M});var n=s(944),a=s.n(n),h=s(512),p=s.n(h);let{seriesTypes:{mapline:{prototype:{pointClass:l}}}}=p(),{pick:f,isString:d,isNumber:g}=a(),c=class extends l{isValid(){let t=!!(this.options.to&&this.options.from);return[this.options.to,this.options.from].forEach(function(o){t=!!(t&&o&&(d(o)||g(f(o[0],o.lat))&&g(f(o[1],o.lon))))}),t}},{series:{prototype:{pointClass:m}},seriesTypes:{column:y,map:u,mapline:x}}=p(),{addEvent:w,arrayMax:P,arrayMin:b,defined:L,extend:W,isArray:v,merge:k,pick:A,relativeLength:O}=a();class C extends x{static getLength(t,o){return Math.sqrt(t*t+o*o)}static normalize(t,o){let e=this.getLength(t,o);return[t/e,o/e]}static markerEndPath(t,o,e,i){let s=O(i.width||0,this.getLength(o[0]-t[0],o[1]-t[1])),r=i.markerType||"arrow",[n,a]=this.normalize(o[0]-t[0],o[1]-t[1]),h=[];if("arrow"===r){let[i,r]=t;i-=n*s,r-=a*s,h.push(["L",i,r]),h.push(["L",e[0],e[1]]),[i,r]=o,i+=n*s,r+=a*s,h.push(["L",i,r])}if("mushroom"===r){let[i,r]=t,[p,l]=o,[f,d]=e,g=(p-i)/2+i,c=(l-r)/2+r;i-=n*s,r-=a*s,h.push(["L",i,r]),p+=n*s,l+=a*s,h.push(["Q",(f-g)*2+g,(d-c)*2+c,p,l])}return h}animate(t){let o=this.points;t||o.forEach(t=>{if(t.shapeArgs&&v(t.shapeArgs.d)&&t.shapeArgs.d.length){let o=t.shapeArgs.d,e=o[0][1],i=o[0][2];if(e&&i){let s=[];for(let t=0;t<o.length;t++){s.push([...o[t]]);for(let r=1;r<o[t].length;r++)s[t][r]=r%2?e:i}t.graphic&&(t.graphic.attr({d:s}),t.graphic.animate({d:o}))}}})}getLinkWidth(t){let o=this.options.width,e=t.options.weight||this.options.weight;if(t.options.weight=e,o&&!e)return o;let i=this.smallestWeight,s=this.greatestWeight;if(!L(e)||!i||!s)return 0;let r=this.options.minWidth;return(e-i)*(this.options.maxWidth-r)/(s-i||1)+r}autoCurve(t,o,e,i,s,r){let n={x:e-t,y:i-o},a={x:(e-t)/2+t,y:(i-o)/2+o},h={x:a.x-s,y:a.y-r},p=n.x*h.x+n.y*h.y,l=Math.atan2(n.x*h.y-n.y*h.x,p),f=180*l/Math.PI;return f<0&&(f=360+f),-(.7*Math.sin(l=f*Math.PI/180))}pointAttribs(t,o){let e=u.prototype.pointAttribs.call(this,t,o);return e.fill=A(t.options.fillColor,t.options.color,"none"===this.options.fillColor?null:this.options.fillColor,this.color),e["fill-opacity"]=A(t.options.fillOpacity,this.options.fillOpacity),e["stroke-width"]=A(t.options.lineWidth,this.options.lineWidth,1),t.options.opacity&&(e.opacity=t.options.opacity),e}translate(){this.chart.hasRendered&&(this.isDirtyData||!this.hasRendered)&&(this.processData(),this.generatePoints());let t=[],o=0,e=0;this.points.forEach(i=>{let s,r,n=this.chart,a=n.mapView,h=i.options,p=()=>{i.series.isDirty=!0},l=t=>{let o=n.get(t);if(o instanceof m&&o.plotX&&o.plotY)return w(o,"update",p),{x:o.plotX,y:o.plotY}},f=t=>v(t)?{lon:t[0],lat:t[1]}:t;"string"==typeof h.from?s=l(h.from):"object"==typeof h.from&&a&&(s=a.lonLatToPixels(f(h.from))),"string"==typeof h.to?r=l(h.to):"object"==typeof h.to&&a&&(r=a.lonLatToPixels(f(h.to))),i.fromPos=s,i.toPos=r,s&&r&&(o+=(s.x+r.x)/2,e+=(s.y+r.y)/2),A(i.options.weight,this.options.weight)&&t.push(A(i.options.weight,this.options.weight))}),this.smallestWeight=b(t),this.greatestWeight=P(t),this.centerOfPoints={x:o/this.points.length,y:e/this.points.length},this.points.forEach(t=>{if(!this.getLinkWidth(t)){t.shapeArgs={d:[]};return}t.fromPos&&(t.plotX=t.fromPos.x,t.plotY=t.fromPos.y),t.shapeType="path",t.shapeArgs=this.getPointShapeArgs(t),t.color=A(t.options.color,t.series.color)})}getPointShapeArgs(t){let{fromPos:o,toPos:e}=t;if(!o||!e)return{};let i=this.getLinkWidth(t)/2,s=t.options,r=k(this.options.markerEnd,s.markerEnd),n=A(s.growTowards,this.options.growTowards),a=o.x||0,h=o.y||0,p=e.x||0,l=e.y||0,f=A(s.curveFactor,this.options.curveFactor),d=r&&r.enabled&&r.height||0;if(L(f)||(f=this.autoCurve(a,h,p,l,this.centerOfPoints.x,this.centerOfPoints.y)),d){d=O(d,4*i);let t=p-a,o=l-h,e=a+(t*=.5),s=h+(o*=.5),r=t,n=e+(t=o)*f,g=s+(o=-r)*f,[c,m]=C.normalize(n-p,g-l);c*=d,m*=d,p+=c,l+=m}let g=p-a,c=l-h,m=a+(g*=.5),y=h+(c*=.5),u=g;g=c,c=-u;let[x,w]=C.normalize(g,c),P=1+.25*Math.sqrt(f*f);x*=i*P,w*=i*P;let b=m+g*f,W=y+c*f,[v,M]=C.normalize(b-a,W-h);u=v,v=M,M=-u,v*=i,M*=i;let[T,E]=C.normalize(b-p,W-l);u=T,T=-E,E=u,T*=i,E*=i,n&&(v/=i,M/=i,x/=4,w/=4);let j={d:[["M",a-v,h-M],["Q",b-x,W-w,p-T,l-E],["L",p+T,l+E],["Q",b+x,W+w,a+v,h+M],["Z"]]};if(r&&r.enabled&&j.d){let t=C.markerEndPath([p-T,l-E],[p+T,l+E],[e.x,e.y],r);j.d.splice(2,0,...t)}let z=t.options.from,H=t.options.to,S=z.lat,R=z.lon,_=H.lat,D=H.lon;return S&&R&&(t.options.from=`${+S}, ${+R}`),_&&D&&(t.options.to=`${+_}, ${+D}`),j}}C.defaultOptions=k(x.defaultOptions,{animation:!0,dataLabels:{enabled:!1},fillOpacity:.5,markerEnd:{enabled:!0,height:"40%",width:"40%",markerType:"arrow"},width:1,maxWidth:25,minWidth:5,lineWidth:void 0,tooltip:{headerFormat:'<span style="font-size: 0.8em">{series.name}</span><br/>',pointFormat:"{point.options.from} → {point.options.to}: <b>{point.options.weight}</b>"}}),W(C.prototype,{pointClass:c,pointArrayMap:["from","to","weight"],drawPoints:y.prototype.drawPoints,dataColumnKeys:y.prototype.dataColumnKeys,useMapGeometry:!0}),p().registerSeriesType("flowmap",C);let M=a();return r.default})());