@@ -3,21 +3,38 @@ import {panFunctions, updateRange, zoomFunctions} from './scale.types';
33import { getState } from './state' ;
44import { directionEnabled , getEnabledScalesByPoint } from './utils' ;
55
6+ function shouldUpdateScaleLimits ( scale , originalScaleLimits , updatedScaleLimits ) {
7+ const { id, options : { min, max} } = scale ;
8+ if ( ! originalScaleLimits [ id ] || ! updatedScaleLimits [ id ] ) {
9+ return true ;
10+ }
11+ const previous = updatedScaleLimits [ id ] ;
12+ return previous . min !== min || previous . max !== max ;
13+ }
14+
15+ function removeMissingScales ( limits , scales ) {
16+ each ( limits , ( opt , key ) => {
17+ if ( ! scales [ key ] ) {
18+ delete limits [ key ] ;
19+ }
20+ } ) ;
21+ }
22+
623function storeOriginalScaleLimits ( chart , state ) {
7- const { originalScaleLimits} = state ;
8- each ( chart . scales , function ( scale ) {
9- if ( ! originalScaleLimits [ scale . id ] ) {
24+ const { scales} = chart ;
25+ const { originalScaleLimits, updatedScaleLimits} = state ;
26+
27+ each ( scales , function ( scale ) {
28+ if ( shouldUpdateScaleLimits ( scale , originalScaleLimits , updatedScaleLimits ) ) {
1029 originalScaleLimits [ scale . id ] = {
1130 min : { scale : scale . min , options : scale . options . min } ,
1231 max : { scale : scale . max , options : scale . options . max } ,
1332 } ;
1433 }
1534 } ) ;
16- each ( originalScaleLimits , function ( opt , key ) {
17- if ( ! chart . scales [ key ] ) {
18- delete originalScaleLimits [ key ] ;
19- }
20- } ) ;
35+
36+ removeMissingScales ( originalScaleLimits , scales ) ;
37+ removeMissingScales ( updatedScaleLimits , scales ) ;
2138 return originalScaleLimits ;
2239}
2340
0 commit comments