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

Update formatting, add locale support. #313

Merged
merged 1 commit into from
Jul 30, 2015
Merged

Update formatting, add locale support. #313

merged 1 commit into from
Jul 30, 2015

Conversation

jheer
Copy link
Member

@jheer jheer commented Jul 30, 2015

This PR updates all axis, legend and template formatting to pass through datalib's formatting support (^1.4.2). As a result Vega/Datalib now control all automatic formatting decisions, with no reliance on (inconsistent) D3 scale tickFormat methods. Most importantly, these facilities support runtime changes to current number and time locale formatting.

For example, to change the number formatting to German (DE-DE):

vg.util.format.numberLocale({
  decimal: ",",
  thousands: ".",
  grouping: [3],
  currency: ["", "\xa0€"]
});

To change the time formatting to German (DE-DE):

vg.util.format.timeLocale({
  dateTime: "%A, der %e. %B %Y, %X",
  date: "%d.%m.%Y",
  time: "%H:%M:%S",
  periods: ["AM", "PM"], // unused
  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"]
});

For more about locale settings, see the d3-format and d3-time-format module repositories.

@jheer jheer added the enhancement For enhancement of existing features label Jul 30, 2015
arvind added a commit that referenced this pull request Jul 30, 2015
Update formatting, add locale support.
@arvind arvind merged commit 7d37c44 into master Jul 30, 2015
@arvind arvind deleted the jh-locale branch July 30, 2015 17:16
@Fil
Copy link
Contributor

Fil commented Apr 26, 2017

What is the correct method with Vega3, and where is it documented? (Sorry to ask here but it's the only reference I found.)

Inspecting the vega object I found the vega.formatLocale method, and a way to get the result I want — but it seems I have to call it before parsing the spec, is that correct?

@jheer
Copy link
Member Author

jheer commented Apr 26, 2017

Yes, Vega 3 exports the formatLocale and formatTimeLocale methods for localization settings. These are actually direct exports of D3 v4's formatDefaultLocale and timeFormatDefaultLocale methods. These set the global default locales for number and time formatting, respectively.

You will want to invoke these methods prior to instantiating a Vega View and thus before any formatting functions are generated. You should be able to parse a spec ahead of time, but you will need to set the locale before invoking the View constructor for your vis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement For enhancement of existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants