highcharts
Version:
JavaScript charting framework
14 lines • 4.66 kB
JavaScript
/**
* Highstock JS v13.0.1 (2026-08-17)
* @module highcharts/indicators/stochastic
* @requires highcharts
* @requires highcharts/modules/stock
*
* Indicator series type for Highcharts Stock
*
* (c) 2010-2026 Highsoft AS
* Author: Paweł Fus
*
* A commercial license may be required depending on use,
* see www.highcharts.com/license
*/import*as e from"../highcharts.js";let t={};t.n=e=>{let a=e&&e.__esModule?()=>e.default:()=>e;return t.d(a,{a:a}),a},t.d=(e,a)=>{if(Array.isArray(a))for(var r=0;r<a.length;){var i=a[r++],o=a[r++];t.o(e,i)?0===o&&r++:0===o?Object.defineProperty(e,i,{enumerable:!0,value:a[r++]}):Object.defineProperty(e,i,{enumerable:!0,get:o})}else for(var i in a)t.o(a,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:a[i]})},t.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let a=e.default;var r,i=t.n(a);let o=function(e,t,a){return e.reduce((e,r)=>[Math.min(e[0],r[t]),Math.max(e[1],r[a])],[Number.MAX_VALUE,-Number.MAX_VALUE])},s=e.default.SeriesRegistry;var n=t.n(s);let{sma:{prototype:l}}=n().seriesTypes;!function(e){let t=["bottomLine"],r=["top","bottom"],i=["top"];function o(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(o(e))}),a}function n(){let e=this,t=e.pointValKey,r=e.linesApiNames,i=e.areaLinesNames,n=e.points,p=e.options,h=e.graph,u={options:{gapSize:p.gapSize}},c=[],d=s(e,t),y=n.length,f;if(d.forEach((e,t)=>{for(c[t]=[];y--;)f=n[y],c[t].push({x:f.x,plotX:f.plotX,plotY:f[e],isNull:!(0,a.defined)(f[e])});y=n.length}),e.userOptions.fillColor&&i.length){let t=c[d.indexOf(o(i[0]))],r=1===i.length?n:c[d.indexOf(o(i[1]))],s=e.color;e.points=r,e.nextPoints=t,e.color=e.userOptions.fillColor,e.options=(0,a.merge)(n,u),e.graph=e.area,e.fillGraph=!0,l.drawGraph.call(e),e.area=e.graph,delete e.nextPoints,delete e.fillGraph,e.color=s}r.forEach((t,r)=>{c[r]?(e.points=c[r],p[t]?e.options=(0,a.merge)(p[t].styles,u):(0,a.error)('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):(0,a.error)('Error: "'+t+" doesn't have equivalent in pointArrayMap. To many elements in linesApiNames relative to pointArrayMap.\"")}),e.points=n,e.options=p,e.graph=h,l.drawGraph.call(e)}function p(e){let t,a=[],r=[];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),r=t.slice(0,a.length);for(let e=r.length-1;e>=0;e--)a.push(r[e])}}else a=l.getGraphPath.apply(this,arguments);return a}function h(e){let t=[];return(this.pointArrayMap||[]).forEach(a=>{t.push(e[a])}),t}function u(){let e=this.pointArrayMap,t=[],a;t=s(this),l.translate.apply(this,arguments),this.points.forEach(r=>{e.forEach((e,i)=>{a=r[e],this.dataModify&&(a=this.dataModify.modifyValue(a)),null!==a&&(r[t[i]]=this.yAxis.toPixels(a,!0))})})}e.compose=function(e){let a=e.prototype;return a.linesApiNames=a.linesApiNames||t.slice(),a.pointArrayMap=a.pointArrayMap||r.slice(),a.pointValKey=a.pointValKey||"top",a.areaLinesNames=a.areaLinesNames||i.slice(),a.drawGraph=n,a.getGraphPath=p,a.toYData=h,a.translate=u,e}}(r||(r={}));let p=r,{sma:h}=n().seriesTypes;class u extends h{init(){super.init.apply(this,arguments),this.options=(0,a.merge)({smoothedLine:{styles:{lineColor:this.color}}},this.options)}getValues(e,t){let r=t.periods[0],i=t.periods[1],s=e.xData,n=e.yData,l=n?n.length:0,p=[],h=[],u=[],c,d,y=null,f,m;if(l<r||!(0,a.isArray)(n[0])||4!==n[0].length)return;let g=!0,A=0;for(m=r-1;m<l;m++){if(c=(f=o(n.slice(m-r+1,m+1),2,1))[0],isNaN(d=(n[m][3]-c)/(f[1]-c)*100)&&g){A++;continue}g&&!isNaN(d)&&(g=!1);let e=h.push(s[m]);isNaN(d)?u.push([u[e-2]&&"number"==typeof u[e-2][0]?u[e-2][0]:null,null]):u.push([d,null]),m>=A+(r-1)+(i-1)&&(y=super.getValues({xData:h.slice(-i),yData:u.slice(-i)},{period:i}).yData[0]),p.push([s[m],d,y]),u[e-1][1]=y}return{values:p,xData:h,yData:u}}}u.defaultOptions=(0,a.merge)(h.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"}}),(0,a.extend)(u.prototype,{areaLinesNames:[],nameComponents:["periods"],nameBase:"Stochastic",pointArrayMap:["y","smoothed"],parallelArrays:["x","y","smoothed"],pointValKey:"y",linesApiNames:["smoothedLine"]}),p.compose(u),n().registerSeriesType("stochastic",u);let c=i();export{c as default};