@@ -22,6 +22,7 @@ import {
22
22
Output ,
23
23
ViewChild ,
24
24
} from '@angular/core' ;
25
+ import { CardFobComponent } from './card_fob_component' ;
25
26
import {
26
27
AxisDirection ,
27
28
CardFobGetStepFromPositionHelper ,
@@ -61,7 +62,7 @@ export class CardFobControllerComponent {
61
62
@Input ( ) lowestStep ! : number ;
62
63
@Input ( ) showExtendedLine ?: Boolean = false ;
63
64
@Input ( ) isProspectiveFobFeatureEnabled ?: Boolean = false ;
64
- @Input ( ) prospectiveStep ? : number | null = null ;
65
+ @Input ( ) prospectiveStep : number | null = null ;
65
66
@Input ( ) prospectiveStepAxisPosition ?: number | null = null ;
66
67
67
68
@Output ( ) onTimeSelectionChanged =
@@ -200,21 +201,30 @@ export class CardFobControllerComponent {
200
201
return newTimeSelection ;
201
202
}
202
203
203
- mouseMove ( event : MouseEvent ) {
204
- if ( this . currentDraggingFob === Fob . NONE ) return ;
205
-
204
+ getNewStepFromMouseEvent ( event : MouseEvent ) : number | null {
206
205
let newStep : number | null = null ;
207
206
const mousePosition = this . getMousePositionFromEvent ( event ) ;
208
207
const movement =
209
208
this . axisDirection === AxisDirection . VERTICAL
210
209
? event . movementY
211
210
: event . movementX ;
212
- if ( this . isDraggingHigher ( mousePosition , movement ) ) {
211
+ if ( this . isMovingHigher ( mousePosition , movement ) ) {
213
212
newStep = this . cardFobHelper . getStepHigherThanAxisPosition ( mousePosition ) ;
214
- } else if ( this . isDraggingLower ( mousePosition , movement ) ) {
213
+ } else if ( this . isMovingLower ( mousePosition , movement ) ) {
215
214
newStep = this . cardFobHelper . getStepLowerThanAxisPosition ( mousePosition ) ;
216
215
}
217
216
217
+ if ( newStep === null ) {
218
+ return null ;
219
+ }
220
+
221
+ return newStep ;
222
+ }
223
+
224
+ mouseMove ( event : MouseEvent ) {
225
+ if ( this . currentDraggingFob === Fob . NONE ) return ;
226
+
227
+ const newStep = this . getNewStepFromMouseEvent ( event ) ;
218
228
if ( newStep === null || ! this . timeSelection ) {
219
229
return ;
220
230
}
@@ -229,19 +239,53 @@ export class CardFobControllerComponent {
229
239
this . hasFobMoved = true ;
230
240
}
231
241
232
- isDraggingLower ( position : number , movement : number ) : boolean {
242
+ mouseOver ( event : MouseEvent ) {
243
+ if (
244
+ this . timeSelection ?. end !== null &&
245
+ this . timeSelection ?. end !== undefined
246
+ ) {
247
+ return ;
248
+ }
249
+
250
+ const newStep = this . getNewStepFromMouseEvent ( event ) ;
251
+ if ( newStep === null ) {
252
+ return ;
253
+ }
254
+
255
+ this . onPrespectiveStepChanged . emit ( newStep ) ;
256
+ }
257
+
258
+ isMovingLower ( position : number , movement : number ) : boolean {
259
+ if ( this . currentDraggingFob === Fob . NONE && this . prospectiveStep === null ) {
260
+ return true ;
261
+ }
262
+
263
+ const currentStep = this . getCurrentFobStep ( ) ;
264
+ if ( currentStep === undefined ) {
265
+ return false ;
266
+ }
267
+
233
268
return (
234
269
position < this . getDraggingFobCenter ( ) &&
235
270
movement < 0 &&
236
- this . getDraggingFobStep ( ) > this . lowestStep
271
+ currentStep > this . lowestStep
237
272
) ;
238
273
}
239
274
240
- isDraggingHigher ( position : number , movement : number ) : boolean {
275
+ isMovingHigher ( position : number , movement : number ) : boolean {
276
+ if ( this . currentDraggingFob === Fob . NONE && this . prospectiveStep === null ) {
277
+ return true ;
278
+ }
279
+
280
+ const currentStep = this . getCurrentFobStep ( ) ;
281
+ if ( currentStep === undefined ) {
282
+ return false ;
283
+ }
284
+
241
285
return (
242
286
position > this . getDraggingFobCenter ( ) &&
243
287
movement > 0 &&
244
- this . getDraggingFobStep ( ) < this . highestStep
288
+ currentStep < this . highestStep
245
289
) ;
246
290
}
247
291
@@ -252,27 +296,43 @@ export class CardFobControllerComponent {
252
296
// the element's natural position(using translateY(-50%)). While in the
253
297
// horizontal direction the fob's center is actually rendered over the left
254
298
// of the element's natural position (using translateX(-50%)).
299
+ const currentFob = this . getCurrentFob ( ) ?. nativeElement ;
300
+ if ( ! currentFob ) {
301
+ return 0 ;
302
+ }
303
+ let fobTopPosition = currentFob . getBoundingClientRect ( ) . top ;
304
+ let fobLeftPosition = currentFob . getBoundingClientRect ( ) . left ;
305
+
255
306
if ( this . axisDirection === AxisDirection . VERTICAL ) {
256
307
return (
257
- ( this . currentDraggingFob !== Fob . END
258
- ? this . startFobWrapper . nativeElement . getBoundingClientRect ( ) . top
259
- : this . endFobWrapper . nativeElement . getBoundingClientRect ( ) . top ) -
260
- this . root . nativeElement . getBoundingClientRect ( ) . top
261
- ) ;
262
- } else {
263
- return (
264
- ( this . currentDraggingFob !== Fob . END
265
- ? this . startFobWrapper . nativeElement . getBoundingClientRect ( ) . left
266
- : this . endFobWrapper . nativeElement . getBoundingClientRect ( ) . left ) -
267
- this . root . nativeElement . getBoundingClientRect ( ) . left
308
+ fobTopPosition - this . root . nativeElement . getBoundingClientRect ( ) . top
268
309
) ;
269
310
}
311
+ return (
312
+ fobLeftPosition - this . root . nativeElement . getBoundingClientRect ( ) . left
313
+ ) ;
314
+ }
315
+
316
+ getCurrentFob ( ) : ElementRef < CardFobComponent & HTMLElement > | null {
317
+ switch ( this . currentDraggingFob ) {
318
+ case Fob . START :
319
+ return this . startFobWrapper ;
320
+ case Fob . END :
321
+ return this . endFobWrapper ;
322
+ case Fob . NONE :
323
+ return this . prospectiveFobWrapper ;
324
+ }
270
325
}
271
326
272
- getDraggingFobStep ( ) : number {
273
- return this . currentDraggingFob !== Fob . END
274
- ? this . timeSelection ! . start . step
275
- : this . timeSelection ! . end ! . step ;
327
+ getCurrentFobStep ( ) : number | undefined {
328
+ switch ( this . currentDraggingFob ) {
329
+ case Fob . START :
330
+ return this . timeSelection ?. start . step ;
331
+ case Fob . END :
332
+ return this . timeSelection ?. end ?. step ;
333
+ case Fob . NONE :
334
+ return this . prospectiveStep ?? undefined ;
335
+ }
276
336
}
277
337
278
338
getMousePositionFromEvent ( event : MouseEvent ) : number {
0 commit comments