-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Localize auto-formatted x-axis date ticks #2261
Localize auto-formatted x-axis date ticks #2261
Conversation
Thanks for the PR. Looks like @alexcjohnson was planning on doing this, but left it as a A few tests are failing. I suspect |
src/lib/dates.js
Outdated
headStr = yearFormatWorld(cDate); | ||
dateStr = dayFormatWorld(cDate); | ||
headStr = formatWorld(cDate, extraFormat.year); | ||
dateStr = formatWorld(cDate, extraFormat.dayMonth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modDateFormat
calls out to components/calendars
to get the full spectrum of d3-to-world-cal conversions - you've got the ones needed so far, but others will likely show up, and no need to reinvent the wheel with formatWorld
.
At one point there was a performance argument for the structure we have here because we could use precompiled formatters... but we lost that benefit with the original date localization PR #2207, so now I think there would be a much more concise way to do this, something like:
calendar = isWorldCalendar(calendar) && calendar;
if(!fmt) {
if(tr === 'y') fmt = extraFormat.year;
else if(tr === 'm') fmt = extraFormat.month;
else if(tr === 'd') {
fmt = extraFormat.dayMonth + '\n' + extraFormat.year;
}
else {
return modDateFormat(extraFormat.dayMonthYear, x, formatter, calendar) +
'\n' + formatTime(x, tr);
}
}
return modDateFormat(fmt, x, formatter, calendar);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I suspected that this conversion table existed somewhere but I didn't know exactly where to look (and code search with date/format/etc returned way too many entries).
I like the new proposal, pretty clear to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just test and it does work indeed on my example (only the last else
is incorrect, need to switch date and time).
src/locale-en.js
Outdated
year: '%Y', | ||
month: '%b %Y', | ||
dayMonth: '%b %e', | ||
dayMonthYear: '%b %e, %Y' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%e
is padded with a space for 1-digit days - we should switch back to %-d
, which has no padding (in fr.js
as well). That's responsible for the image test failures.
@TomDemulierChevret are you able to get the tests to run locally? It looks like You can run just these three suites with the command: |
Well I had a problem on my first try, but I will try again tomorrow. |
Sorry, didn't have time to check this issue on Friday. Regarding axes_test, the issue was with the initialisation of Regarding But since my knowledge of I will try to add new test in |
Just added a new test which check that both default locale (en) & provided locale format correctly the auto-formatted x-axis date tick. Do you feel it is enough or should I add more test case ? If everything is okay, can this PR be added to the next release ? |
@TomDemulierChevret looks great - thanks for the fixes, and the new test covers it all nicely. I'm re-running the tests - we've had a lot of spurious failures lately just when running the tests on CI, we're working on making those more robust - assuming it passes (eventually) I think this is ready to go! 💃 I'm going to wait a few days before merging, in case we need a patch release since we just put out several major new features. But yes, this will be in |
Perfect ! |
plotly#2261: Front: Reset zoom when detection time is applied
plotly#2261: Front: Reset zoom when detection time is applied
Features, Bug fixes, and others:
This pull request add the possibility to localize the auto-formatted x-axis date ticks.
It countains a working example for the french locale.
If some (or all) of the new formats are missing in the locale set by the user, format from the
en
locale will be used (as it does for the base d3 format and for the translation keys).