vscode-vega-viewer icon indicating copy to clipboard operation
vscode-vega-viewer copied to clipboard

add date and numbers extension formatting seetings for rendered and exported vega charts

Open stenzengel opened this issue 5 years ago • 3 comments

Is it possible to set timeFormatLocale and formatLocale to non-default values for the preview and when exporting images?

This is supported by Vega and Vega-Lite:

  • https://vega.github.io/vega/docs/api/locale/
  • https://gist.github.com/domoritz/a5707e5d9430c173019583ea8bc5707a

E.g I would like to see a preview and export an SVG image in the German locale:

  1. formatLocale
{
  "decimal": ",",
  "thousands": ".",
  "grouping": [3],
  "currency": ["", "\u00a0€"]
}
  1. timeFormatLocale
{
  "dateTime": "%A, der %e. %B %Y, %X",
  "date": "%d.%m.%Y",
  "time": "%H:%M:%S",
  "periods": ["AM", "PM"],
  "days": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
  "shortDays": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
  "months": ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
  "shortMonths": ["Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]
}

My personal favorite solution would be to be able to define this in the VS Code Settings (User, Folder or Workspace) and not have to do this every time I open a preview.

Any help greatly appreciated.

stenzengel avatar Jan 26 '20 14:01 stenzengel

@stenzengel so, I like the idea, however that's a lot of settings to add and config.

What if we just add date/time and numbers locale settings and then let vega-embed handle the rest via JS, etc.

So, I propose we specify Date/Time default locale setting i.e. en-US, etc. Similar for numbers.

Then sort it out on the Vega spec and rendering side.

Also, I do believe you have ability to do this in vega specs if your charts are locale sensitive.

What am I missing so far?

RandomFractals avatar Jan 27 '20 05:01 RandomFractals

@RandomFractals Yes, to only specify the locale in the VS Code settings (User, Folder or Workspace) is my preferred solution. Personally, I do not need to specify each property of the locale settings (e.g. decimal or thousands) individually, only specifying "de-DE" would be the easiest form me. I think it should be ok, to specify only one locale which is used for both vega-lite settings (formatLocale, timeFormatLocale), but specifying both is perhaps easier to implement.

I did not find the ability to specify the locale in the vega specs (e.g. in the json file). If it is possible, can you give me a URL to the vega-lite documentation?

stenzengel avatar Jan 28 '20 07:01 stenzengel

ok. I'll just add locales for numbers and date formatting to this extension Settings then. You will be able to set them in User settings for all Vega renders, or Workspace settings for a poject.

I had a brief chat with @domoritz from Vega team and he preferred this simple solution to configure it too.

I'll dig into Vega api to see if there is a way to do it by locale name, rather than fine settings you outlined originally to keep it simple.

RandomFractals avatar Jan 28 '20 12:01 RandomFractals