Open
Description
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:
vl.vega.timeFormatLocale(locale);
vl.vega.formatLocale(locale);
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!
Activity
[-]A global locale option[/-][+]A top-level locale option[/+]mbostock commentedon May 12, 2021
I propose this is a top-level Plot.plot option, i.e.,
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:
(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:
mbostock commentedon May 12, 2021
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.
Fil commentedon May 13, 2021
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.)
rusosnith commentedon May 2, 2022
This would be very important for us spanish users! Date parse as mentioned for axis it's a must!
Fil commentedon May 7, 2022
See also https://blog.datawrapper.de/right-to-left-visualizations/
rusosnith commentedon Jul 1, 2022
MAybe this should be handled on notebook level? as in an Observable configuration itself?
that would be really handy
observablehq/feedback#411 (comment)
oluckyman commentedon Jan 25, 2023
Any suggestion how to set ticks locale now, while the
locale
option is not implemented?I am aware that I can set
scale.tickFormat
, but don't want to copypaste the implementation of multi-scale time format which is used ind3
by default.Is there a simpler option?
Fil commentedon Jan 25, 2023
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.
oluckyman commentedon Jan 25, 2023
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.
rusosnith commentedon Apr 10, 2024
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