@@ -472,7 +472,6 @@ Note:
472
472
timeWindow === ' yearly' ? 50 :
473
473
timeWindow === ' monthly' ? 75 : 100 ;
474
474
const numTicks = Math .max (2 , Math .floor (pixels / minPixelsPerTick));
475
- const currentDate = new Date (startDate);
476
475
const yearStep = Math .ceil ((endDate .getFullYear () - startDate .getFullYear () + 1 ) / numTicks);
477
476
const startMonth = 12 * startDate .getFullYear () + startDate .getMonth ();
478
477
const endMonth = 12 * endDate .getFullYear () + endDate .getMonth ();
@@ -481,19 +480,18 @@ Note:
481
480
const msPerDay = 1000 * 60 * 60 * 24 ;
482
481
const dayStep = Math .ceil (msStep / msPerDay);
483
482
484
- function incrementDate (d , yearStep , monthStep , dayStep ) {
485
- if (timeWindow === ' yearly' ) d .setFullYear (d .getFullYear () + yearStep);
486
- else if (timeWindow === ' monthly' ) d .setMonth (d .getMonth () + monthStep);
487
- else d .setDate (d .getDate () + dayStep);
488
- }
489
-
490
483
const ticks = [];
491
- while (ticks .length < numTicks && currentDate <= endDate) {
484
+ const date = new Date (startDate);
485
+ while (ticks .length < numTicks && date <= endDate) {
486
+ // Record the label in the ticks list
492
487
ticks .push ({
493
- v: currentDate .getTime (),
494
- label: opts (' axisLabelFormatter' ).call (dygraph, currentDate , 0 , opts, dygraph)
488
+ v: date .getTime (),
489
+ label: opts (' axisLabelFormatter' ).call (dygraph, date , 0 , opts, dygraph)
495
490
});
496
- incrementDate (currentDate, yearStep, monthStep, dayStep);
491
+ // Increment date to next label position
492
+ if (timeWindow === ' yearly' ) date .setFullYear (date .getFullYear () + yearStep);
493
+ else if (timeWindow === ' monthly' ) date .setMonth (date .getMonth () + monthStep);
494
+ else date .setDate (date .getDate () + dayStep);
497
495
}
498
496
499
497
return ticks;
0 commit comments