@@ -6,6 +6,29 @@ import {panFunctions, zoomFunctions, zoomRectFunctions} from './scale.types';
66import { getState , removeState } from './state' ;
77import { version } from '../package.json' ;
88
9+ function draw ( chart , caller , options ) {
10+ const dragOptions = options . zoom . drag ;
11+ const { dragStart, dragEnd} = getState ( chart ) ;
12+
13+ if ( dragOptions . drawTime !== caller || ! dragEnd ) {
14+ return ;
15+ }
16+ const { left, top, width, height} = computeDragRect ( chart , options . zoom . mode , dragStart , dragEnd ) ;
17+ const ctx = chart . ctx ;
18+
19+ ctx . save ( ) ;
20+ ctx . beginPath ( ) ;
21+ ctx . fillStyle = dragOptions . backgroundColor || 'rgba(225,225,225,0.3)' ;
22+ ctx . fillRect ( left , top , width , height ) ;
23+
24+ if ( dragOptions . borderWidth > 0 ) {
25+ ctx . lineWidth = dragOptions . borderWidth ;
26+ ctx . strokeStyle = dragOptions . borderColor || 'rgba(225,225,225)' ;
27+ ctx . strokeRect ( left , top , width , height ) ;
28+ }
29+ ctx . restore ( ) ;
30+ }
31+
932export default {
1033 id : 'zoom' ,
1134
@@ -26,6 +49,7 @@ export default {
2649 } ,
2750 drag : {
2851 enabled : false ,
52+ drawTime : 'beforeDatasetsDraw' ,
2953 modifierKey : null
3054 } ,
3155 pinch : {
@@ -75,27 +99,20 @@ export default {
7599 addListeners ( chart , options ) ;
76100 } ,
77101
78- beforeDatasetsDraw : function ( chart , args , options ) {
79- const { dragStart, dragEnd} = getState ( chart ) ;
80-
81- if ( dragEnd ) {
82- const { left, top, width, height} = computeDragRect ( chart , options . zoom . mode , dragStart , dragEnd ) ;
102+ beforeDatasetsDraw ( chart , _args , options ) {
103+ draw ( chart , 'beforeDatasetsDraw' , options ) ;
104+ } ,
83105
84- const dragOptions = options . zoom . drag ;
85- const ctx = chart . ctx ;
106+ afterDatasetsDraw ( chart , _args , options ) {
107+ draw ( chart , 'afterDatasetsDraw' , options ) ;
108+ } ,
86109
87- ctx . save ( ) ;
88- ctx . beginPath ( ) ;
89- ctx . fillStyle = dragOptions . backgroundColor || 'rgba(225,225,225,0.3)' ;
90- ctx . fillRect ( left , top , width , height ) ;
110+ beforeDraw ( chart , _args , options ) {
111+ draw ( chart , 'beforeDraw' , options ) ;
112+ } ,
91113
92- if ( dragOptions . borderWidth > 0 ) {
93- ctx . lineWidth = dragOptions . borderWidth ;
94- ctx . strokeStyle = dragOptions . borderColor || 'rgba(225,225,225)' ;
95- ctx . strokeRect ( left , top , width , height ) ;
96- }
97- ctx . restore ( ) ;
98- }
114+ afterDraw ( chart , _args , options ) {
115+ draw ( chart , 'afterDraw' , options ) ;
99116 } ,
100117
101118 stop : function ( chart ) {
0 commit comments