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) {
5858}
5959
6060function 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+ } ;
6667 }
67- return point ;
68+ return getRelativePosition ( event , chart ) ;
6869}
6970
7071function zoomStart ( chart , event , zoomOptions ) {
Original file line number Diff line number Diff line change @@ -450,6 +450,63 @@ describe('zoom with drag', function() {
450450 expect ( scaleY . options . min ) . toBeCloseTo ( 1.2 ) ;
451451 expect ( scaleY . options . max ) . toBeCloseTo ( 1.7 ) ;
452452 } ) ;
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+ } ) ;
453510 } ) ;
454511
455512 describe ( 'events' , function ( ) {
You can’t perform that action at this time.
0 commit comments