@@ -39,12 +39,14 @@ function updateRange(scale, {min, max}, limits, zoom = false) {
3939 }
4040 scaleOpts . min = min ;
4141 scaleOpts . max = max ;
42+ // return true if the scale range is changed
43+ return scale . parse ( min ) !== scale . min || scale . parse ( max ) !== scale . max ;
4244}
4345
4446function zoomNumericalScale ( scale , zoom , center , limits ) {
4547 const delta = zoomDelta ( scale , zoom , center ) ;
4648 const newRange = { min : scale . min + delta . min , max : scale . max - delta . max } ;
47- updateRange ( scale , newRange , limits , true ) ;
49+ return updateRange ( scale , newRange , limits , true ) ;
4850}
4951
5052const integerChange = ( v ) => v === 0 || isNaN ( v ) ? 0 : v < 0 ? Math . min ( Math . round ( v ) , - 1 ) : Math . max ( Math . round ( v ) , 1 ) ;
@@ -61,7 +63,7 @@ function zoomCategoryScale(scale, zoom, center, limits) {
6163 }
6264 const delta = zoomDelta ( scale , zoom , center ) ;
6365 const newRange = { min : scale . min + integerChange ( delta . min ) , max : scale . max - integerChange ( delta . max ) } ;
64- updateRange ( scale , newRange , limits , true ) ;
66+ return updateRange ( scale , newRange , limits , true ) ;
6567}
6668
6769const categoryDelta = new WeakMap ( ) ;
@@ -80,14 +82,27 @@ function panCategoryScale(scale, delta, panOptions, limits) {
8082
8183 categoryDelta . set ( scale , minIndex !== scaleMin ? 0 : cumDelta ) ;
8284
83- updateRange ( scale , { min : minIndex , max : maxIndex } , limits ) ;
85+ return updateRange ( scale , { min : minIndex , max : maxIndex } , limits ) ;
8486}
8587
88+ const OFFSETS = {
89+ second : 500 , // 500 ms
90+ minute : 30 * 1000 , // 30 s
91+ hour : 30 * 60 * 1000 , // 30 m
92+ day : 12 * 60 * 60 * 1000 , // 12 h
93+ week : 3.5 * 24 * 60 * 60 * 1000 , // 3.5 d
94+ month : 15 * 24 * 60 * 60 * 1000 , // 15 d
95+ quarter : 60 * 24 * 60 * 60 * 1000 , // 60 d
96+ year : 182 * 24 * 60 * 60 * 1000 // 182 d
97+ } ;
98+
8699function panNumericalScale ( scale , delta , panOptions , limits ) {
87- const { min : prevStart , max : prevEnd } = scale ;
88- const newMin = scale . getValueForPixel ( scale . getPixelForValue ( prevStart ) - delta ) ;
89- const newMax = scale . getValueForPixel ( scale . getPixelForValue ( prevEnd ) - delta ) ;
90- updateRange ( scale , { min : newMin , max : newMax } , limits ) ;
100+ const { min : prevStart , max : prevEnd , options} = scale ;
101+ const round = options . time && options . time . round ;
102+ const offset = OFFSETS [ round ] || 0 ;
103+ const newMin = scale . getValueForPixel ( scale . getPixelForValue ( prevStart + offset ) - delta ) ;
104+ const newMax = scale . getValueForPixel ( scale . getPixelForValue ( prevEnd + offset ) - delta ) ;
105+ return updateRange ( scale , { min : newMin , max : newMax } , limits ) ;
91106}
92107
93108export const zoomFunctions = {
0 commit comments