highcharts
Version:
JavaScript charting framework
13 lines • 6 kB
JavaScript
/**
* Highcharts JS v13.0.1 (2026-08-17)
* @module highcharts/modules/windbarb
* @requires highcharts
*
* Wind barb series module
*
* (c) 2010-2026 Highsoft AS
* Author: Torstein Hønsi
*
* A commercial license may be required depending on use,
* see www.highcharts.com/license
*/import*as t from"../highcharts.js";import*as e from"./datagrouping.js";let r={};r.n=t=>{let e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{if(Array.isArray(e))for(var o=0;o<e.length;){var i=e[o++],s=e[o++];r.o(t,i)?0===s&&o++:0===s?Object.defineProperty(t,i,{enumerable:!0,value:e[o++]}):Object.defineProperty(t,i,{enumerable:!0,get:s})}else for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let o=t.default;var i,s=r.n(o);let a=e.default.dataGrouping.approximations;var l=r.n(a);let n=t.default.Series.types.column;var p=r.n(n);let h=t.default.Series;var d=r.n(h);let{composed:u}=s(),{prototype:f}=p(),{prototype:c}=d();var g=i||(i={});function b(t){return c.getPlotBox.call(this.options.onSeries&&this.chart.get(this.options.onSeries)||this,t)}function y(){f.translate.apply(this);let t=this,e=t.options,r=t.chart,i=t.points,s=e.onSeries,a=s&&r.get(s),l=a&&a.options.step,n=a&&a.points,p=r.inverted,h=t.xAxis,d=t.yAxis,u=i.length-1,c,g,b=e.onKey||"y",y=n&&n.length,x=0,m,v,L,S,w;if(a&&a.visible&&y){for(x=(a.pointXOffset||0)+(a.barW||0)/2,S=a.currentDataGrouping,v=n[y-1].x+(S?S.totalRange:0),(0,o.stableSort)(i,(t,e)=>t.x-e.x),b="plot"+b[0].toUpperCase()+b.substr(1);y--&&i[u];)if(m=n[y],(c=i[u]).y=m.y,m.x<=c.x&&void 0!==m[b]){if(c.x<=v&&(c.plotY=m[b],m.x<c.x&&!l&&(L=n[y+1]))&&void 0!==L[b])if((0,o.defined)(c.plotX)&&a.is("spline")){let t=[m.plotX||0,m.plotY||0],e=[L.plotX||0,L.plotY||0],r=m.controlPoints?.high||t,i=L.controlPoints?.low||e,s=(o,s)=>Math.pow(1-o,3)*t[s]+3*(1-o)*(1-o)*o*r[s]+3*(1-o)*o*o*i[s]+o*o*o*e[s],a=0,l=1,n;for(let t=0;t<100;t++){let t=(a+l)/2,e=s(t,0);if(null===e)break;if(.25>Math.abs(e-c.plotX)){n=t;break}e<c.plotX?a=t:l=t}(0,o.defined)(n)&&(c.plotY=s(n,1),c.y=d.toValue(c.plotY,!0))}else w=(c.x-m.x)/(L.x-m.x),c.plotY+=w*(L[b]-m[b]),c.y+=w*(L.y-m.y);if(u--,y++,u<0)break}}i.forEach((e,r)=>{let s;e.plotX+=x,(void 0===e.plotY||p)&&(e.plotX>=0&&e.plotX<=h.len?p?(e.plotY=h.translate(e.x,0,1,0,1),e.plotX=(0,o.defined)(e.y)?d.translate(e.y,0,0,0,1):0):e.plotY=(h.opposite?0:t.yAxis.len)+h.offset:e.shapeArgs={}),(g=i[r-1])&&g.plotX===e.plotX&&(void 0===g.stackIndex&&(g.stackIndex=0),s=g.stackIndex+1),e.stackIndex=s}),this.onSeries=a}g.compose=function(t){if((0,o.pushUnique)(u,"OnSeries")){let e=t.prototype;e.getPlotBox=b,e.translate=y}return t},g.getPlotBox=b,g.translate=y;let x=i,m=t.default.SeriesRegistry;var v=r.n(m);class L extends p().prototype.pointClass{isValid(){return(0,o.isNumber)(this.value)&&this.value>=0}}let{column:S}=v().seriesTypes;class w extends S{init(t,e){super.init(t,e)}pointAttribs(t,e){let r=this.options,o=t?.color||this.color,i=r.lineWidth;return e&&(o=r.states?.[e]?.color||o,i=(r.states?.[e]?.lineWidthPlus||0)+(r.states?.[e]?.lineWidth||i||0)),{stroke:o,"stroke-width":i}}windArrow(t){let e=t.beaufortLevel,r=this.options.vectorLength/20,o=1.943844*t.value,i,s=-10;if(t.isNull)return[];if(0===e)return this.chart.renderer.symbols.circle(-10*r,-10*r,20*r,20*r);let a=[["M",0,7*r],["L",-1.5*r,7*r],["L",0,10*r],["L",1.5*r,7*r],["L",0,7*r],["L",0,-10*r]];if((i=(o-o%50)/50)>0)for(;i--;)a.push(-10===s?["L",0,s*r]:["M",0,s*r],["L",5*r,s*r+2],["L",0,s*r+4]),o-=50,s+=7;if((i=(o-o%10)/10)>0)for(;i--;)a.push(-10===s?["L",0,s*r]:["M",0,s*r],["L",7*r,s*r]),o-=10,s+=3;if((i=(o-o%5)/5)>0)for(;i--;)a.push(-10===s?["L",0,s*r]:["M",0,s*r],["L",4*r,s*r]),o-=5,s+=3;return a}drawPoints(){let t=this.chart,e=this.yAxis,r=t.inverted,i=this.options.vectorLength/2;for(let s of this.points){let a=s.plotX,l=s.plotY;!1===this.options.clip||t.isInsidePlot(a,0)?(s.graphic||(s.graphic=this.chart.renderer.path().add(this.markerGroup).addClass("highcharts-point highcharts-color-"+(0,o.pick)(s.colorIndex,s.series.colorIndex))),s.graphic.attr({d:this.windArrow(s),translateX:a+this.options.xOffset,translateY:l+this.options.yOffset,rotation:s.direction}),this.chart.styledMode||s.graphic.attr(this.pointAttribs(s))):s.graphic&&(s.graphic=s.graphic.destroy()),s.tooltipPos=[a+this.options.xOffset+(r&&!this.onSeries?i:0),l+this.options.yOffset-(r?0:i+e.pos-t.plotTop)]}}animate(t){t?this.markerGroup.attr({opacity:.01}):this.markerGroup.animate({opacity:1},(0,o.animObject)(this.options.animation))}markerAttribs(){return{}}getExtremes(){return{}}shouldShowTooltip(t,e,r={}){return r.ignoreX=this.chart.inverted,r.ignoreY=!r.ignoreX,super.shouldShowTooltip(t,e,r)}}w.defaultOptions=(0,o.merge)(S.defaultOptions,{dataGrouping:{enabled:!0,approximation:"windbarb",groupPixelWidth:30},lineWidth:2,onSeries:null,states:{hover:{lineWidthPlus:0}},tooltip:{pointFormat:'<span style="color:{point.color}">●</span> {series.name}: <b>{point.value}</b> ({point.beaufort})<br/>'},vectorLength:20,colorKey:"value",yOffset:-20,xOffset:0}),x.compose(w),(0,o.extend)(w.prototype,{beaufortFloor:[0,.3,1.6,3.4,5.5,8,10.8,13.9,17.2,20.8,24.5,28.5,32.7],beaufortName:["Calm","Light air","Light breeze","Gentle breeze","Moderate breeze","Fresh breeze","Strong breeze","Near gale","Gale","Strong gale","Storm","Violent storm","Hurricane"],invertible:!1,parallelArrays:["x","value","direction"],pointArrayMap:["value","direction"],pointClass:L,trackerGroups:["markerGroup"],translate:function(){let t=this.beaufortFloor,e=this.beaufortName;for(let r of(x.translate.call(this),this.points)){let o=0;for(;o<t.length&&!(t[o]>r.value);o++);r.beaufortLevel=o-1,r.beaufort=e[o-1]}}}),v().registerSeriesType("windbarb",w),l().windbarb||(l().windbarb=(t,e)=>{let r=0,o=0;for(let i=0,a=t.length;i<a;i++)r+=t[i]*Math.cos(e[i]*s().deg2rad),o+=t[i]*Math.sin(e[i]*s().deg2rad);return[t.reduce((t,e)=>t+e,0)/t.length,Math.atan2(o,r)/s().deg2rad]});let O=s();export{O as default};