-
Notifications
You must be signed in to change notification settings - Fork 185
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
A top-level locale option #384
Comments
I propose this is a top-level Plot.plot option, i.e., Plot.plot({
locale: "de",
marks: …
}) The plot should then inherit this locale rather than the default "en-US". This is possibly a little tricky with things like Plot.formatWeekday since that function currently needs to be supplied the locale upon creation, whereas here we would need to somehow pass the plot’s locale into the format function. One way to do that might be to pass the plot’s locale to the format function instead: function formatMonth(month = "short") {
return (i, locale = "en-US") => {
if (i != null && !isNaN(i = new Date(Date.UTC(2000, +i)))) {
return i.toLocaleString(locale, {timeZone: "UTC", month});
}
};
} (I think this would also be slower since we couldn’t reuse the same Intl.DateFormatInstance, but we could address that separately using memoization.) In addition, we could do something like Plot.defaults: plot = Plot.defaults({locale: "de"}) plot({marks: …}) |
And more specifically: let’s not use global mutation, e.g. Plot.setLocale(locale), since this makes it hard to support multiple locales on the page and introduces ordering problems where the behavior of Plot.plot will change before or after a call to Plot.setLocale. |
This would also impact the automatic word "frequency", #395, and maybe other language elements. (Regarding autodetection of "date"/"year" to omit the axis label, it is based on the field name so I would tend to not consider it in this context.) |
This would be very important for us spanish users! Date parse as mentioned for axis it's a must! |
MAybe this should be handled on notebook level? as in an Observable configuration itself? that would be really handy |
Any suggestion how to set ticks locale now, while the I am aware that I can set |
why?
I don't think so. The only alternative I can think of is to work on implementing this in Plot, so it can be simpler in the future. |
I think it's irrational. Observable + Plot usually work like magic and allow to stay in the flow longer, so any obstacle feels frustrating. But it's not a problem. I'll make my own multi-scale time format to reuse in Plots. Just wondered if there was a solution that I was not aware of. |
I'm back here to add more push to this. So sad to see other-than-english languages are left out of the Plot magic sad emoji |
Wherever English formatting appears by default, a simple possibility of taking into account any other language could/should be proposed.
E.g.: formatting of numbers or dates on the axes.
Suggestion: a high level
locale
property in a Plot specification, applying to the whole plot. By default, locale is set to "en".This would work in a similar way to what has very usefully appeared in the Table component.
Note: vega-lite allows you to globally specify a locale for numbers and for dates:
PS: Plot is a great library, very intellectually stimulating, and the 21 beautifully written articles in the https://observablehq.com/collection/@observablehq/plot collection should be read by all data scientists!
The text was updated successfully, but these errors were encountered: