highcharts
Version:
JavaScript charting framework
1 lines • 3.61 kB
JavaScript
import*as o from"../highcharts.js";import"../modules/stock.js";var e={};e.n=o=>{var l=o&&o.__esModule?()=>o.default:()=>o;return e.d(l,{a:l}),l},e.d=(o,l)=>{for(var t in l)e.o(l,t)&&!e.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:l[t]})},e.o=(o,e)=>Object.prototype.hasOwnProperty.call(o,e);let l=o.default;var t=e.n(l);e.d({},{});let r=o.default.SeriesRegistry;var s=e.n(r);let{atr:n,sma:i}=s().seriesTypes,{addEvent:p,correctFloat:a,isArray:d,isNumber:c,extend:h,merge:u,objectEach:g}=t();function x(o,e){return{index:e,close:o.getColumn("close")[e],x:o.getColumn("x")[e]}}class y extends i{init(){let o=this;super.init.apply(o,arguments);let e=p(this.chart.constructor,"afterLinkSeries",()=>{if(o.options){let e=o.options;e.cropThreshold=o.linkedParent.options.cropThreshold-(e.params.period-1)}e()},{order:1})}drawGraph(){let o=this,e=o.options,l=o.linkedParent,t=l.getColumn("x"),r=l?l.points:[],s=o.points,n=o.graph,p=r.length-s.length,a=p>0?p:0,d={options:{gapSize:e.gapSize}},h={top:[],bottom:[],intersect:[]},y={top:{styles:{lineWidth:e.lineWidth,lineColor:e.fallingTrendColor||e.color,dashStyle:e.dashStyle}},bottom:{styles:{lineWidth:e.lineWidth,lineColor:e.risingTrendColor||e.color,dashStyle:e.dashStyle}},intersect:e.changeTrendLine},m,f,C,T,S,b,v,D,L,N=s.length;for(;N--;)m=s[N],f=s[N-1],C=r[N-1+a],T=r[N-2+a],S=r[N+a],b=r[N+a+1],v=m.options.color,D={x:m.x,plotX:m.plotX,plotY:m.plotY,isNull:!1},!T&&C&&c(t[C.index-1])&&(T=x(l,C.index-1)),!b&&S&&c(t[S.index+1])&&(b=x(l,S.index+1)),!C&&T&&c(t[T.index+1])?C=x(l,T.index+1):!C&&S&&c(t[S.index-1])&&(C=x(l,S.index-1)),m&&C&&S&&T&&m.x!==C.x&&(m.x===S.x?(T=C,C=S):m.x===T.x?(C=T,T={close:l.getColumn("close")[C.index-1],x:t[C.index-1]}):b&&m.x===b.x&&(C=b,T=S)),f&&T&&C?(L={x:f.x,plotX:f.plotX,plotY:f.plotY,isNull:!1},m.y>=C.close&&f.y>=T.close?(m.color=v||e.fallingTrendColor||e.color,h.top.push(D)):m.y<C.close&&f.y<T.close?(m.color=v||e.risingTrendColor||e.color,h.bottom.push(D)):(h.intersect.push(D),h.intersect.push(L),h.intersect.push(u(L,{isNull:!0})),m.y>=C.close&&f.y<T.close?(m.color=v||e.fallingTrendColor||e.color,f.color=v||e.risingTrendColor||e.color,h.top.push(D),h.top.push(u(L,{isNull:!0}))):m.y<C.close&&f.y>=T.close&&(m.color=v||e.risingTrendColor||e.color,f.color=v||e.fallingTrendColor||e.color,h.bottom.push(D),h.bottom.push(u(L,{isNull:!0}))))):C&&(m.y>=C.close?(m.color=v||e.fallingTrendColor||e.color,h.top.push(D)):(m.color=v||e.risingTrendColor||e.color,h.bottom.push(D)));g(h,function(e,l){o.points=e,o.options=u(y[l].styles,d),o.graph=o["graph"+l+"Line"],i.prototype.drawGraph.call(o),o["graph"+l+"Line"]=o.graph}),o.points=s,o.options=e,o.graph=n}getValues(o,e){let l=e.period,t=e.multiplier,r=o.xData,s=o.yData,i=[],p=[],c=[],h=0===l?0:l-1,u=[],g=[],x=[],y,m,f,C,T,S,b,v,D;if(!(r.length<=l)&&d(s[0])&&4===s[0].length&&!(l<0)){for(D=0,x=n.prototype.getValues.call(this,o,{period:l}).yData;D<x.length;D++)v=s[h+D],b=s[h+D-1]||[],C=u[D-1],T=g[D-1],S=c[D-1],0===D&&(C=T=S=0),y=a((v[1]+v[2])/2+t*x[D]),m=a((v[1]+v[2])/2-t*x[D]),y<C||b[3]>C?u[D]=y:u[D]=C,m>T||b[3]<T?g[D]=m:g[D]=T,S===C&&v[3]<u[D]||S===T&&v[3]<g[D]?f=u[D]:(S===C&&v[3]>u[D]||S===T&&v[3]>g[D])&&(f=g[D]),i.push([r[h+D],f]),p.push(r[h+D]),c.push(f);return{values:i,xData:p,yData:c}}}}y.defaultOptions=u(i.defaultOptions,{params:{index:void 0,multiplier:3,period:10},risingTrendColor:"#06b535",fallingTrendColor:"#f21313",changeTrendLine:{styles:{lineWidth:1,lineColor:"#333333",dashStyle:"LongDash"}}}),h(y.prototype,{nameBase:"Supertrend",nameComponents:["multiplier","period"]}),s().registerSeriesType("supertrend",y);let m=t();export{m as default};