highcharts
Version:
JavaScript charting framework
12 lines • 4.93 kB
JavaScript
/**
* Highstock JS v12.3.0 (2025-06-21)
* @module highcharts/indicators/dmi
* @requires highcharts
* @requires highcharts/modules/stock
*
* Indicator series type for Highcharts Stock
*
* (c) 2010-2025 Rafal Sebestjanski
*
* License: www.highcharts.com/license
*/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 s in e)a.o(e,s)&&!a.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let s=t.default;var i=a.n(s);a.d({},{});let l=t.default.SeriesRegistry;var o=a.n(l);let{sma:{prototype:r}}=o().seriesTypes,{defined:n,error:p,merge:h}=i();!function(t){let e=["bottomLine"],a=["top","bottom"],s=["top"];function i(t){return"plot"+t.charAt(0).toUpperCase()+t.slice(1)}function l(t,e){let a=[];return(t.pointArrayMap||[]).forEach(t=>{t!==e&&a.push(i(t))}),a}function o(){let t=this,e=t.pointValKey,a=t.linesApiNames,s=t.areaLinesNames,o=t.points,u=t.options,c=t.graph,m={options:{gapSize:u.gapSize}},y=[],f=l(t,e),d=o.length,D;if(f.forEach((t,e)=>{for(y[e]=[];d--;)D=o[d],y[e].push({x:D.x,plotX:D.plotX,plotY:D[t],isNull:!n(D[t])});d=o.length}),t.userOptions.fillColor&&s.length){let e=y[f.indexOf(i(s[0]))],a=1===s.length?o:y[f.indexOf(i(s[1]))],l=t.color;t.points=a,t.nextPoints=e,t.color=t.userOptions.fillColor,t.options=h(o,m),t.graph=t.area,t.fillGraph=!0,r.drawGraph.call(t),t.area=t.graph,delete t.nextPoints,delete t.fillGraph,t.color=l}a.forEach((e,a)=>{y[a]?(t.points=y[a],u[e]?t.options=h(u[e].styles,m):p('Error: "There is no '+e+' in DOCS options declared. Check if linesApiNames are consistent with your DOCS line names."'),t.graph=t["graph"+e],r.drawGraph.call(t),t["graph"+e]=t.graph):p('Error: "'+e+" doesn't have equivalent in pointArrayMap. To many elements in linesApiNames relative to pointArrayMap.\"")}),t.points=o,t.options=u,t.graph=c,r.drawGraph.call(t)}function u(t){let e,a=[],s=[];if(t=t||this.points,this.fillGraph&&this.nextPoints){if((e=r.getGraphPath.call(this,this.nextPoints))&&e.length){e[0][0]="L",a=r.getGraphPath.call(this,t),s=e.slice(0,a.length);for(let t=s.length-1;t>=0;t--)a.push(s[t])}}else a=r.getGraphPath.apply(this,arguments);return a}function c(t){let e=[];return(this.pointArrayMap||[]).forEach(a=>{e.push(t[a])}),e}function m(){let t=this.pointArrayMap,e=[],a;e=l(this),r.translate.apply(this,arguments),this.points.forEach(s=>{t.forEach((t,i)=>{a=s[t],this.dataModify&&(a=this.dataModify.modifyValue(a)),null!==a&&(s[e[i]]=this.yAxis.toPixels(a,!0))})})}t.compose=function(t){let i=t.prototype;return i.linesApiNames=i.linesApiNames||e.slice(),i.pointArrayMap=i.pointArrayMap||a.slice(),i.pointValKey=i.pointValKey||"top",i.areaLinesNames=i.areaLinesNames||s.slice(),i.drawGraph=o,i.getGraphPath=u,i.toYData=c,i.translate=m,t}}(e||(e={}));let u=e,{sma:c}=o().seriesTypes,{correctFloat:m,extend:y,isArray:f,merge:d}=i();class D extends c{calculateDM(t,e,a){let s,i=t[e][1],l=t[e][2],o=t[e-1][1],r=t[e-1][2];return m(i-o>r-l?a?Math.max(i-o,0):0:a?0:Math.max(r-l,0))}calculateDI(t,e){return t/e*100}calculateDX(t,e){return m(Math.abs(t-e)/Math.abs(t+e)*100)}smoothValues(t,e,a){return m(t-t/a+e)}getTR(t,e){return m(Math.max(t[1]-t[2],e?Math.abs(t[1]-e[3]):0,e?Math.abs(t[2]-e[3]):0))}getValues(t,e){let a=e.period,s=t.xData,i=t.yData,l=i?i.length:0,o=[],r=[],n=[];if(s.length<=a||!f(i[0])||4!==i[0].length)return;let p=0,h=0,u=0,c;for(c=1;c<l;c++){let t,e,l,m,y,f,d,D,g;c<=a?(m=this.calculateDM(i,c,!0),y=this.calculateDM(i,c),f=this.getTR(i[c],i[c-1]),p+=m,h+=y,u+=f,c===a&&(d=this.calculateDI(p,u),D=this.calculateDI(h,u),g=this.calculateDX(p,h),o.push([s[c],g,d,D]),r.push(s[c]),n.push([g,d,D]))):(m=this.calculateDM(i,c,!0),y=this.calculateDM(i,c),f=this.getTR(i[c],i[c-1]),t=this.smoothValues(p,m,a),e=this.smoothValues(h,y,a),l=this.smoothValues(u,f,a),p=t,h=e,u=l,d=this.calculateDI(p,u),D=this.calculateDI(h,u),g=this.calculateDX(p,h),o.push([s[c],g,d,D]),r.push(s[c]),n.push([g,d,D]))}return{values:o,xData:r,yData:n}}}D.defaultOptions=d(c.defaultOptions,{params:{index:void 0},marker:{enabled:!1},tooltip:{pointFormat:'<span style="color: {point.color}">●</span><b> {series.name}</b><br/><span style="color: {point.color}">DX</span>: {point.y}<br/><span style="color: {point.series.options.plusDILine.styles.lineColor}">+DI</span>: {point.plusDI}<br/><span style="color: {point.series.options.minusDILine.styles.lineColor}">-DI</span>: {point.minusDI}<br/>'},plusDILine:{styles:{lineWidth:1,lineColor:"#06b535"}},minusDILine:{styles:{lineWidth:1,lineColor:"#f21313"}},dataGrouping:{approximation:"averages"}}),y(D.prototype,{areaLinesNames:[],nameBase:"DMI",linesApiNames:["plusDILine","minusDILine"],pointArrayMap:["y","plusDI","minusDI"],parallelArrays:["x","y","plusDI","minusDI"],pointValKey:"y"}),u.compose(D),o().registerSeriesType("dmi",D);let g=i();export{g as default};