@@ -167,6 +167,7 @@ export const useZoomRequeryXDomainSettings = (args: ZoomRequeryArgs) => {
167167 timeRange = null ,
168168 } = args
169169
170+ const [ selectedTimeRange , setSelectedTimeRange ] = useState ( timeRange )
170171 const initialDomain = useMemo ( ( ) => {
171172 if ( storedDomain ) {
172173 return storedDomain
@@ -178,6 +179,7 @@ export const useZoomRequeryXDomainSettings = (args: ZoomRequeryArgs) => {
178179 /*
179180 * preZoomDomain:
180181 * - can be changed only by the query results
182+ * - can be changed by the time range dropdown
181183 * - uses one-way state to capture the very first set of values
182184 */
183185 const [ preZoomDomain ] = useOneWayState ( initialDomain )
@@ -249,9 +251,13 @@ export const useZoomRequeryXDomainSettings = (args: ZoomRequeryArgs) => {
249251
250252 // sync preZoomDomain and domain
251253 // - when query results change to refit the graph
252- // - except when it is the time axis to prevent a shrunken graph
254+ // - when it is the time axis, then only if the timeRange has changed
253255 useEffect ( ( ) => {
254- if ( ! timeRange && isNotEqual ( preZoomDomain , domain ) ) {
256+ if (
257+ ( ! timeRange || isNotEqual ( timeRange , selectedTimeRange ) ) &&
258+ isNotEqual ( preZoomDomain , domain )
259+ ) {
260+ setSelectedTimeRange ( timeRange )
255261 setDomain ( preZoomDomain )
256262 }
257263 } , [ preZoomDomain ] ) // eslint-disable-line react-hooks/exhaustive-deps
@@ -291,6 +297,7 @@ export const useZoomRequeryYDomainSettings = (args: ZoomRequeryArgs) => {
291297 timeRange = null ,
292298 } = args
293299
300+ const [ selectedTimeRange , setSelectedTimeRange ] = useState ( timeRange )
294301 const initialDomain = useMemo ( ( ) => {
295302 if (
296303 ! Array . isArray ( storedDomain ) ||
@@ -307,6 +314,7 @@ export const useZoomRequeryYDomainSettings = (args: ZoomRequeryArgs) => {
307314 /*
308315 * preZoomDomain:
309316 * - can be changed only by the query results
317+ * - can be changed by the time range dropdown
310318 * - uses one-way state to capture the very first set of values
311319 */
312320 const [ preZoomDomain ] = useOneWayState ( initialDomain )
@@ -378,9 +386,13 @@ export const useZoomRequeryYDomainSettings = (args: ZoomRequeryArgs) => {
378386
379387 // sync preZoomDomain and domain
380388 // - when query results change to refit the graph
381- // - except when it is the time axis to prevent a shrunken graph
389+ // - when it is the time axis, then only if the timeRange has changed
382390 useEffect ( ( ) => {
383- if ( ! timeRange && isNotEqual ( preZoomDomain , domain ) ) {
391+ if (
392+ ( ! timeRange || isNotEqual ( timeRange , selectedTimeRange ) ) &&
393+ isNotEqual ( preZoomDomain , domain )
394+ ) {
395+ setSelectedTimeRange ( timeRange )
384396 setDomain ( preZoomDomain )
385397 }
386398 } , [ preZoomDomain ] ) // eslint-disable-line react-hooks/exhaustive-deps
0 commit comments