@@ -104,9 +104,9 @@ export function mouseDown(chart, event) {
104104 addHandler ( chart , window . document , 'keydown' , keyDown ) ;
105105}
106106
107- function applyAspectRatio ( endPoint , beginPoint , aspectRatio ) {
108- let width = endPoint . x - beginPoint . x ;
109- let height = endPoint . y - beginPoint . y ;
107+ function applyAspectRatio ( { begin , end } , aspectRatio ) {
108+ let width = end . x - begin . x ;
109+ let height = end . y - begin . y ;
110110 const ratio = Math . abs ( width / height ) ;
111111
112112 if ( ratio > aspectRatio ) {
@@ -115,41 +115,43 @@ function applyAspectRatio(endPoint, beginPoint, aspectRatio) {
115115 height = Math . sign ( height ) * Math . abs ( width / aspectRatio ) ;
116116 }
117117
118- endPoint . x = beginPoint . x + width ;
119- endPoint . y = beginPoint . y + height ;
118+ end . x = begin . x + width ;
119+ end . y = begin . y + height ;
120120}
121121
122- function applyMinMaxProps ( rect , chartArea , beginPoint , endPoint , { min, max, prop} ) {
123- rect [ min ] = clamp ( Math . min ( beginPoint [ prop ] , endPoint [ prop ] ) , chartArea [ min ] , chartArea [ max ] ) ;
124- rect [ max ] = clamp ( Math . max ( beginPoint [ prop ] , endPoint [ prop ] ) , chartArea [ min ] , chartArea [ max ] ) ;
122+ function applyMinMaxProps ( rect , chartArea , points , { min, max, prop} ) {
123+ rect [ min ] = clamp ( Math . min ( points . begin [ prop ] , points . end [ prop ] ) , chartArea [ min ] , chartArea [ max ] ) ;
124+ rect [ max ] = clamp ( Math . max ( points . begin [ prop ] , points . end [ prop ] ) , chartArea [ min ] , chartArea [ max ] ) ;
125125}
126126
127- function getRelativePoints ( chart , points , maintainAspectRatio ) {
128- const beginPoint = getPointPosition ( points . dragStart , chart ) ;
129- const endPoint = getPointPosition ( points . dragEnd , chart ) ;
127+ function getRelativePoints ( chart , pointEvents , maintainAspectRatio ) {
128+ const points = {
129+ begin : getPointPosition ( pointEvents . dragStart , chart ) ,
130+ end : getPointPosition ( pointEvents . dragEnd , chart ) ,
131+ } ;
130132
131133 if ( maintainAspectRatio ) {
132134 const aspectRatio = chart . chartArea . width / chart . chartArea . height ;
133- applyAspectRatio ( endPoint , beginPoint , aspectRatio ) ;
135+ applyAspectRatio ( points , aspectRatio ) ;
134136 }
135137
136- return { beginPoint , endPoint } ;
138+ return points ;
137139}
138140
139- export function computeDragRect ( chart , mode , points , maintainAspectRatio ) {
141+ export function computeDragRect ( chart , mode , pointEvents , maintainAspectRatio ) {
140142 const xEnabled = directionEnabled ( mode , 'x' , chart ) ;
141143 const yEnabled = directionEnabled ( mode , 'y' , chart ) ;
142144 const { top, left, right, bottom, width : chartWidth , height : chartHeight } = chart . chartArea ;
143145 const rect = { top, left, right, bottom} ;
144146
145- const { beginPoint , endPoint } = getRelativePoints ( chart , points , maintainAspectRatio && xEnabled && yEnabled ) ;
147+ const points = getRelativePoints ( chart , pointEvents , maintainAspectRatio && xEnabled && yEnabled ) ;
146148
147149 if ( xEnabled ) {
148- applyMinMaxProps ( rect , chart . chartArea , beginPoint , endPoint , { min : 'left' , max : 'right' , prop : 'x' } ) ;
150+ applyMinMaxProps ( rect , chart . chartArea , points , { min : 'left' , max : 'right' , prop : 'x' } ) ;
149151 }
150152
151153 if ( yEnabled ) {
152- applyMinMaxProps ( rect , chart . chartArea , beginPoint , endPoint , { min : 'top' , max : 'bottom' , prop : 'y' } ) ;
154+ applyMinMaxProps ( rect , chart . chartArea , points , { min : 'top' , max : 'bottom' , prop : 'y' } ) ;
153155 }
154156
155157 const width = rect . right - rect . left ;
0 commit comments