UNPKG

highcharts

Version:
13 lines 6.79 kB
/** * Highcharts JS v12.6.0 (2026-04-13) * @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";var o,r={};r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=t.default;var n=r.n(i);let s=e.default.dataGrouping.approximations;var l=r.n(s);let a=t.default.Series.types.column;var p=r.n(a);let h=t.default.Series;var f=r.n(h);let{doc:u,win:c}=n();function d(t){return g(t)&&"number"==typeof t.nodeType}function g(t,e){let o;return!!t&&"object"==typeof t&&(!e||"[object Array]"!==(o=Object.prototype.toString.call(t))&&"[object Array Iterator]"!==o)}Array.prototype.find;let{composed:b}=n(),{prototype:y}=p(),{prototype:x}=f();var v=o||(o={});function m(t){return x.getPlotBox.call(this.options.onSeries&&this.chart.get(this.options.onSeries)||this,t)}function L(){y.translate.apply(this);let t=this,e=t.options,o=t.chart,r=t.points,i=e.onSeries,n=i&&o.get(i),s=n&&n.options.step,l=n&&n.points,a=o.inverted,p=t.xAxis,h=t.yAxis,f=r.length-1,u,c,d=e.onKey||"y",g=l&&l.length,b=0,x,v,m,L,O;if(n&&n.visible&&g){for(b=(n.pointXOffset||0)+(n.barW||0)/2,L=n.currentDataGrouping,v=l[g-1].x+(L?L.totalRange:0),!function(t,e){let o,r,i=t.length;for(r=0;r<i;r++)t[r].safeI=r;for(t.sort(function(t,r){return 0===(o=e(t,r))?t.safeI-r.safeI:o}),r=0;r<i;r++)delete t[r].safeI}(r,(t,e)=>t.x-e.x),d="plot"+d[0].toUpperCase()+d.substr(1);g--&&r[f];)if(x=l[g],(u=r[f]).y=x.y,x.x<=u.x&&void 0!==x[d]){if(u.x<=v&&(u.plotY=x[d],x.x<u.x&&!s&&(m=l[g+1]))&&void 0!==m[d])if(null!=u.plotX&&n.is("spline")){let t=[x.plotX||0,x.plotY||0],e=[m.plotX||0,m.plotY||0],o=x.controlPoints?.high||t,r=m.controlPoints?.low||e,i=(i,n)=>Math.pow(1-i,3)*t[n]+3*(1-i)*(1-i)*i*o[n]+3*(1-i)*i*i*r[n]+i*i*i*e[n],n=0,s=1,l;for(let t=0;t<100;t++){let t=(n+s)/2,e=i(t,0);if(null===e)break;if(.25>Math.abs(e-u.plotX)){l=t;break}e<u.plotX?n=t:s=t}null!=l&&(u.plotY=i(l,1),u.y=h.toValue(u.plotY,!0))}else O=(u.x-x.x)/(m.x-x.x),u.plotY+=O*(m[d]-x[d]),u.y+=O*(m.y-x.y);if(f--,g++,f<0)break}}r.forEach((e,o)=>{let i;if(e.plotX+=b,void 0===e.plotY||a)if(e.plotX>=0&&e.plotX<=p.len)if(a)e.plotY=p.translate(e.x,0,1,0,1),e.plotX=null!=e.y?h.translate(e.y,0,0,0,1):0;else e.plotY=(p.opposite?0:t.yAxis.len)+p.offset;else e.shapeArgs={};(c=r[o-1])&&c.plotX===e.plotX&&(void 0===c.stackIndex&&(c.stackIndex=0),i=c.stackIndex+1),e.stackIndex=i}),this.onSeries=n}v.compose=function(t){var e;if(e="OnSeries",0>b.indexOf(e)&&b.push(e)){let e=t.prototype;e.getPlotBox=m,e.translate=L}return t},v.getPlotBox=m,v.translate=L;let O=o,w=t.default.SeriesRegistry;var S=r.n(w);class A extends p().prototype.pointClass{isValid(){var t;return"number"==typeof(t=this.value)&&!isNaN(t)&&t<1/0&&t>-1/0&&this.value>=0}}let{animObject:X}=n(),{column:k}=S().seriesTypes;class P extends k{init(t,e){super.init(t,e)}pointAttribs(t,e){let o=this.options,r=t.color||this.color,i=this.options.lineWidth;return e&&(r=o.states[e].color||r,i=(o.states[e].lineWidth||i)+(o.states[e].lineWidthPlus||0)),{stroke:r,"stroke-width":i}}windArrow(t){let e=t.beaufortLevel,o=this.options.vectorLength/20,r=1.943844*t.value,i,n=-10;if(t.isNull)return[];if(0===e)return this.chart.renderer.symbols.circle(-10*o,-10*o,20*o,20*o);let s=[["M",0,7*o],["L",-1.5*o,7*o],["L",0,10*o],["L",1.5*o,7*o],["L",0,7*o],["L",0,-10*o]];if((i=(r-r%50)/50)>0)for(;i--;)s.push(-10===n?["L",0,n*o]:["M",0,n*o],["L",5*o,n*o+2],["L",0,n*o+4]),r-=50,n+=7;if((i=(r-r%10)/10)>0)for(;i--;)s.push(-10===n?["L",0,n*o]:["M",0,n*o],["L",7*o,n*o]),r-=10,n+=3;if((i=(r-r%5)/5)>0)for(;i--;)s.push(-10===n?["L",0,n*o]:["M",0,n*o],["L",4*o,n*o]),r-=5,n+=3;return s}drawPoints(){let t=this.chart,e=this.yAxis,o=t.inverted,r=this.options.vectorLength/2;for(let i of this.points){let n=i.plotX,s=i.plotY;!1===this.options.clip||t.isInsidePlot(n,0)?(i.graphic||(i.graphic=this.chart.renderer.path().add(this.markerGroup).addClass("highcharts-point highcharts-color-"+function(){let t=arguments,e=t.length;for(let o=0;o<e;o++){let e=t[o];if(null!=e)return e}}(i.colorIndex,i.series.colorIndex))),i.graphic.attr({d:this.windArrow(i),translateX:n+this.options.xOffset,translateY:s+this.options.yOffset,rotation:i.direction}),this.chart.styledMode||i.graphic.attr(this.pointAttribs(i))):i.graphic&&(i.graphic=i.graphic.destroy()),i.tooltipPos=[n+this.options.xOffset+(o&&!this.onSeries?r:0),s+this.options.yOffset-(o?0:r+e.pos-t.plotTop)]}}animate(t){t?this.markerGroup.attr({opacity:.01}):this.markerGroup.animate({opacity:1},X(this.options.animation))}markerAttribs(){return{}}getExtremes(){return{}}shouldShowTooltip(t,e,o={}){return o.ignoreX=this.chart.inverted,o.ignoreY=!o.ignoreX,super.shouldShowTooltip(t,e,o)}}P.defaultOptions=function(t,...e){let o,r=[t,...e],i={},n=function(t,e){return"object"!=typeof t&&(t={}),function(t,e,o){for(let o in t)Object.hasOwnProperty.call(t,o)&&e.call((0,t[o]),t[o],o,t)}(e,function(o,r){if("__proto__"!==r&&"constructor"!==r){let i;!g(o,!0)||(i=o?.constructor,g(o,!0)&&!d(o)&&i?.name&&"Object"!==i.name)||d(o)?t[r]=e[r]:t[r]=n(t[r]||{},o)}}),t};!0===t&&(i=r[1],r=Array.prototype.slice.call(r,2));let s=r.length;for(o=0;o<s;o++)i=n(i,r[o]);return i}(k.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}),O.compose(P),function(t,e){let o;for(o in t||(t={}),e)t[o]=e[o]}(P.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:A,trackerGroups:["markerGroup"],translate:function(){let t=this.beaufortFloor,e=this.beaufortName;for(let o of(O.translate.call(this),this.points)){let r=0;for(;r<t.length&&!(t[r]>o.value);r++);o.beaufortLevel=r-1,o.beaufort=e[r-1]}}}),S().registerSeriesType("windbarb",P),l().windbarb||(l().windbarb=(t,e)=>{let o=0,r=0;for(let i=0,s=t.length;i<s;i++)o+=t[i]*Math.cos(e[i]*n().deg2rad),r+=t[i]*Math.sin(e[i]*n().deg2rad);return[t.reduce((t,e)=>t+e,0)/t.length,Math.atan2(r,o)/n().deg2rad]});let M=n();export{M as default};