highcharts
Version:
JavaScript charting framework
1 lines • 4.16 kB
JavaScript
import*as e from"../highcharts.js";import"../modules/stock.js";var t,a={};a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var o in t)a.o(t,o)&&!a.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let o=e.default;var i=a.n(o);a.d({},{});let s={getArrayExtremes:function(e,t,a){return e.reduce((e,o)=>[Math.min(e[0],o[t]),Math.max(e[1],o[a])],[Number.MAX_VALUE,-Number.MAX_VALUE])}},r=e.default.SeriesRegistry;var n=a.n(r);let{sma:{prototype:l}}=n().seriesTypes,{defined:p,error:h,merge:c}=i();!function(e){let t=["bottomLine"],a=["top","bottom"],o=["top"];function i(e){return"plot"+e.charAt(0).toUpperCase()+e.slice(1)}function s(e,t){let a=[];return(e.pointArrayMap||[]).forEach(e=>{e!==t&&a.push(i(e))}),a}function r(){let e=this,t=e.pointValKey,a=e.linesApiNames,o=e.areaLinesNames,r=e.points,n=e.options,u=e.graph,d={options:{gapSize:n.gapSize}},m=[],y=s(e,t),f=r.length,g;if(y.forEach((e,t)=>{for(m[t]=[];f--;)g=r[f],m[t].push({x:g.x,plotX:g.plotX,plotY:g[e],isNull:!p(g[e])});f=r.length}),e.userOptions.fillColor&&o.length){let t=m[y.indexOf(i(o[0]))],a=1===o.length?r:m[y.indexOf(i(o[1]))],s=e.color;e.points=a,e.nextPoints=t,e.color=e.userOptions.fillColor,e.options=c(r,d),e.graph=e.area,e.fillGraph=!0,l.drawGraph.call(e),e.area=e.graph,delete e.nextPoints,delete e.fillGraph,e.color=s}a.forEach((t,a)=>{m[a]?(e.points=m[a],n[t]?e.options=c(n[t].styles,d):h('Error: "There is no '+t+' in DOCS options declared. Check if linesApiNames are consistent with your DOCS line names."'),e.graph=e["graph"+t],l.drawGraph.call(e),e["graph"+t]=e.graph):h('Error: "'+t+" doesn't have equivalent in pointArrayMap. To many elements in linesApiNames relative to pointArrayMap.\"")}),e.points=r,e.options=n,e.graph=u,l.drawGraph.call(e)}function n(e){let t,a=[],o=[];if(e=e||this.points,this.fillGraph&&this.nextPoints){if((t=l.getGraphPath.call(this,this.nextPoints))&&t.length){t[0][0]="L",a=l.getGraphPath.call(this,e),o=t.slice(0,a.length);for(let e=o.length-1;e>=0;e--)a.push(o[e])}}else a=l.getGraphPath.apply(this,arguments);return a}function u(e){let t=[];return(this.pointArrayMap||[]).forEach(a=>{t.push(e[a])}),t}function d(){let e=this.pointArrayMap,t=[],a;t=s(this),l.translate.apply(this,arguments),this.points.forEach(o=>{e.forEach((e,i)=>{a=o[e],this.dataModify&&(a=this.dataModify.modifyValue(a)),null!==a&&(o[t[i]]=this.yAxis.toPixels(a,!0))})})}e.compose=function(e){let i=e.prototype;return i.linesApiNames=i.linesApiNames||t.slice(),i.pointArrayMap=i.pointArrayMap||a.slice(),i.pointValKey=i.pointValKey||"top",i.areaLinesNames=i.areaLinesNames||o.slice(),i.drawGraph=r,i.getGraphPath=n,i.toYData=u,i.translate=d,e}}(t||(t={}));let u=t,{sma:d}=n().seriesTypes,{extend:m,isArray:y,merge:f}=i();class g extends d{init(){super.init.apply(this,arguments),this.options=f({smoothedLine:{styles:{lineColor:this.color}}},this.options)}getValues(e,t){let a=t.periods[0],o=t.periods[1],i=e.xData,r=e.yData,n=r?r.length:0,l=[],p=[],h=[],c,u,d,m=null,f,g;if(n<a||!y(r[0])||4!==r[0].length)return;let A=!0,x=0;for(g=a-1;g<n;g++){if(c=r.slice(g-a+1,g+1),u=(f=s.getArrayExtremes(c,2,1))[0],isNaN(d=(r[g][3]-u)/(f[1]-u)*100)&&A){x++;continue}A&&!isNaN(d)&&(A=!1);let e=p.push(i[g]);isNaN(d)?h.push([h[e-2]&&"number"==typeof h[e-2][0]?h[e-2][0]:null,null]):h.push([d,null]),g>=x+(a-1)+(o-1)&&(m=super.getValues({xData:p.slice(-o),yData:h.slice(-o)},{period:o}).yData[0]),l.push([i[g],d,m]),h[e-1][1]=m}return{values:l,xData:p,yData:h}}}g.defaultOptions=f(d.defaultOptions,{params:{index:void 0,period:void 0,periods:[14,3]},marker:{enabled:!1},tooltip:{pointFormat:'<span style="color:{point.color}">●</span><b> {series.name}</b><br/>%K: {point.y}<br/>%D: {point.smoothed}<br/>'},smoothedLine:{styles:{lineWidth:1,lineColor:void 0}},dataGrouping:{approximation:"averages"}}),m(g.prototype,{areaLinesNames:[],nameComponents:["periods"],nameBase:"Stochastic",pointArrayMap:["y","smoothed"],parallelArrays:["x","y","smoothed"],pointValKey:"y",linesApiNames:["smoothedLine"]}),u.compose(g),n().registerSeriesType("stochastic",g);let A=i();export{A as default};