@@ -472,7 +472,6 @@ Note:
472472 timeWindow === ' yearly' ? 50 :
473473 timeWindow === ' monthly' ? 75 : 100 ;
474474 const numTicks = Math .max (2 , Math .floor (pixels / minPixelsPerTick));
475- const currentDate = new Date (startDate);
476475 const yearStep = Math .ceil ((endDate .getFullYear () - startDate .getFullYear () + 1 ) / numTicks);
477476 const startMonth = 12 * startDate .getFullYear () + startDate .getMonth ();
478477 const endMonth = 12 * endDate .getFullYear () + endDate .getMonth ();
@@ -481,19 +480,18 @@ Note:
481480 const msPerDay = 1000 * 60 * 60 * 24 ;
482481 const dayStep = Math .ceil (msStep / msPerDay);
483482
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-
490483 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
492487 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)
495490 });
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);
497495 }
498496
499497 return ticks;
0 commit comments