@@ -104,9 +104,9 @@ export function mouseDown(chart, event) {
104
104
addHandler ( chart , window . document , 'keydown' , keyDown ) ;
105
105
}
106
106
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 ;
110
110
const ratio = Math . abs ( width / height ) ;
111
111
112
112
if ( ratio > aspectRatio ) {
@@ -115,41 +115,43 @@ function applyAspectRatio(endPoint, beginPoint, aspectRatio) {
115
115
height = Math . sign ( height ) * Math . abs ( width / aspectRatio ) ;
116
116
}
117
117
118
- endPoint . x = beginPoint . x + width ;
119
- endPoint . y = beginPoint . y + height ;
118
+ end . x = begin . x + width ;
119
+ end . y = begin . y + height ;
120
120
}
121
121
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 ] ) ;
125
125
}
126
126
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
+ } ;
130
132
131
133
if ( maintainAspectRatio ) {
132
134
const aspectRatio = chart . chartArea . width / chart . chartArea . height ;
133
- applyAspectRatio ( endPoint , beginPoint , aspectRatio ) ;
135
+ applyAspectRatio ( points , aspectRatio ) ;
134
136
}
135
137
136
- return { beginPoint , endPoint } ;
138
+ return points ;
137
139
}
138
140
139
- export function computeDragRect ( chart , mode , points , maintainAspectRatio ) {
141
+ export function computeDragRect ( chart , mode , pointEvents , maintainAspectRatio ) {
140
142
const xEnabled = directionEnabled ( mode , 'x' , chart ) ;
141
143
const yEnabled = directionEnabled ( mode , 'y' , chart ) ;
142
144
const { top, left, right, bottom, width : chartWidth , height : chartHeight } = chart . chartArea ;
143
145
const rect = { top, left, right, bottom} ;
144
146
145
- const { beginPoint , endPoint } = getRelativePoints ( chart , points , maintainAspectRatio && xEnabled && yEnabled ) ;
147
+ const points = getRelativePoints ( chart , pointEvents , maintainAspectRatio && xEnabled && yEnabled ) ;
146
148
147
149
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' } ) ;
149
151
}
150
152
151
153
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' } ) ;
153
155
}
154
156
155
157
const width = rect . right - rect . left ;
0 commit comments