highcharts
Version:
JavaScript charting framework
11 lines • 5.94 kB
JavaScript
/**
* Highcharts JS v13.0.1 (2026-08-17)
* @module highcharts/modules/flowmap
* @requires highcharts
* @requires highcharts/modules/map
*
* (c) 2009-2026
*
* A commercial license may be required depending on use,
* see www.highcharts.com/license
*/import*as t from"../highcharts.js";let e={};e.n=t=>{let i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},e.d=(t,i)=>{if(Array.isArray(i))for(var o=0;o<i.length;){var s=i[o++],r=i[o++];e.o(t,s)?0===r&&o++:0===r?Object.defineProperty(t,s,{enumerable:!0,value:i[o++]}):Object.defineProperty(t,s,{enumerable:!0,get:r})}else for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=t.default;var o=e.n(i);let s=t.default.SeriesRegistry;var r=e.n(s);let{seriesTypes:{mapline:{prototype:{pointClass:n}}}}=r(),a=class extends n{isValid(){let t=!!(this.options.to&&this.options.from);return[this.options.to,this.options.from].forEach(function(e){t=!!(t&&e&&((0,i.isString)(e)||(0,i.isNumber)((0,i.pick)(e[0],e.lat))&&(0,i.isNumber)((0,i.pick)(e[1],e.lon))))}),t}},{series:{prototype:{pointClass:p}},seriesTypes:{column:l,map:h,mapline:d}}=r();class f extends d{static getLength(t,e){return Math.sqrt(t*t+e*e)}static normalize(t,e){let i=this.getLength(t,e);return[t/i,e/i]}static markerEndPath(t,e,o,s){let r=(0,i.relativeLength)(s.width||0,this.getLength(e[0]-t[0],e[1]-t[1])),n=s.markerType||"arrow",[a,p]=this.normalize(e[0]-t[0],e[1]-t[1]),l=[];if("arrow"===n){let[i,s]=t;i-=a*r,s-=p*r,l.push(["L",i,s]),l.push(["L",o[0],o[1]]),[i,s]=e,i+=a*r,s+=p*r,l.push(["L",i,s])}if("mushroom"===n){let[i,s]=t,[n,h]=e,[d,f]=o,g=(n-i)/2+i,m=(h-s)/2+s;i-=a*r,s-=p*r,l.push(["L",i,s]),n+=a*r,h+=p*r,l.push(["Q",(d-g)*2+g,(f-m)*2+m,n,h])}return l}animate(t){let e=this.points;t||e.forEach(t=>{if(t.shapeArgs&&(0,i.isArray)(t.shapeArgs.d)&&t.shapeArgs.d.length){let e=t.shapeArgs.d,i=e[0][1],o=e[0][2];if(i&&o){let s=[];for(let t=0;t<e.length;t++){s.push([...e[t]]);for(let r=1;r<e[t].length;r++)s[t][r]=r%2?i:o}t.graphic&&(t.graphic.attr({d:s}),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 s=this.smallestWeight,r=this.greatestWeight;if(!(0,i.defined)(o)||!s||!r)return 0;let n=this.options.minWidth;return(o-s)*(this.options.maxWidth-n)/(r-s||1)+n}autoCurve(t,e,i,o,s,r){let n={x:i-t,y:o-e},a={x:(i-t)/2+t,y:(o-e)/2+e},p={x:a.x-s,y:a.y-r},l=n.x*p.x+n.y*p.y,h=Math.atan2(n.x*p.y-n.y*p.x,l),d=180*h/Math.PI;return d<0&&(d=360+d),-(.7*Math.sin(h=d*Math.PI/180))}pointAttribs(t,e){let o=h.prototype.pointAttribs.call(this,t,e);return o.fill=(0,i.pick)(t.options.fillColor,t.options.color,"none"===this.options.fillColor?null:this.options.fillColor,this.color),o["fill-opacity"]=(0,i.pick)(t.options.fillOpacity,this.options.fillOpacity),o["stroke-width"]=(0,i.pick)(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(s=>{let r,n,a=this.chart,l=a.mapView,h=s.options,d=()=>{s.series.isDirty=!0},f=t=>{let e=a.get(t);if(e instanceof p&&e.plotX&&e.plotY)return(0,i.addEvent)(e,"update",d),{x:e.plotX,y:e.plotY}},g=t=>(0,i.isArray)(t)?{lon:t[0],lat:t[1]}:t;"string"==typeof h.from?r=f(h.from):"object"==typeof h.from&&l&&(r=l.lonLatToPixels(g(h.from))),"string"==typeof h.to?n=f(h.to):"object"==typeof h.to&&l&&(n=l.lonLatToPixels(g(h.to))),s.fromPos=r,s.toPos=n,r&&n&&(e+=(r.x+n.x)/2,o+=(r.y+n.y)/2),(0,i.pick)(s.options.weight,this.options.weight)&&t.push((0,i.pick)(s.options.weight,this.options.weight))}),this.smallestWeight=(0,i.arrayMin)(t),this.greatestWeight=(0,i.arrayMax)(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=(0,i.pick)(t.options.color,t.series.color)})}getPointShapeArgs(t){let{fromPos:e,toPos:o}=t;if(!e||!o)return{};let s=this.getLinkWidth(t)/2,r=t.options,n=(0,i.merge)(this.options.markerEnd,r.markerEnd),a=(0,i.pick)(r.growTowards,this.options.growTowards),p=e.x||0,l=e.y||0,h=o.x||0,d=o.y||0,g=(0,i.pick)(r.curveFactor,this.options.curveFactor),m=n&&n.enabled&&n.height||0;if((0,i.defined)(g)||(g=this.autoCurve(p,l,h,d,this.centerOfPoints.x,this.centerOfPoints.y)),m){m=(0,i.relativeLength)(m,4*s);let t=h-p,e=d-l,o=p+(t*=.5),r=l+(e*=.5),n=t,a=o+(t=e)*g,c=r+(e=-n)*g,[y,u]=f.normalize(a-h,c-d);y*=m,u*=m,h+=y,d+=u}let c=h-p,y=d-l,u=p+(c*=.5),w=l+(y*=.5),x=c;c=y,y=-x;let[P,b]=f.normalize(c,y),k=1+.25*Math.sqrt(g*g);P*=s*k,b*=s*k;let L=u+c*g,A=w+y*g,[v,W]=f.normalize(L-p,A-l);x=v,v=W,W=-x,v*=s,W*=s;let[O,M]=f.normalize(L-h,A-d);x=O,O=-M,M=x,O*=s,M*=s,a&&(v/=s,W/=s,P/=4,b/=4);let C={d:[["M",p-v,l-W],["Q",L-P,A-b,h-O,d-M],["L",h+O,d+M],["Q",L+P,A+b,p+v,l+W],["Z"]]};if(n&&n.enabled&&C.d){let t=f.markerEndPath([h-O,d-M],[h+O,d+M],[o.x,o.y],n);C.d.splice(2,0,...t)}let E=t.options.from,T=t.options.to,j=E.lat,z=E.lon,D=T.lat,S=T.lon;return j&&z&&(t.options.from=`${+j}, ${+z}`),D&&S&&(t.options.to=`${+D}, ${+S}`),C}}f.defaultOptions=(0,i.merge)(d.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>"}}),(0,i.extend)(f.prototype,{pointClass:a,pointArrayMap:["from","to","weight"],drawPoints:l.prototype.drawPoints,getDataColumnKeys:l.prototype.getDataColumnKeys,useMapGeometry:!0}),r().registerSeriesType("flowmap",f);let g=o();export{g as default};