highcharts
Version:
JavaScript charting framework
13 lines • 4.1 kB
JavaScript
/**
* Highstock JS v12.3.0 (2025-06-21)
* @module highcharts/modules/drag-panes
* @requires highcharts
* @requires highcharts/modules/stock
*
* Drag-panes module
*
* (c) 2010-2025 Highsoft AS
* Author: Kacper Madej
*
* License: www.highcharts.com/license
*/import*as e from"../highcharts.js";import"./stock.js";var t={};t.n=e=>{var s=e&&e.__esModule?()=>e.default:()=>e;return t.d(s,{a:s}),s},t.d=(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},t.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let s=e.default;var i=t.n(s);let{addEvent:o,clamp:r,isNumber:n,relativeLength:h}=i();class a{constructor(e){this.init(e)}init(e,t){this.axis=e,this.options=e.options.resize||{},this.render(),t||this.addMouseEvents()}render(){let e=this.axis,t=e.chart,s=this.options,i=s.x||0,o=s.y,n=r(e.top+e.height+o,t.plotTop,t.plotTop+t.plotHeight),h={};t.styledMode||(h={cursor:s.cursor,stroke:s.lineColor,"stroke-width":s.lineWidth,dashstyle:s.lineDashStyle}),this.lastPos=n-o,this.controlLine||(this.controlLine=t.renderer.path().addClass("highcharts-axis-resizer")),this.controlLine.add(e.axisGroup);let a=t.styledMode?this.controlLine.strokeWidth():s.lineWidth;h.d=t.renderer.crispLine([["M",e.left+i,n],["L",e.left+e.width+i,n]],a),this.controlLine.attr(h)}addMouseEvents(){let e,t,s,i=this,r=i.controlLine.element,n=i.axis.chart.container,h=[];i.mouseMoveHandler=e=e=>i.onMouseMove(e),i.mouseUpHandler=t=e=>i.onMouseUp(e),i.mouseDownHandler=s=()=>i.onMouseDown(),h.push(o(n,"mousemove",e),o(n.ownerDocument,"mouseup",t),o(r,"mousedown",s),o(n,"touchmove",e),o(n.ownerDocument,"touchend",t),o(r,"touchstart",s)),i.eventsToUnbind=h}onMouseMove(e){if(!e.touches||0!==e.touches[0].pageX){let t=this.axis.chart.pointer;this.grabbed&&t&&(this.hasDragged=!0,this.updateAxes(t.normalize(e).chartY-(this.options.y||0)))}}onMouseUp(e){let t=this.axis.chart.pointer;this.hasDragged&&t&&this.updateAxes(t.normalize(e).chartY-(this.options.y||0)),this.grabbed=this.hasDragged=this.axis.chart.activeResizer=void 0}onMouseDown(){this.axis.chart.pointer?.reset(!1,0),this.grabbed=this.axis.chart.activeResizer=!0}updateAxes(e){let t=this.axis.chart,s=this.options.controlledAxis,i=0===s.next.length?[t.yAxis.indexOf(this.axis)+1]:s.next,o=[this.axis].concat(s.prev),a=[],l=t.plotTop,c=t.plotHeight,d=l+c,p=e=>100*e/c+"%",u=(e,t,s)=>Math.round(r(e,t,s));e=r(e,l,d);let x=!1,f=e-this.lastPos;if(f*f<1)return;let g=!0;for(let s of[o,i])for(let o of s){let r,y,m=n(o)?t.yAxis[o]:g?o:t.get(o),v=m&&m.options,z={};if(!v||v.isInternal){g=!1;continue}y=m.top;let M=Math.round(h(v.minLength||NaN,c)),b=Math.round(h(v.maxLength||NaN,c));if(g||s!==i)(r=u(e-y,M,b))===b&&(x=!0),e=y+r,a.push({axis:m,options:{height:p(r)}});else{if(f=e-this.lastPos,r=u(m.len-f,M,b),(y=m.top+f)+r>d){let t=d-r-y;e+=t,y+=t}y<l&&(y=l)+r>d&&(r=c),r===M&&(x=!0),a.push({axis:m,options:{top:p(y-l),height:p(r)}})}g=!1,z.height=r}if(!x){for(let e of a)e.axis.update(e.options,!1);t.redraw(!1)}}destroy(){let e=this.axis;for(let t of(delete e.resizer,this.eventsToUnbind&&this.eventsToUnbind.forEach(e=>e()),this.controlLine.destroy(),Object.keys(this)))this[t]=null}}a.resizerOptions={minLength:"10%",maxLength:"100%",resize:{controlledAxis:{next:[],prev:[]},enabled:!1,cursor:"ns-resize",lineColor:"#cccccc",lineDashStyle:"Solid",lineWidth:4,x:0,y:0}};let{defaultOptions:l}=i(),{addEvent:c,merge:d,wrap:p}=i();function u(){let e=this.resizer,t=this.options.resize;if(t){let s=!1!==t.enabled;e?s?e.init(this,!0):e.destroy():s&&(this.resizer=new a(this))}}function x(e){!e.keepEvents&&this.resizer&&this.resizer.destroy()}function f(e){this.chart.activeResizer||e.apply(this,[].slice.call(arguments,1))}function g(e){this.chart.activeResizer||e.apply(this,[].slice.call(arguments,1))}t.d({},{});let y=i();y.AxisResizer=a,({compose:function(e,t){e.keepProps.includes("resizer")||(d(!0,l.yAxis,a.resizerOptions),e.keepProps.push("resizer"),c(e,"afterRender",u),c(e,"destroy",x),p(t.prototype,"runPointActions",g),p(t.prototype,"drag",f))}}).compose(y.Axis,y.Pointer);let m=i();export{m as default};