Skip to content
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

handle various time formats in ticklabelmode period #5065

Merged
merged 14 commits into from Aug 13, 2020

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Aug 11, 2020

Follow up of implementing #4911 by #4993 and considering adding new time-formats added in #5026.

@plotly/plotly_js

else if(
_has('%A') || // full weekday name
_has('%a') || // abbreviated weekday name
_has('%U') || // Sunday-based week of the year as a decimal number [00,53]
Copy link
Member

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
Member

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
Contributor

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
Member

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
Contributor

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...

Copy link
Contributor

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

@archmoj functionally this looks good. I feel like perf and compactness may improve with a single regex test, eg /%[fLQsSMHIpX]/.test(ax.tickformat) instead of repeated indexOf calls. Not a big deal though. Just need a couple of jasmine tests, and your call whether to add the tick0 Sunday/Monday fix here or in a separate PR.

@nicolaskruchten
Copy link
Member

Here's a pen based on this bundle: https://codepen.io/nicolaskruchten/pen/rNeOgXj?editors=0010 (no rangebreaks) ... the label doesn't appear in the middle of the week unfortunately

) definedDelta = ONEDAY;
else if(
_has('%A') || // full weekday name
_has('%a') || // abbreviated weekday name
Copy link
Contributor

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.

afterEach(destroyGraphDiv);

function _assert(msg, exp) {
var labelPositions = gd._fullLayout.xaxis._vals.map(function(d) { return d.periodX; });
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice tests! But can we use _fullLayout.xaxis.c2d(d.periodX) to get these back into date string form - eg 1562079600000 would give '2019-07-02 15:00', and it's not clear to me how we got that precise value, but at least it has a recognizable meaning.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also perhaps we can test the text that's stored in xaxis._vals[].text so it's obvious what labels we're showing at what datetime values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very nice tests! But can we use _fullLayout.xaxis.c2d(d.periodX) to get these back into date string form - eg 1562079600000 would give '2019-07-02 15:00', and it's not clear to me how we got that precise value, but at least it has a recognizable meaning.

Good call. Done in f0f078a.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also perhaps we can test the text that's stored in xaxis._vals[].text so it's obvious what labels we're showing at what datetime values?

Done in 90ee834.

Comment on lines 5246 to 5247
})
.then(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
})
.then(function() {

Not a big deal, but here (and the other new tests) these assertions can be done together.

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 1c94ba9.

Copy link
Contributor

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

Beauty! Thanks for the test changes, much easier to see what's really going on 💃

@archmoj archmoj merged commit 00d7c6b into master Aug 13, 2020
@archmoj archmoj deleted the new-formats-in-period-ticklabelmode branch August 13, 2020 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants