UNPKG

highcharts

Version:
14 lines 7.49 kB
/** * Highstock JS v13.0.1 (2026-08-17) * @module highcharts/indicators/volume-by-price * @requires highcharts * @requires highcharts/modules/stock * * Indicator series type for Highcharts Stock * * (c) 2010-2026 Highsoft AS * Author: Paweł Dalek * * 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 i=e&&e.__esModule?()=>e.default:()=>e;return t.d(i,{a:i}),i},t.d=(e,i)=>{if(Array.isArray(i))for(var o=0;o<i.length;){var s=i[o++],a=i[o++];t.o(e,s)?0===a&&o++:0===a?Object.defineProperty(e,s,{enumerable:!0,value:i[o++]}):Object.defineProperty(e,s,{enumerable:!0,get:a})}else for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},t.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let i=e.default;var o=t.n(i);let s=e.default.SeriesRegistry;var a=t.n(s);let{sma:{prototype:{pointClass:n}}}=a().seriesTypes,r=class extends n{destroy(){this.negativeGraphic&&(this.negativeGraphic=this.negativeGraphic.destroy()),super.destroy.apply(this,arguments)}},{noop:l}=o(),{column:{prototype:p},sma:d}=a().seriesTypes,h=Math.abs;class u extends d{init(e,t){let o=this;delete t.data,super.init.apply(o,arguments);let s=(0,i.addEvent)(this.chart.constructor,"afterLinkSeries",function(){if(o.options){let t=o.options.params,i=o.linkedParent,s=t?.volumeSeriesID?e.get(t?.volumeSeriesID):void 0;i&&s&&o.addCustomEvents(i,s)}s()},{order:1});return o}addCustomEvents(e,t){let o=this,s=()=>{o.chart.redraw(),o.setData([]),o.zoneStarts=[],o.zoneLinesSVG&&(o.zoneLinesSVG=o.zoneLinesSVG.destroy())};return o.dataEventsToUnbind.push((0,i.addEvent)(e,"remove",function(){s()})),t&&o.dataEventsToUnbind.push((0,i.addEvent)(t,"remove",function(){s()})),o}animate(e){let t=this,o=t.chart.inverted,s=t.group,a={};if(!e&&s){let e=o?t.yAxis.top:t.xAxis.left;o?(s["forceAnimate:translateY"]=!0,a.translateY=e):(s["forceAnimate:translateX"]=!0,a.translateX=e),s.animate(a,(0,i.extend)((0,i.animObject)(t.options.animation),{step:function(e,i){t.group.attr({scaleX:Math.max(.001,i.pos)})}}))}}drawPoints(){this.options.volumeDivision.enabled&&(this.posNegVolume(!0,!0),p.drawPoints.apply(this,arguments),this.posNegVolume(!1,!1)),p.drawPoints.apply(this,arguments)}posNegVolume(e,t){let i=t?["positive","negative"]:["negative","positive"],o=this.options.volumeDivision,s=this.points.length,a=[],n=[],r=0,l,p,d,h;for(e?(this.posWidths=a,this.negWidths=n):(a=this.posWidths,n=this.negWidths);r<s;r++)(h=this.points[r])[i[0]+"Graphic"]=h.graphic,h.graphic=h[i[1]+"Graphic"],e&&(l=h.shapeArgs.width,(d=(p=this.priceZones[r]).wholeVolumeData)?(a.push(l/d*p.positiveVolumeData),n.push(l/d*p.negativeVolumeData)):(a.push(0),n.push(0))),h.color=t?o.styles.positiveColor:o.styles.negativeColor,h.shapeArgs.width=t?this.posWidths[r]:this.negWidths[r],h.shapeArgs.x=t?h.shapeArgs.x:this.posWidths[r]}translate(){let e=this,t=e.options,o=e.chart,s=e.yAxis,a=s.min,n=e.options.zoneLines,r=e.priceZones,l=0,d,u,m,c,g,v,f,y,x,D,V;p.translate.apply(e);let S=e.points;S.length&&(y=t.pointPadding<.5?t.pointPadding:.1,d=e.volumeDataArray,u=(0,i.arrayMax)(d),m=o.plotWidth/2,x=o.plotTop,c=h(s.toPixels(a)-s.toPixels(a+e.rangeStep)),v=h(s.toPixels(a)-s.toPixels(a+e.rangeStep)),y&&(g=h(c*(1-2*y)),l=h((c-g)/2),c=h(g)),S.forEach(function(t,o){D=t.barX=t.plotX=0,V=t.plotY=s.toPixels(r[o].start)-x-(s.reversed?c-v:c)-l,t.pointWidth=f=(0,i.correctFloat)(m*r[o].wholeVolumeData/u),t.shapeArgs=e.crispCol.apply(e,[D,V,f,c]),t.volumeNeg=r[o].negativeVolumeData,t.volumePos=r[o].positiveVolumeData,t.volumeAll=r[o].wholeVolumeData,delete t.origin,t.isInside=e.isPointInside(t)}),n.enabled&&e.drawZones(o,s,e.zoneStarts,n.styles))}getExtremes(){let e,t=this.options.compare,i=this.options.cumulative;return this.options.compare?(this.options.compare=void 0,e=super.getExtremes(),this.options.compare=t):this.options.cumulative?(this.options.cumulative=!1,e=super.getExtremes(),this.options.cumulative=i):e=super.getExtremes(),e}getValues(e,t){let o=e.getColumn("x",!0),s=e.processedYData,a=this.chart,n=t.ranges,r=[],l=[],p=[],d=a.get(t.volumeSeriesID);if(!e.chart)return void(0,i.error)("Base series not found! In case it has been removed, add a new one.",!0,a);if(!d||!d.getColumn("x",!0).length){let e=d&&!d.getColumn("x",!0).length?" does not contain any data.":" not found! Check `volumeSeriesID`.";(0,i.error)("Series "+t.volumeSeriesID+e,!0,a);return}let h=(0,i.isArray)(s[0]);return h&&4!==s[0].length?void(0,i.error)("Type of "+e.name+" series is different than line, OHLC or candlestick.",!0,a):((this.priceZones=this.specifyZones(h,o,s,n,d)).forEach(function(e,t){r.push([e.x,e.end]),l.push(r[t][0]),p.push(r[t][1])}),{values:r,xData:l,yData:p})}specifyZones(e,t,o,s,a){let n=!!e&&function(e){let t=e.length,i=e[0][3],o=i,s=1,a;for(;s<t;s++)(a=e[s][3])<i&&(i=a),a>o&&(o=a);return{min:i,max:o}}(o),r=this.zoneStarts=[],l=[],p=n?n.min:(0,i.arrayMin)(o),d=n?n.max:(0,i.arrayMax)(o),h=0,u=1,m=this.linkedParent;if(!this.options.compareToMain&&m.dataModify&&(p=m.dataModify.modifyValue(p),d=m.dataModify.modifyValue(d)),!(0,i.defined)(p)||!(0,i.defined)(d))return this.points.length&&(this.setData([]),this.zoneStarts=[],this.zoneLinesSVG&&(this.zoneLinesSVG=this.zoneLinesSVG.destroy())),[];let c=this.rangeStep=(0,i.correctFloat)(d-p)/s;for(r.push(p);h<s-1;h++)r.push((0,i.correctFloat)(r[h]+c));r.push(d);let g=r.length;for(;u<g;u++)l.push({index:u-1,x:t[0],start:r[u-1],end:r[u]});return this.volumePerZone(e,l,a,t,o)}volumePerZone(e,t,i,o,s){let a,n,r,l,p,d=this,u=i.getColumn("x",!0),m=i.getColumn("y",!0),c=t.length-1,g=s.length,v=m.length;return h(g-v)&&(o[0]!==u[0]&&m.unshift(0),o[g-1]!==u[v-1]&&m.push(0)),d.volumeDataArray=[],t.forEach(function(t){for(p=0,t.wholeVolumeData=0,t.positiveVolumeData=0,t.negativeVolumeData=0;p<g;p++){n=!1,r=!1,l=e?s[p][3]:s[p],a=p?e?s[p-1][3]:s[p-1]:l;let i=d.linkedParent;!d.options.compareToMain&&i.dataModify&&(l=i.dataModify.modifyValue(l),a=i.dataModify.modifyValue(a)),l<=t.start&&0===t.index&&(n=!0),l>=t.end&&t.index===c&&(r=!0),(l>t.start||n)&&(l<t.end||r)&&(t.wholeVolumeData+=m[p],a>l?t.negativeVolumeData+=m[p]:t.positiveVolumeData+=m[p])}d.volumeDataArray.push(t.wholeVolumeData)}),t}drawZones(e,t,i,o){let s=e.renderer,a=e.plotWidth,n=e.plotTop,r=this.zoneLinesSVG,l=[],p;i.forEach(function(i){p=t.toPixels(i)-n,l=l.concat(e.renderer.crispLine([["M",0,p],["L",a,p]],o.lineWidth))}),r?r.animate({d:l}):r=this.zoneLinesSVG=s.path(l).attr({"stroke-width":o.lineWidth,stroke:o.color,dashstyle:o.dashStyle,zIndex:this.group.zIndex+.1}).add(this.group)}}u.defaultOptions=(0,i.merge)(d.defaultOptions,{params:{index:void 0,period:void 0,ranges:12,volumeSeriesID:"volume"},zoneLines:{enabled:!0,styles:{color:"#0A9AC9",dashStyle:"LongDash",lineWidth:1}},volumeDivision:{enabled:!0,styles:{positiveColor:"rgba(144, 237, 125, 0.8)",negativeColor:"rgba(244, 91, 91, 0.8)"}},animationLimit:1e3,enableMouseTracking:!1,pointPadding:0,zIndex:-1,crisp:!0,dataGrouping:{enabled:!1},dataLabels:{align:"left",allowOverlap:!0,distance:0,enabled:!0,format:"P: {point.volumePos:.2f} | N: {point.volumeNeg:.2f}",padding:0,style:{fontSize:"0.5em"},verticalAlign:"top"}}),(0,i.extend)(u.prototype,{nameBase:"Volume by Price",nameComponents:["ranges"],calculateOn:{chart:"render",xAxis:"afterSetExtremes"},pointClass:r,markerAttribs:l,drawGraph:l,getColumnMetrics:p.getColumnMetrics,crispCol:p.crispCol}),a().registerSeriesType("vbp",u);let m=o();export{m as default};