UNPKG

highcharts

Version:
14 lines 8.14 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 */function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(e._Highcharts,e._Highcharts.SeriesRegistry):"function"==typeof define&&define.amd?define("highcharts/indicators/volume-by-price",["highcharts/highcharts"],function(e){return t(e,e.SeriesRegistry)}):"object"==typeof exports?exports["highcharts/indicators/volume-by-price"]=t(e._Highcharts,e._Highcharts.SeriesRegistry):e.Highcharts=t(e.Highcharts,e.Highcharts.SeriesRegistry)}("u"<typeof window?this:window,(e,t)=>(()=>{"use strict";var i={512(e){e.exports=t},944(t){t.exports=e}};let o={};function s(e){let t=o[e];if(void 0!==t)return t.exports;let a=o[e]={exports:{}};return i[e](a,a.exports,s),a.exports}s.n=e=>{let t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{if(Array.isArray(t))for(var i=0;i<t.length;){var o=t[i++],a=t[i++];s.o(e,o)?0===a&&i++:0===a?Object.defineProperty(e,o,{enumerable:!0,value:t[i++]}):Object.defineProperty(e,o,{enumerable:!0,get:a})}else for(var o in t)s.o(t,o)&&!s.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let a={};s.d(a,{default:()=>v});var r=s(944),n=s.n(r),l=s(512),p=s.n(l);let{sma:{prototype:{pointClass:h}}}=p().seriesTypes,d=class extends h{destroy(){this.negativeGraphic&&(this.negativeGraphic=this.negativeGraphic.destroy()),super.destroy.apply(this,arguments)}},{noop:u}=n(),{column:{prototype:c},sma:m}=p().seriesTypes,g=Math.abs;class f extends m{init(e,t){let i=this;delete t.data,super.init.apply(i,arguments);let o=(0,r.addEvent)(this.chart.constructor,"afterLinkSeries",function(){if(i.options){let t=i.options.params,o=i.linkedParent,s=t?.volumeSeriesID?e.get(t?.volumeSeriesID):void 0;o&&s&&i.addCustomEvents(o,s)}o()},{order:1});return i}addCustomEvents(e,t){let i=this,o=()=>{i.chart.redraw(),i.setData([]),i.zoneStarts=[],i.zoneLinesSVG&&(i.zoneLinesSVG=i.zoneLinesSVG.destroy())};return i.dataEventsToUnbind.push((0,r.addEvent)(e,"remove",function(){o()})),t&&i.dataEventsToUnbind.push((0,r.addEvent)(t,"remove",function(){o()})),i}animate(e){let t=this,i=t.chart.inverted,o=t.group,s={};if(!e&&o){let e=i?t.yAxis.top:t.xAxis.left;i?(o["forceAnimate:translateY"]=!0,s.translateY=e):(o["forceAnimate:translateX"]=!0,s.translateX=e),o.animate(s,(0,r.extend)((0,r.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),c.drawPoints.apply(this,arguments),this.posNegVolume(!1,!1)),c.drawPoints.apply(this,arguments)}posNegVolume(e,t){let i=t?["positive","negative"]:["negative","positive"],o=this.options.volumeDivision,s=this.points.length,a=[],r=[],n=0,l,p,h,d;for(e?(this.posWidths=a,this.negWidths=r):(a=this.posWidths,r=this.negWidths);n<s;n++)(d=this.points[n])[i[0]+"Graphic"]=d.graphic,d.graphic=d[i[1]+"Graphic"],e&&(l=d.shapeArgs.width,(h=(p=this.priceZones[n]).wholeVolumeData)?(a.push(l/h*p.positiveVolumeData),r.push(l/h*p.negativeVolumeData)):(a.push(0),r.push(0))),d.color=t?o.styles.positiveColor:o.styles.negativeColor,d.shapeArgs.width=t?this.posWidths[n]:this.negWidths[n],d.shapeArgs.x=t?d.shapeArgs.x:this.posWidths[n]}translate(){let e=this,t=e.options,i=e.chart,o=e.yAxis,s=o.min,a=e.options.zoneLines,n=e.priceZones,l=0,p,h,d,u,m,f,v,y,x,D,S;c.translate.apply(e);let b=e.points;b.length&&(y=t.pointPadding<.5?t.pointPadding:.1,p=e.volumeDataArray,h=(0,r.arrayMax)(p),d=i.plotWidth/2,x=i.plotTop,u=g(o.toPixels(s)-o.toPixels(s+e.rangeStep)),f=g(o.toPixels(s)-o.toPixels(s+e.rangeStep)),y&&(m=g(u*(1-2*y)),l=g((u-m)/2),u=g(m)),b.forEach(function(t,i){D=t.barX=t.plotX=0,S=t.plotY=o.toPixels(n[i].start)-x-(o.reversed?u-f:u)-l,t.pointWidth=v=(0,r.correctFloat)(d*n[i].wholeVolumeData/h),t.shapeArgs=e.crispCol.apply(e,[D,S,v,u]),t.volumeNeg=n[i].negativeVolumeData,t.volumePos=n[i].positiveVolumeData,t.volumeAll=n[i].wholeVolumeData,delete t.origin,t.isInside=e.isPointInside(t)}),a.enabled&&e.drawZones(i,o,e.zoneStarts,a.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 i=e.getColumn("x",!0),o=e.processedYData,s=this.chart,a=t.ranges,n=[],l=[],p=[],h=s.get(t.volumeSeriesID);if(!e.chart)return void(0,r.error)("Base series not found! In case it has been removed, add a new one.",!0,s);if(!h||!h.getColumn("x",!0).length){let e=h&&!h.getColumn("x",!0).length?" does not contain any data.":" not found! Check `volumeSeriesID`.";(0,r.error)("Series "+t.volumeSeriesID+e,!0,s);return}let d=(0,r.isArray)(o[0]);return d&&4!==o[0].length?void(0,r.error)("Type of "+e.name+" series is different than line, OHLC or candlestick.",!0,s):((this.priceZones=this.specifyZones(d,i,o,a,h)).forEach(function(e,t){n.push([e.x,e.end]),l.push(n[t][0]),p.push(n[t][1])}),{values:n,xData:l,yData:p})}specifyZones(e,t,i,o,s){let a=!!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}}(i),n=this.zoneStarts=[],l=[],p=a?a.min:(0,r.arrayMin)(i),h=a?a.max:(0,r.arrayMax)(i),d=0,u=1,c=this.linkedParent;if(!this.options.compareToMain&&c.dataModify&&(p=c.dataModify.modifyValue(p),h=c.dataModify.modifyValue(h)),!(0,r.defined)(p)||!(0,r.defined)(h))return this.points.length&&(this.setData([]),this.zoneStarts=[],this.zoneLinesSVG&&(this.zoneLinesSVG=this.zoneLinesSVG.destroy())),[];let m=this.rangeStep=(0,r.correctFloat)(h-p)/o;for(n.push(p);d<o-1;d++)n.push((0,r.correctFloat)(n[d]+m));n.push(h);let g=n.length;for(;u<g;u++)l.push({index:u-1,x:t[0],start:n[u-1],end:n[u]});return this.volumePerZone(e,l,s,t,i)}volumePerZone(e,t,i,o,s){let a,r,n,l,p,h=this,d=i.getColumn("x",!0),u=i.getColumn("y",!0),c=t.length-1,m=s.length,f=u.length;return g(m-f)&&(o[0]!==d[0]&&u.unshift(0),o[m-1]!==d[f-1]&&u.push(0)),h.volumeDataArray=[],t.forEach(function(t){for(p=0,t.wholeVolumeData=0,t.positiveVolumeData=0,t.negativeVolumeData=0;p<m;p++){r=!1,n=!1,l=e?s[p][3]:s[p],a=p?e?s[p-1][3]:s[p-1]:l;let i=h.linkedParent;!h.options.compareToMain&&i.dataModify&&(l=i.dataModify.modifyValue(l),a=i.dataModify.modifyValue(a)),l<=t.start&&0===t.index&&(r=!0),l>=t.end&&t.index===c&&(n=!0),(l>t.start||r)&&(l<t.end||n)&&(t.wholeVolumeData+=u[p],a>l?t.negativeVolumeData+=u[p]:t.positiveVolumeData+=u[p])}h.volumeDataArray.push(t.wholeVolumeData)}),t}drawZones(e,t,i,o){let s=e.renderer,a=e.plotWidth,r=e.plotTop,n=this.zoneLinesSVG,l=[],p;i.forEach(function(i){p=t.toPixels(i)-r,l=l.concat(e.renderer.crispLine([["M",0,p],["L",a,p]],o.lineWidth))}),n?n.animate({d:l}):n=this.zoneLinesSVG=s.path(l).attr({"stroke-width":o.lineWidth,stroke:o.color,dashstyle:o.dashStyle,zIndex:this.group.zIndex+.1}).add(this.group)}}f.defaultOptions=(0,r.merge)(m.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,r.extend)(f.prototype,{nameBase:"Volume by Price",nameComponents:["ranges"],calculateOn:{chart:"render",xAxis:"afterSetExtremes"},pointClass:d,markerAttribs:u,drawGraph:u,getColumnMetrics:c.getColumnMetrics,crispCol:c.crispCol}),p().registerSeriesType("vbp",f);let v=n();return a.default})());