neherlab / covid19_scenarios

Models of COVID-19 outbreak trajectories and hospital demand
https://covid19-scenarios.org
MIT License
1.36k stars 352 forks source link

Human-friendly number formats (bonus: i18n) #158

Closed ivan-aksamentov closed 4 years ago

ivan-aksamentov commented 4 years ago

🙋 Feature Request

🔦 Context

Currently the numbers in plot tooltips, and possibly in other places are displayed as raw values. for example:

   deaths: 2654451

which is completely unreadable.

😯 Describe the feature

We need to display those in a human-friendly manner

deaths: 2.654 M

💻 Examples

See above

💁 Possible Solution

Related: https://github.com/neherlab/covid19_scenarios/issues/56

rcbevans commented 4 years ago

I'll pick this up, looks like d3 already has everything we need.

ivan-aksamentov commented 4 years ago

After some back and forth with libraries we ended up with numeral library.

numeral seems to be an abandoned library (last updated 3 years ago). And in particular there is a crash if you add numeralLocale for Polish, eve though polish locale seems to be present in numeral.

I found that numbro is a spiritual suceessor (originally a fork) to numeral with an old interface that is similar and a v2 interface with improvements. Many more locales also. https://github.com/BenjaminVanRyseghem/numbro http://numbrojs.com/

I reopen this for someone to pick up.

rcbevans commented 4 years ago

Alrighty, I'll do a swap for numbro now.

rcbevans commented 4 years ago

Only just got back around to this. Replace numeral with numbro. By default, French, German, and Portuguese locales use the same abbreviations as English.

I am using fr-Fr, de-De, and pt-Pt for locales. Some of the language variations use other endings if that would be preferred: see https://github.com/BenjaminVanRyseghem/numbro/blob/develop/languages/fr-CA.js.