UNPKG

highcharts

Version:
10 lines 7.08 kB
/** * Highcharts JS v12.6.0 (2026-04-13) * @module highcharts/modules/flowmap * @requires highcharts * * (c) 2009-2026 * * 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 o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},e.d=(t,o)=>{for(var i in o)e.o(o,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:o[i]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let o=t.default;var i=e.n(o);let r=t.default.SeriesRegistry;var s=e.n(r);let{doc:n,win:a}=i();function l(t){return f(t)&&"number"==typeof t.nodeType}function p(t){return"number"==typeof t&&!isNaN(t)&&t<1/0&&t>-1/0}function h(t){let e=Object.prototype.toString.call(t);return"[object Array]"===e||"[object Array Iterator]"===e}function f(t,e){return!!t&&"object"==typeof t&&(!e||!h(t))}function c(t,...e){let o,i=[t,...e],r={},s=function(t,e){return"object"!=typeof t&&(t={}),function(t,e,o){for(let i in t)Object.hasOwnProperty.call(t,i)&&e.call(o||t[i],t[i],i,t)}(e,function(o,i){if("__proto__"!==i&&"constructor"!==i){let r;!f(o,!0)||(r=o?.constructor,f(o,!0)&&!l(o)&&r?.name&&"Object"!==r.name)||l(o)?t[i]=e[i]:t[i]=s(t[i]||{},o)}}),t};!0===t&&(r=i[1],i=Array.prototype.slice.call(i,2));let n=i.length;for(o=0;o<n;o++)r=s(r,i[o]);return r}Array.prototype.find;function u(){let t=arguments,e=t.length;for(let o=0;o<e;o++){let e=t[o];if(null!=e)return e}}function d(t,e,o){return/%$/.test(t)?e*parseFloat(t)/100+(o||0):parseFloat(t)}let{seriesTypes:{mapline:{prototype:{pointClass:y}}}}=s(),g=class extends y{isValid(){let t=!!(this.options.to&&this.options.from);return[this.options.to,this.options.from].forEach(function(e){t=!!(t&&e&&("string"==typeof e||p(u(e[0],e.lat))&&p(u(e[1],e.lon))))}),t}},{series:{prototype:{pointClass:m}},seriesTypes:{column:w,map:b,mapline:P}}=s();class x extends P{static getLength(t,e){return Math.sqrt(t*t+e*e)}static normalize(t,e){let o=this.getLength(t,e);return[t/o,e/o]}static markerEndPath(t,e,o,i){let r=d(i.width||0,this.getLength(e[0]-t[0],e[1]-t[1])),s=i.markerType||"arrow",[n,a]=this.normalize(e[0]-t[0],e[1]-t[1]),l=[];if("arrow"===s){let[i,s]=t;i-=n*r,s-=a*r,l.push(["L",i,s]),l.push(["L",o[0],o[1]]),[i,s]=e,i+=n*r,s+=a*r,l.push(["L",i,s])}if("mushroom"===s){let[i,s]=t,[p,h]=e,[f,c]=o,u=(p-i)/2+i,d=(h-s)/2+s;i-=n*r,s-=a*r,l.push(["L",i,s]),p+=n*r,h+=a*r,l.push(["Q",(f-u)*2+u,(c-d)*2+d,p,h])}return l}animate(t){let e=this.points;t||e.forEach(t=>{if(t.shapeArgs&&h(t.shapeArgs.d)&&t.shapeArgs.d.length){let e=t.shapeArgs.d,o=e[0][1],i=e[0][2];if(o&&i){let r=[];for(let t=0;t<e.length;t++){r.push([...e[t]]);for(let s=1;s<e[t].length;s++)r[t][s]=s%2?o:i}t.graphic&&(t.graphic.attr({d:r}),t.graphic.animate({d:e}))}}})}getLinkWidth(t){let e=this.options.width,o=t.options.weight||this.options.weight;if(t.options.weight=o,e&&!o)return e;let i=this.smallestWeight,r=this.greatestWeight;if(null==o||!i||!r)return 0;let s=this.options.minWidth;return(o-i)*(this.options.maxWidth-s)/(r-i||1)+s}autoCurve(t,e,o,i,r,s){let n={x:o-t,y:i-e},a={x:(o-t)/2+t,y:(i-e)/2+e},l={x:a.x-r,y:a.y-s},p=n.x*l.x+n.y*l.y,h=Math.atan2(n.x*l.y-n.y*l.x,p),f=180*h/Math.PI;return f<0&&(f=360+f),-(.7*Math.sin(h=f*Math.PI/180))}pointAttribs(t,e){let o=b.prototype.pointAttribs.call(this,t,e);return o.fill=u(t.options.fillColor,t.options.color,"none"===this.options.fillColor?null:this.options.fillColor,this.color),o["fill-opacity"]=u(t.options.fillOpacity,this.options.fillOpacity),o["stroke-width"]=u(t.options.lineWidth,this.options.lineWidth,1),t.options.opacity&&(o.opacity=t.options.opacity),o}translate(){this.chart.hasRendered&&(this.isDirtyData||!this.hasRendered)&&(this.processData(),this.generatePoints());let t=[],e=0,o=0;this.points.forEach(r=>{let s,n,a=this.chart,l=a.mapView,p=r.options,f=()=>{r.series.isDirty=!0},c=t=>{let e=a.get(t);if(e instanceof m&&e.plotX&&e.plotY)return!function(t,e,o,r={}){let s="function"==typeof t&&t.prototype||t;Object.hasOwnProperty.call(s,"hcEvents")||(s.hcEvents={});let n=s.hcEvents;i().Point&&t instanceof i().Point&&t.series&&t.series.chart&&(t.series.chart.runTrackerClick=!0);let a=t.addEventListener;a&&a.call(t,e,o,!!i().supportsPassiveEvents&&{passive:void 0===r.passive?-1!==e.indexOf("touch"):r.passive,capture:!1}),n[e]||(n[e]=[]);let l={fn:o,order:"number"==typeof r.order?r.order:1/0};n[e].push(l),n[e].sort((t,e)=>t.order-e.order)}(e,"update",f),{x:e.plotX,y:e.plotY}},d=t=>h(t)?{lon:t[0],lat:t[1]}:t;"string"==typeof p.from?s=c(p.from):"object"==typeof p.from&&l&&(s=l.lonLatToPixels(d(p.from))),"string"==typeof p.to?n=c(p.to):"object"==typeof p.to&&l&&(n=l.lonLatToPixels(d(p.to))),r.fromPos=s,r.toPos=n,s&&n&&(e+=(s.x+n.x)/2,o+=(s.y+n.y)/2),u(r.options.weight,this.options.weight)&&t.push(u(r.options.weight,this.options.weight))}),this.smallestWeight=function(t){let e=t.length,o=t[0];for(;e--;)t[e]<o&&(o=t[e]);return o}(t),this.greatestWeight=function(t){let e=t.length,o=t[0];for(;e--;)t[e]>o&&(o=t[e]);return o}(t),this.centerOfPoints={x:e/this.points.length,y:o/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=u(t.options.color,t.series.color)})}getPointShapeArgs(t){let{fromPos:e,toPos:o}=t;if(!e||!o)return{};let i=this.getLinkWidth(t)/2,r=t.options,s=c(this.options.markerEnd,r.markerEnd),n=u(r.growTowards,this.options.growTowards),a=e.x||0,l=e.y||0,p=o.x||0,h=o.y||0,f=u(r.curveFactor,this.options.curveFactor),y=s&&s.enabled&&s.height||0;if(null==f&&(f=this.autoCurve(a,l,p,h,this.centerOfPoints.x,this.centerOfPoints.y)),y){y=d(y,4*i);let t=p-a,e=h-l,o=a+(t*=.5),r=l+(e*=.5),s=t,n=o+(t=e)*f,c=r+(e=-s)*f,[u,g]=x.normalize(n-p,c-h);u*=y,g*=y,p+=u,h+=g}let g=p-a,m=h-l,w=a+(g*=.5),b=l+(m*=.5),P=g;g=m,m=-P;let[v,O]=x.normalize(g,m),A=1+.25*Math.sqrt(f*f);v*=i*A,O*=i*A;let L=w+g*f,E=b+m*f,[W,j]=x.normalize(L-a,E-l);P=W,W=j,j=-P,W*=i,j*=i;let[k,T]=x.normalize(L-p,E-h);P=k,k=-T,T=P,k*=i,T*=i,n&&(W/=i,j/=i,v/=4,O/=4);let C={d:[["M",a-W,l-j],["Q",L-v,E-O,p-k,h-T],["L",p+k,h+T],["Q",L+v,E+O,a+W,l+j],["Z"]]};if(s&&s.enabled&&C.d){let t=x.markerEndPath([p-k,h-T],[p+k,h+T],[o.x,o.y],s);C.d.splice(2,0,...t)}let M=t.options.from,z=t.options.to,_=M.lat,F=M.lon,S=z.lat,$=z.lon;return _&&F&&(t.options.from=`${+_}, ${+F}`),S&&$&&(t.options.to=`${+S}, ${+$}`),C}}x.defaultOptions=c(P.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>"}}),function(t,e){let o;for(o in t||(t={}),e)t[o]=e[o]}(x.prototype,{pointClass:g,pointArrayMap:["from","to","weight"],drawPoints:w.prototype.drawPoints,dataColumnKeys:w.prototype.dataColumnKeys,useMapGeometry:!0}),s().registerSeriesType("flowmap",x);let v=i();export{v as default};