UNPKG

highcharts

Version:
1 lines 7.13 kB
import*as t from"../highcharts.js";import"../modules/stock.js";var e,a={};a.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return a.d(e,{a:e}),e},a.d=(t,e)=>{for(var i in e)a.o(e,i)&&!a.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let i=t.default;var s=a.n(i);let n=t.default.Chart;var r=a.n(n);let o=t.default.SeriesRegistry;var l=a.n(o);let{line:p}=l().seriesTypes,{addEvent:h,fireEvent:u,error:d,extend:c,isArray:f,merge:m,pick:y}=s(),x=(t,e)=>{let a=[],i=t.pointArrayMap,s=e&&t.dataTable.modified||t.dataTable;if(!i)return t.getColumn("y",e);let n=i.map(a=>t.getColumn(a,e));for(let t=0;t<s.rowCount;t++){let e=i.map((e,a)=>n[a]?.[t]||0);a.push(e)}return a};class g extends p{destroy(){this.dataEventsToUnbind.forEach(function(t){t()}),super.destroy.apply(this,arguments)}getName(){let t=[],e=this.name;return e||((this.nameComponents||[]).forEach(function(e,a){t.push(this.options.params[e]+y(this.nameSuffixes[a],""))},this),e=(this.nameBase||this.type.toUpperCase())+(this.nameComponents?" ("+t.join(", ")+")":"")),e}getValues(t,e){let a=e.period,i=t.xData||[],s=t.yData,n=s.length,r=[],o=[],l=[],p,h=-1,u=0,d,c=0;if(!(i.length<a)){for(f(s[0])&&(h=e.index?e.index:0);u<a-1;)c+=h<0?s[u]:s[u][h],u++;for(p=u;p<n;p++)c+=h<0?s[p]:s[p][h],d=[i[p],c/a],r.push(d),o.push(d[0]),l.push(d[1]),c-=h<0?s[p-u]:s[p-u][h];return{values:r,xData:o,yData:l}}}init(t,e){let a=this;super.init.call(a,t,e);let i=h(r(),"afterLinkSeries",function({isUpdating:e}){if(e)return;let i=!!a.dataEventsToUnbind.length;if(!a.linkedParent)return d("Series "+a.options.linkedTo+" not found! Check `linkedTo`.",!1,t);if(!i&&(a.dataEventsToUnbind.push(h(a.linkedParent,"updatedData",function(){a.recalculateValues()})),a.calculateOn.xAxis&&a.dataEventsToUnbind.push(h(a.linkedParent.xAxis,a.calculateOn.xAxis,function(){a.recalculateValues()}))),"init"===a.calculateOn.chart)a.closestPointRange||a.recalculateValues();else if(!i){let t=h(a.chart,a.calculateOn.chart,function(){a.recalculateValues(),t()})}},{order:0});a.dataEventsToUnbind=[],a.eventsToUnbind.push(i)}recalculateValues(){let t=[],e=this.dataTable,a=this.points||[],i=this.dataTable.rowCount,s=!0,n,r,o,l,p=this.linkedParent.yData,h=this.linkedParent.processedYData;this.linkedParent.xData=this.linkedParent.getColumn("x"),this.linkedParent.yData=x(this.linkedParent),this.linkedParent.processedYData=x(this.linkedParent,!0);let d=this.linkedParent.options&&this.linkedParent.dataTable.rowCount&&this.getValues(this.linkedParent,this.options.params)||{values:[],xData:[],yData:[]};delete this.linkedParent.xData,this.linkedParent.yData=p,this.linkedParent.processedYData=h;let c=this.pointArrayMap||["y"],m={};if(d.yData.forEach(t=>{c.forEach((e,a)=>{let i=m[e]||[];i.push(f(t)?t[a]:t),m[e]||(m[e]=i)})}),i&&!this.hasGroupedData&&this.visible&&this.points){if(this.cropped){this.xAxis&&(o=this.xAxis.min,l=this.xAxis.max);let i=this.cropData(e,o,l),s=["x",...this.pointArrayMap||["y"]];for(let e=0;e<(i.modified?.rowCount||0);e++){let a=s.map(t=>this.getColumn(t)[e]||0);t.push(a)}let p=this.getColumn("x");n=d.xData.indexOf(p[0]),r=d.xData.indexOf(p[p.length-1]),-1===n&&r===d.xData.length-2&&t[0][0]===a[0].x&&t.shift(),this.updateData(t)}else(this.updateAllPoints||d.xData.length!==i-1&&d.xData.length!==i+1)&&(s=!1,this.updateData(d.values))}s&&(e.setColumns({...m,x:d.xData}),this.options.data=d.values),this.calculateOn.xAxis&&this.getColumn("x",!0).length&&(this.isDirty=!0,this.redraw()),this.isDirtyData=!!this.linkedSeries.length,u(this,"updatedData")}processData(){let t=this.options.compareToMain,e=this.linkedParent;super.processData.apply(this,arguments),this.dataModify&&e&&e.dataModify&&e.dataModify.compareValue&&t&&(this.dataModify.compareValue=e.dataModify.compareValue)}}g.defaultOptions=m(p.defaultOptions,{name:void 0,tooltip:{valueDecimals:4},linkedTo:void 0,compareToMain:!1,params:{index:3,period:14}}),c(g.prototype,{calculateOn:{chart:"init"},hasDerivedData:!0,nameComponents:["period"],nameSuffixes:[],useCommonDataGrouping:!0}),l().registerSeriesType("sma",g);let{sma:D}=l().seriesTypes,{correctFloat:P,isArray:k,merge:v}=s();class A extends D{accumulatePeriodPoints(t,e,a){let i=0,s=0,n=0;for(;s<t;)i+=e<0?a[s]:a[s][e],s++;return i}calculateEma(t,e,a,i,s,n,r){let o=t[a-1],l=n<0?e[a-1]:e[a-1][n];return[o,void 0===s?r:P(l*i+s*(1-i))]}getValues(t,e){let a=e.period,i=t.xData,s=t.yData,n=s?s.length:0,r=2/(a+1),o=[],l=[],p=[],h,u,d,c=-1,f=0,m=0;if(!(n<a)){for(k(s[0])&&(c=e.index?e.index:0),m=this.accumulatePeriodPoints(a,c,s)/a,d=a;d<n+1;d++)u=this.calculateEma(i,s,d,r,h,c,m),o.push(u),l.push(u[0]),p.push(u[1]),h=u[1];return{values:o,xData:l,yData:p}}}}A.defaultOptions=v(D.defaultOptions,{params:{index:3,period:9}}),l().registerSeriesType("ema",A);let{sma:{prototype:C}}=l().seriesTypes,{defined:T,error:M,merge:O}=s();!function(t){let e=["bottomLine"],a=["top","bottom"],i=["top"];function s(t){return"plot"+t.charAt(0).toUpperCase()+t.slice(1)}function n(t,e){let a=[];return(t.pointArrayMap||[]).forEach(t=>{t!==e&&a.push(s(t))}),a}function r(){let t=this,e=t.pointValKey,a=t.linesApiNames,i=t.areaLinesNames,r=t.points,o=t.options,l=t.graph,p={options:{gapSize:o.gapSize}},h=[],u=n(t,e),d=r.length,c;if(u.forEach((t,e)=>{for(h[e]=[];d--;)c=r[d],h[e].push({x:c.x,plotX:c.plotX,plotY:c[t],isNull:!T(c[t])});d=r.length}),t.userOptions.fillColor&&i.length){let e=h[u.indexOf(s(i[0]))],a=1===i.length?r:h[u.indexOf(s(i[1]))],n=t.color;t.points=a,t.nextPoints=e,t.color=t.userOptions.fillColor,t.options=O(r,p),t.graph=t.area,t.fillGraph=!0,C.drawGraph.call(t),t.area=t.graph,delete t.nextPoints,delete t.fillGraph,t.color=n}a.forEach((e,a)=>{h[a]?(t.points=h[a],o[e]?t.options=O(o[e].styles,p):M('Error: "There is no '+e+' in DOCS options declared. Check if linesApiNames are consistent with your DOCS line names."'),t.graph=t["graph"+e],C.drawGraph.call(t),t["graph"+e]=t.graph):M('Error: "'+e+" doesn't have equivalent in pointArrayMap. To many elements in linesApiNames relative to pointArrayMap.\"")}),t.points=r,t.options=o,t.graph=l,C.drawGraph.call(t)}function o(t){let e,a=[],i=[];if(t=t||this.points,this.fillGraph&&this.nextPoints){if((e=C.getGraphPath.call(this,this.nextPoints))&&e.length){e[0][0]="L",a=C.getGraphPath.call(this,t),i=e.slice(0,a.length);for(let t=i.length-1;t>=0;t--)a.push(i[t])}}else a=C.getGraphPath.apply(this,arguments);return a}function l(t){let e=[];return(this.pointArrayMap||[]).forEach(a=>{e.push(t[a])}),e}function p(){let t=this.pointArrayMap,e=[],a;e=n(this),C.translate.apply(this,arguments),this.points.forEach(i=>{t.forEach((t,s)=>{a=i[t],this.dataModify&&(a=this.dataModify.modifyValue(a)),null!==a&&(i[e[s]]=this.yAxis.toPixels(a,!0))})})}t.compose=function(t){let s=t.prototype;return s.linesApiNames=s.linesApiNames||e.slice(),s.pointArrayMap=s.pointArrayMap||a.slice(),s.pointValKey=s.pointValKey||"top",s.areaLinesNames=s.areaLinesNames||i.slice(),s.drawGraph=r,s.getGraphPath=o,s.toYData=l,s.translate=p,t}}(e||(e={}));let E=e;a.d({},{});let b=s();b.MultipleLinesComposition=b.MultipleLinesComposition||E;let V=s();export{V as default};