Skip to content

Commit e220b65

Browse files
committed
handle various time formats in ticklabelmode period
1 parent ad1e8ff commit e220b65

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

src/plots/cartesian/axes.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -700,18 +700,44 @@ axes.calcTicks = function calcTicks(ax, opts) {
700700
};
701701

702702
if(
703-
!_has('%f') &&
704-
!_has('%H') &&
705-
!_has('%I') &&
706-
!_has('%L') &&
707-
!_has('%Q') &&
708-
!_has('%S') &&
709-
!_has('%s') &&
710-
!_has('%X')
703+
!_has('%f') && // microseconds as a decimal number [000000, 999999]
704+
!_has('%L') && // milliseconds as a decimal number [000, 999]
705+
!_has('%Q') && // milliseconds since UNIX epoch
706+
!_has('%s') && // seconds since UNIX epoch
707+
!_has('%S') && // second as a decimal number [00,61]
708+
!_has('%M') && // minute as a decimal number [00,59]
709+
!_has('%H') && // hour (24-hour clock) as a decimal number [00,23]
710+
!_has('%I') && // hour (12-hour clock) as a decimal number [01,12]
711+
!_has('%p') && // either AM or PM
712+
!_has('%X') // the locale’s time, such as %-I:%M:%S %p
711713
) {
712-
if(_has('%x') || _has('%d') || _has('%e') || _has('%j')) definedDelta = ONEDAY;
713-
else if(_has('%B') || _has('%b') || _has('%m')) definedDelta = ONEAVGMONTH;
714-
else if(_has('%Y') || _has('%y')) definedDelta = ONEAVGYEAR;
714+
if(
715+
_has('%d') || // zero-padded day of the month as a decimal number [01,31]
716+
_has('%e') || // space-padded day of the month as a decimal number [ 1,31]
717+
_has('%j') || // day of the year as a decimal number [001,366]
718+
_has('%u') || // Monday-based (ISO 8601) weekday as a decimal number [1,7]
719+
_has('%w') || // Sunday-based weekday as a decimal number [0,6]
720+
_has('%x') // the locale’s date, such as %-m/%-d/%Y
721+
) definedDelta = ONEDAY;
722+
else if(
723+
_has('%A') || // full weekday name
724+
_has('%a') || // abbreviated weekday name
725+
_has('%U') || // Sunday-based week of the year as a decimal number [00,53]
726+
_has('%V') || // ISO 8601 week of the year as a decimal number [01, 53]
727+
_has('%W') // Monday-based week of the year as a decimal number [00,53]
728+
) definedDelta = ONEDAY * 7;
729+
else if(
730+
_has('%B') || // full month name
731+
_has('%b') || // abbreviated month name
732+
_has('%m') // month as a decimal number [01,12]
733+
) definedDelta = ONEAVGMONTH;
734+
else if(
735+
_has('%q') // quarter of the year as a decimal number [1,4]
736+
) definedDelta = ONEAVGYEAR / 4;
737+
else if(
738+
_has('%Y') || // year with century as a decimal number, such as 1999
739+
_has('%y') // year without century as a decimal number [00,99]
740+
) definedDelta = ONEAVGYEAR;
715741
}
716742
}
717743

0 commit comments

Comments
 (0)