@@ -346,6 +346,7 @@ describe('zoom', function() {
346
346
plugins : {
347
347
zoom : {
348
348
pan : {
349
+ enabled : true ,
349
350
modifierKey : key ,
350
351
} ,
351
352
zoom : {
@@ -396,6 +397,75 @@ describe('zoom', function() {
396
397
}
397
398
} ) ;
398
399
400
+ describe ( 'drag with modifierKey' , function ( ) {
401
+ for ( const key of [ 'ctrl' , 'alt' , 'shift' , 'meta' ] ) {
402
+ for ( const pressed of [ true , false ] ) {
403
+ let chart , scaleX , scaleY ;
404
+ it ( `should ${ pressed ? '' : 'not ' } change ${ pressed ? 'with' : 'without' } key ${ key } ` , async function ( ) {
405
+ const rejectedSpy = jasmine . createSpy ( 'wheelFailed' ) ;
406
+ chart = window . acquireChart ( {
407
+ type : 'line' ,
408
+ data,
409
+ options : {
410
+ scales : {
411
+ x : {
412
+ type : 'linear' ,
413
+ min : 0 ,
414
+ max : 10
415
+ } ,
416
+ y : {
417
+ type : 'linear'
418
+ }
419
+ } ,
420
+ plugins : {
421
+ zoom : {
422
+ zoom : {
423
+ drag : {
424
+ enabled : true ,
425
+ modifierKey : key ,
426
+ } ,
427
+ mode : 'x' ,
428
+ onZoomRejected : rejectedSpy
429
+ }
430
+ }
431
+ }
432
+ }
433
+ } ) ;
434
+
435
+ scaleX = chart . scales . x ;
436
+ scaleY = chart . scales . y ;
437
+
438
+ const oldMinX = scaleX . options . min ;
439
+ const oldMaxX = scaleX . options . max ;
440
+
441
+ const pt = {
442
+ x : scaleX . getPixelForValue ( 1.5 ) ,
443
+ y : scaleY . getPixelForValue ( 1.1 ) ,
444
+ } ;
445
+ const pt2 = { x : pt . x + 20 , y : pt . y + 20 } ;
446
+ const init = { } ;
447
+ if ( pressed ) {
448
+ init [ key + 'Key' ] = true ;
449
+ }
450
+
451
+ jasmine . dispatchEvent ( chart , 'mousedown' , pt , init ) ;
452
+ jasmine . dispatchEvent ( chart , 'mousemove' , pt2 , init ) ;
453
+ jasmine . dispatchEvent ( chart , 'mouseup' , pt2 , init ) ;
454
+
455
+ if ( pressed ) {
456
+ expect ( scaleX . options . min ) . not . toEqual ( oldMinX ) ;
457
+ expect ( scaleX . options . max ) . not . toEqual ( oldMaxX ) ;
458
+ expect ( rejectedSpy ) . not . toHaveBeenCalled ( ) ;
459
+ } else {
460
+ expect ( scaleX . options . min ) . toEqual ( oldMinX ) ;
461
+ expect ( scaleX . options . max ) . toEqual ( oldMaxX ) ;
462
+ expect ( rejectedSpy ) . toHaveBeenCalled ( ) ;
463
+ }
464
+ } ) ;
465
+ }
466
+ }
467
+ } ) ;
468
+
399
469
describe ( 'with overScaleMode = y and mode = xy' , function ( ) {
400
470
const config = {
401
471
type : 'line' ,
0 commit comments