1+ import { valueOrDefault } from 'chart.js/helpers' ;
12import { getState } from './state' ;
23
34function zoomDelta ( scale , zoom , center ) {
@@ -14,26 +15,23 @@ function zoomDelta(scale, zoom, center) {
1415 } ;
1516}
1617
17- function getLimit ( chartState , scale , scaleLimits , prop , fallback ) {
18+ function getLimit ( state , scale , scaleLimits , prop , fallback ) {
1819 let limit = scaleLimits [ prop ] ;
1920 if ( limit === 'original' ) {
20- const original = chartState . originalScaleLimits [ scale . id ] [ prop ] ;
21- limit = original . options !== null && original . options !== undefined ? original . options : original . scale ;
21+ const original = state . originalScaleLimits [ scale . id ] [ prop ] ;
22+ limit = valueOrDefault ( original . options , original . scale ) ;
2223 }
23- if ( limit === null || limit === undefined ) {
24- limit = fallback ;
25- }
26- return limit ;
24+ return valueOrDefault ( limit , fallback ) ;
2725}
2826
2927export function updateRange ( scale , { min, max} , limits , zoom = false ) {
30- const chartState = getState ( scale . chart ) ;
28+ const state = getState ( scale . chart ) ;
3129 const { id, axis, options : scaleOpts } = scale ;
3230
3331 const scaleLimits = limits && ( limits [ id ] || limits [ axis ] ) || { } ;
3432 const { minRange = 0 } = scaleLimits ;
35- const minLimit = getLimit ( chartState , scale , scaleLimits , 'min' , - Infinity ) ;
36- const maxLimit = getLimit ( chartState , scale , scaleLimits , 'max' , Infinity ) ;
33+ const minLimit = getLimit ( state , scale , scaleLimits , 'min' , - Infinity ) ;
34+ const maxLimit = getLimit ( state , scale , scaleLimits , 'max' , Infinity ) ;
3735
3836 const cmin = Math . max ( min , minLimit ) ;
3937 const cmax = Math . min ( max , maxLimit ) ;
0 commit comments