UNPKG

highcharts

Version:
14 lines 9.6 kB
!/** * Highstock JS v12.6.0 (2026-04-13) * @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 o={512:e=>{e.exports=t},944:t=>{t.exports=e}},i={};function n(e){var t=i[e];if(void 0!==t)return t.exports;var s=i[e]={exports:{}};return o[e](s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var s={};n.d(s,{default:()=>E});var r=n(944),a=n.n(r),l=n(512),p=n.n(l);let{sma:{prototype:{pointClass:h}}}=p().seriesTypes,u=class extends h{destroy(){this.negativeGraphic&&(this.negativeGraphic=this.negativeGraphic.destroy()),super.destroy.apply(this,arguments)}},{doc:c,win:d}=a();function f(e,t,o,i={}){let n="function"==typeof e&&e.prototype||e;Object.hasOwnProperty.call(n,"hcEvents")||(n.hcEvents={});let s=n.hcEvents;a().Point&&e instanceof a().Point&&e.series&&e.series.chart&&(e.series.chart.runTrackerClick=!0);let r=e.addEventListener;r&&r.call(e,t,o,!!a().supportsPassiveEvents&&{passive:void 0===i.passive?-1!==t.indexOf("touch"):i.passive,capture:!1}),s[t]||(s[t]=[]);let l={fn:o,order:"number"==typeof i.order?i.order:1/0};return s[t].push(l),s[t].sort((e,t)=>e.order-t.order),function(){!function(e,t,o){function i(t,o){let i=e.removeEventListener;i&&i.call(e,t,o,!1)}function n(o){let n,s;e.nodeName&&(t?(n={})[t]=!0:n=o,S(n,function(e,t){if(o[t])for(s=o[t].length;s--;)i(t,o[t][s].fn)}))}let s="function"==typeof e&&e.prototype||e;if(Object.hasOwnProperty.call(s,"hcEvents")){let e=s.hcEvents;if(t){let s=e[t]||[];o?(e[t]=s.filter(function(e){return o!==e.fn}),i(t,o)):(n(e),e[t]=[])}else n(e),delete s.hcEvents}}(e,t,o)}}function m(e){let t=e.length,o=e[0];for(;t--;)e[t]>o&&(o=e[t]);return o}function g(e,t){return e>1e14?e:parseFloat(e.toPrecision(t||14))}function v(e,t){let o;for(o in e||(e={}),t)e[o]=t[o];return e}function y(e){return b(e)&&"number"==typeof e.nodeType}function x(e){let t=Object.prototype.toString.call(e);return"[object Array]"===t||"[object Array Iterator]"===t}function b(e,t){return!!e&&"object"==typeof e&&(!t||!x(e))}function S(e,t,o){for(let i in e)Object.hasOwnProperty.call(e,i)&&t.call(o||e[i],e[i],i,e)}Array.prototype.find;let{animObject:D}=a(),{noop:V}=a(),{column:{prototype:P},sma:w}=p().seriesTypes,A=Math.abs;class C extends w{init(e,t){let o=this;delete t.data,super.init.apply(o,arguments);let i=f(this.chart.constructor,"afterLinkSeries",function(){if(o.options){let t=o.options.params,i=o.linkedParent,n=e.get(t.volumeSeriesID);o.addCustomEvents(i,n)}i()},{order:1});return o}addCustomEvents(e,t){let o=this,i=()=>{o.chart.redraw(),o.setData([]),o.zoneStarts=[],o.zoneLinesSVG&&(o.zoneLinesSVG=o.zoneLinesSVG.destroy())};return o.dataEventsToUnbind.push(f(e,"remove",function(){i()})),t&&o.dataEventsToUnbind.push(f(t,"remove",function(){i()})),o}animate(e){let t=this,o=t.chart.inverted,i=t.group,n={};if(!e&&i){let e=o?t.yAxis.top:t.xAxis.left;o?(i["forceAnimate:translateY"]=!0,n.translateY=e):(i["forceAnimate:translateX"]=!0,n.translateX=e),i.animate(n,v(D(t.options.animation),{step:function(e,o){t.group.attr({scaleX:Math.max(.001,o.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 o=t?["positive","negative"]:["negative","positive"],i=this.options.volumeDivision,n=this.points.length,s=[],r=[],a=0,l,p,h,u;for(e?(this.posWidths=s,this.negWidths=r):(s=this.posWidths,r=this.negWidths);a<n;a++)(u=this.points[a])[o[0]+"Graphic"]=u.graphic,u.graphic=u[o[1]+"Graphic"],e&&(l=u.shapeArgs.width,(h=(p=this.priceZones[a]).wholeVolumeData)?(s.push(l/h*p.positiveVolumeData),r.push(l/h*p.negativeVolumeData)):(s.push(0),r.push(0))),u.color=t?i.styles.positiveColor:i.styles.negativeColor,u.shapeArgs.width=t?this.posWidths[a]:this.negWidths[a],u.shapeArgs.x=t?u.shapeArgs.x:this.posWidths[a]}translate(){let e=this,t=e.options,o=e.chart,i=e.yAxis,n=i.min,s=e.options.zoneLines,r=e.priceZones,a=0,l,p,h,u,c,d,f,v,y,x;P.translate.apply(e);let b=e.points;b.length&&(f=t.pointPadding<.5?t.pointPadding:.1,l=m(e.volumeDataArray),p=o.plotWidth/2,v=o.plotTop,h=A(i.toPixels(n)-i.toPixels(n+e.rangeStep)),c=A(i.toPixels(n)-i.toPixels(n+e.rangeStep)),f&&(u=A(h*(1-2*f)),a=A((h-u)/2),h=A(u)),b.forEach(function(t,o){y=t.barX=t.plotX=0,x=t.plotY=i.toPixels(r[o].start)-v-(i.reversed?h-c:h)-a,t.pointWidth=d=g(p*r[o].wholeVolumeData/l),t.shapeArgs=e.crispCol.apply(e,[y,x,d,h]),t.volumeNeg=r[o].negativeVolumeData,t.volumePos=r[o].positiveVolumeData,t.volumeAll=r[o].wholeVolumeData}),s.enabled&&e.drawZones(o,i,e.zoneStarts,s.styles))}getExtremes(){let e,t=this.options.compare,o=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=o):e=super.getExtremes(),e}getValues(e,t){let o=e.getColumn("x",!0),i=e.processedYData,n=this.chart,s=t.ranges,a=[],l=[],p=[],h=n.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,n);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,n);return}let u=x(i[0]);return u&&4!==i[0].length?void(0,r.error)("Type of "+e.name+" series is different than line, OHLC or candlestick.",!0,n):((this.priceZones=this.specifyZones(u,o,i,s,h)).forEach(function(e,t){a.push([e.x,e.end]),l.push(a[t][0]),p.push(a[t][1])}),{values:a,xData:l,yData:p})}specifyZones(e,t,o,i,n){let s=!!e&&function(e){let t=e.length,o=e[0][3],i=o,n=1,s;for(;n<t;n++)(s=e[n][3])<o&&(o=s),s>i&&(i=s);return{min:o,max:i}}(o),r=this.zoneStarts=[],a=[],l=s?s.min:function(e){let t=e.length,o=e[0];for(;t--;)e[t]<o&&(o=e[t]);return o}(o),p=s?s.max:m(o),h=0,u=1,c=this.linkedParent;if(!this.options.compareToMain&&c.dataModify&&(l=c.dataModify.modifyValue(l),p=c.dataModify.modifyValue(p)),null==l||null==p)return this.points.length&&(this.setData([]),this.zoneStarts=[],this.zoneLinesSVG&&(this.zoneLinesSVG=this.zoneLinesSVG.destroy())),[];let d=this.rangeStep=g(p-l)/i;for(r.push(l);h<i-1;h++)r.push(g(r[h]+d));r.push(p);let f=r.length;for(;u<f;u++)a.push({index:u-1,x:t[0],start:r[u-1],end:r[u]});return this.volumePerZone(e,a,n,t,o)}volumePerZone(e,t,o,i,n){let s,r,a,l,p,h=this,u=o.getColumn("x",!0),c=o.getColumn("y",!0),d=t.length-1,f=n.length,m=c.length;return A(f-m)&&(i[0]!==u[0]&&c.unshift(0),i[f-1]!==u[m-1]&&c.push(0)),h.volumeDataArray=[],t.forEach(function(t){for(p=0,t.wholeVolumeData=0,t.positiveVolumeData=0,t.negativeVolumeData=0;p<f;p++){r=!1,a=!1,l=e?n[p][3]:n[p],s=p?e?n[p-1][3]:n[p-1]:l;let o=h.linkedParent;!h.options.compareToMain&&o.dataModify&&(l=o.dataModify.modifyValue(l),s=o.dataModify.modifyValue(s)),l<=t.start&&0===t.index&&(r=!0),l>=t.end&&t.index===d&&(a=!0),(l>t.start||r)&&(l<t.end||a)&&(t.wholeVolumeData+=c[p],s>l?t.negativeVolumeData+=c[p]:t.positiveVolumeData+=c[p])}h.volumeDataArray.push(t.wholeVolumeData)}),t}drawZones(e,t,o,i){let n=e.renderer,s=e.plotWidth,r=e.plotTop,a=this.zoneLinesSVG,l=[],p;o.forEach(function(o){p=t.toPixels(o)-r,l=l.concat(e.renderer.crispLine([["M",0,p],["L",s,p]],i.lineWidth))}),a?a.animate({d:l}):a=this.zoneLinesSVG=n.path(l).attr({"stroke-width":i.lineWidth,stroke:i.color,dashstyle:i.dashStyle,zIndex:this.group.zIndex+.1}).add(this.group)}}C.defaultOptions=function(e,...t){let o,i=[e,...t],n={},s=function(e,t){return"object"!=typeof e&&(e={}),S(t,function(o,i){if("__proto__"!==i&&"constructor"!==i){let n;!b(o,!0)||(n=o?.constructor,b(o,!0)&&!y(o)&&n?.name&&"Object"!==n.name)||y(o)?e[i]=t[i]:e[i]=s(e[i]||{},o)}}),e};!0===e&&(n=i[1],i=Array.prototype.slice.call(i,2));let r=i.length;for(o=0;o<r;o++)n=s(n,i[o]);return n}(w.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,enabled:!0,format:"P: {point.volumePos:.2f} | N: {point.volumeNeg:.2f}",padding:0,style:{fontSize:"0.5em"},verticalAlign:"top"}}),v(C.prototype,{nameBase:"Volume by Price",nameComponents:["ranges"],calculateOn:{chart:"render",xAxis:"afterSetExtremes"},pointClass:u,markerAttribs:V,drawGraph:V,getColumnMetrics:P.getColumnMetrics,crispCol:P.crispCol}),p().registerSeriesType("vbp",C);let E=a();return s.default})());