Skip to content

handle various time formats in ticklabelmode period #5065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,18 +700,44 @@ axes.calcTicks = function calcTicks(ax, opts) {
};

if(
!_has('%f') &&
!_has('%H') &&
!_has('%I') &&
!_has('%L') &&
!_has('%Q') &&
!_has('%S') &&
!_has('%s') &&
!_has('%X')
!_has('%f') && // microseconds as a decimal number [000000, 999999]
!_has('%L') && // milliseconds as a decimal number [000, 999]
!_has('%Q') && // milliseconds since UNIX epoch
!_has('%s') && // seconds since UNIX epoch
!_has('%S') && // second as a decimal number [00,61]
!_has('%M') && // minute as a decimal number [00,59]
!_has('%H') && // hour (24-hour clock) as a decimal number [00,23]
!_has('%I') && // hour (12-hour clock) as a decimal number [01,12]
!_has('%p') && // either AM or PM
!_has('%X') // the locale’s time, such as %-I:%M:%S %p
) {
if(_has('%x') || _has('%d') || _has('%e') || _has('%j')) definedDelta = ONEDAY;
else if(_has('%B') || _has('%b') || _has('%m')) definedDelta = ONEAVGMONTH;
else if(_has('%Y') || _has('%y')) definedDelta = ONEAVGYEAR;
if(
_has('%d') || // zero-padded day of the month as a decimal number [01,31]
_has('%e') || // space-padded day of the month as a decimal number [ 1,31]
_has('%j') || // day of the year as a decimal number [001,366]
_has('%u') || // Monday-based (ISO 8601) weekday as a decimal number [1,7]
_has('%w') || // Sunday-based weekday as a decimal number [0,6]
_has('%x') // the locale’s date, such as %-m/%-d/%Y
) definedDelta = ONEDAY;
else if(
_has('%A') || // full weekday name
_has('%a') || // abbreviated weekday name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't weekdays go in the ONEDAY bucket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9424347.

_has('%U') || // Sunday-based week of the year as a decimal number [00,53]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where in the code do you differentiate between the start point of %U and %W (Sunday vs Monday) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This is just the fall back to set the distance between labels.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but then how can we differentiate between sunday- and monday-starting weeks? via tick0 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - it's a bit different from the point of this PR, but here's where the automatic tick0 gets set to Sundays:

// get week ticks on sunday
// this will also move the base tick off 2000-01-01 if dtick is
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
ax.tick0 = Lib.dateTick0(ax.calendar, true);

I guess with a tickformat including %W we should add a day to the result there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should, yes :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also %V starts on Mondays.

Side note: Am I missing something or are %u (new week on Monday) and %w (new week on Sunday) backward compared to %U (new week on Sunday) and %W (new week on Monday)? I mean, not an error here, nor in D3, this dates back to strftime from C so has probably been around for 40 years...

_has('%V') || // ISO 8601 week of the year as a decimal number [01, 53]
_has('%W') // Monday-based week of the year as a decimal number [00,53]
) definedDelta = ONEDAY * 7;
else if(
_has('%B') || // full month name
_has('%b') || // abbreviated month name
_has('%m') // month as a decimal number [01,12]
) definedDelta = ONEAVGMONTH;
else if(
_has('%q') // quarter of the year as a decimal number [1,4]
) definedDelta = ONEAVGYEAR / 4;
else if(
_has('%Y') || // year with century as a decimal number, such as 1999
_has('%y') // year without century as a decimal number [00,99]
) definedDelta = ONEAVGYEAR;
}
}

Expand Down