File tree Expand file tree Collapse file tree 2 files changed +64
-6
lines changed Expand file tree Collapse file tree 2 files changed +64
-6
lines changed Original file line number Diff line number Diff line change @@ -58,13 +58,14 @@ function keyDown(chart, event) {
58
58
}
59
59
60
60
function getPointPosition ( event , chart ) {
61
- const point = getRelativePosition ( event , chart ) ;
62
- const canvasArea = chart . canvas . getBoundingClientRect ( ) ;
63
- if ( ! _isPointInArea ( event , canvasArea ) ) {
64
- point . x = event . clientX - canvasArea . left ;
65
- point . y = event . clientY - canvasArea . top ;
61
+ if ( event . target !== chart . canvas ) {
62
+ const canvasArea = chart . canvas . getBoundingClientRect ( ) ;
63
+ return {
64
+ x : event . clientX - canvasArea . left ,
65
+ y : event . clientY - canvasArea . top ,
66
+ } ;
66
67
}
67
- return point ;
68
+ return getRelativePosition ( event , chart ) ;
68
69
}
69
70
70
71
function zoomStart ( chart , event , zoomOptions ) {
Original file line number Diff line number Diff line change @@ -450,6 +450,63 @@ describe('zoom with drag', function() {
450
450
expect ( scaleY . options . min ) . toBeCloseTo ( 1.2 ) ;
451
451
expect ( scaleY . options . max ) . toBeCloseTo ( 1.7 ) ;
452
452
} ) ;
453
+
454
+ it ( 'handles dragging off the right edge of the chart canvas' , function ( ) {
455
+ chart = window . acquireChart ( {
456
+ type : 'line' ,
457
+ data,
458
+ options : {
459
+ scales : {
460
+ xScale0 : {
461
+ id : 'xScale0' ,
462
+ type : 'linear' ,
463
+ min : 0 ,
464
+ max : 4
465
+ } ,
466
+ yScale0 : {
467
+ id : 'yScale0' ,
468
+ type : 'linear' ,
469
+ min : 0 ,
470
+ max : 4 ,
471
+ }
472
+ } ,
473
+ plugins : {
474
+ zoom : {
475
+ zoom : {
476
+ drag : {
477
+ enabled : true
478
+ } ,
479
+ mode : 'xy'
480
+ }
481
+ }
482
+ }
483
+ }
484
+ } , {
485
+ wrapper : { style : 'position: absolute; left: 50px; top: 50px;' }
486
+ } ) ;
487
+
488
+ scaleX = chart . scales . xScale0 ;
489
+ scaleY = chart . scales . yScale0 ;
490
+
491
+ jasmine . triggerMouseEvent ( chart , 'mousedown' , {
492
+ x : scaleX . getPixelForValue ( 1.5 ) ,
493
+ y : scaleY . getPixelForValue ( 1.2 )
494
+ } ) ;
495
+
496
+ const rect = chart . canvas . getBoundingClientRect ( ) ;
497
+ document . documentElement . dispatchEvent ( new MouseEvent ( 'mouseup' , {
498
+ clientX : rect . right ,
499
+ clientY : rect . top + scaleY . getPixelForValue ( 1.7 ) ,
500
+ cancelable : true ,
501
+ bubbles : true ,
502
+ view : window
503
+ } ) ) ;
504
+
505
+ expect ( scaleX . options . min ) . toBeCloseTo ( 1.5 ) ;
506
+ expect ( scaleX . options . max ) . toBeCloseTo ( 4 ) ;
507
+ expect ( scaleY . options . min ) . toBeCloseTo ( 1.2 ) ;
508
+ expect ( scaleY . options . max ) . toBeCloseTo ( 1.7 ) ;
509
+ } ) ;
453
510
} ) ;
454
511
455
512
describe ( 'events' , function ( ) {
You can’t perform that action at this time.
0 commit comments