Skip to content

Commit

Permalink
Merge pull request #1097 from MilosKozak/wip/d3locale
Browse files Browse the repository at this point in the history
Wip/d3locale
  • Loading branch information
jasoncalabrese committed Sep 27, 2015
2 parents 2182c6e + 1b474a3 commit 4ac6d80
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var _ = require('lodash');
var times = require('../times');
var d3locales = require('../d3locales');

var DEBOUNCE_MS = 10
, padding = { bottom: 30 }
Expand All @@ -13,6 +14,8 @@ function init (client, d3, $) {
var utils = client.utils;
var renderer = client.renderer;

var localeFormater = d3.locale(d3locales.locale(client.settings.language));

function brushStarted ( ) {
// update the opacity of the context data points to brush extent
chart.context.selectAll('circle')
Expand Down Expand Up @@ -40,7 +43,7 @@ function init (client, d3, $) {
var yScale2 = chart.yScale2 = d3.scale.log()
.domain([utils.scaleMgdl(36), utils.scaleMgdl(420)]);

var tickFormat = d3.time.format.multi( [
var tickFormat = localeFormater.timeFormat.multi( [
['.%L', function(d) { return d.getMilliseconds(); }],
[':%S', function(d) { return d.getSeconds(); }],
['%I:%M', function(d) { return d.getMinutes(); }],
Expand Down Expand Up @@ -84,7 +87,7 @@ function init (client, d3, $) {

chart.yAxis = d3.svg.axis()
.scale(yScale)
.tickFormat(d3.format('d'))
.tickFormat(localeFormater.timeFormat('d'))
.tickValues(tickValues)
.orient('left');

Expand All @@ -96,7 +99,7 @@ function init (client, d3, $) {

chart.yAxis2 = d3.svg.axis()
.scale(yScale2)
.tickFormat(d3.format('d'))
.tickFormat(localeFormater.timeFormat('d'))
.tickValues(tickValues)
.orient('right');

Expand Down
181 changes: 181 additions & 0 deletions lib/d3locales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
'use strict';

// https://github.com/mbostock/d3/wiki/Localization
// https://github.com/mbostock/d3/wiki/Time-Formatting#format
// some are in node_modules/d3/src/locale


var d3locales = { };

d3locales.cs_CZ = {
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['', 'CZK'],
dateTime: '%A %e %b %Y %X',
date: '%d.%m.%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'],
days: ['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'],
shortDays: ['Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'],
months: ['Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'],
shortMonths: ['Led', 'Úno', 'Bře', 'Dub', 'Kvě', 'Čvn', 'Čvc', 'Srp', 'Zář', 'Říj', 'Lis', 'Pro']
};

d3locales.de_DE = {
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['', ' €'],
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']
};

d3locales.en_US = {
decimal: '.',
thousands: ',',
grouping: [3],
currency: ['$', ''],
dateTime: '%a %b %e %X %Y',
date: '%m/%d/%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'],
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
};

d3locales.es_ES = {
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['', ' €'],
dateTime: '%A, %e de %B de %Y, %X',
date: '%d/%m/%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'],
days: ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'],
shortDays: ['dom', 'lun', 'mar', 'mié', 'jue', 'vie', 'sáb'],
months: ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'],
shortMonths: ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'sep', 'oct', 'nov', 'dic']
};

d3locales.fi_FI = {
decimal: ',',
thousands: '\xa0',
grouping: [3],
currency: ['', '\xa0€'],
dateTime: '%A, %-d. %Bta %Y klo %X',
date: '%-d.%-m.%Y',
time: '%H:%M:%S',
periods: ['a.m.', 'p.m.'],
days: ['sunnuntai', 'maanantai', 'tiistai', 'keskiviikko', 'torstai', 'perjantai', 'lauantai'],
shortDays: ['Su', 'Ma', 'Ti', 'Ke', 'To', 'Pe', 'La'],
months: ['tammikuu', 'helmikuu', 'maaliskuu', 'huhtikuu', 'toukokuu', 'kesäkuu', 'heinäkuu', 'elokuu', 'syyskuu', 'lokakuu', 'marraskuu', 'joulukuu'],
shortMonths: ['Tammi', 'Helmi', 'Maalis', 'Huhti', 'Touko', 'Kesä', 'Heinä', 'Elo', 'Syys', 'Loka', 'Marras', 'Joulu']
};

d3locales.fr_FR = {
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['', ' €'],
dateTime: '%A, le %e %B %Y, %X',
date: '%d/%m/%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'], // unused
days: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
shortDays: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
months: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
shortMonths: ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.']
};

d3locales.he_IL = {
decimal: '.',
thousands: ',',
grouping: [3],
currency: ['₪', ''],
dateTime: '%A, %e ב%B %Y %X',
date: '%d.%m.%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'],
days: ['ראשון', 'שני', 'שלישי', 'רביעי', 'חמישי', 'שישי', 'שבת'],
shortDays: ['א׳', 'ב׳', 'ג׳', 'ד׳', 'ה׳', 'ו׳', 'ש׳'],
months: ['ינואר', 'פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר', 'דצמבר'],
shortMonths: ['ינו׳', 'פבר׳', 'מרץ', 'אפר׳', 'מאי', 'יוני', 'יולי', 'אוג׳', 'ספט׳', 'אוק׳', 'נוב׳', 'דצמ׳']
};

d3locales.it_IT = {
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['€', ''],
dateTime: '%A %e %B %Y, %X',
date: '%d/%m/%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'], // unused
days: ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'],
shortDays: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'],
months: ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
shortMonths: ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic']
};

d3locales.pt_BR = {
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['R$', ''],
dateTime: '%A, %e de %B de %Y. %X',
date: '%d/%m/%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'],
days: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'],
shortDays: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
months: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
shortMonths: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez']
};

d3locales.ru_RU = {
decimal: ',',
thousands: '\xa0',
grouping: [3],
currency: ['', ' руб.'],
dateTime: '%A, %e %B %Y г. %X',
date: '%d.%m.%Y',
time: '%H:%M:%S',
periods: ['AM', 'PM'],
days: ['воскресенье', 'понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота'],
shortDays: ['вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб'],
months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
};

d3locales.locale = function locale (language) {
// map locale until we switch to full en_US
var mapper = {
cs: 'cs_CZ'
, de: 'de_DE'
, en: 'en_US'
, es: 'es_ES'
, fi: 'fi_FI'
, fr: 'fr_FR'
, he: 'he_IL'
, it: 'it_IT'
, pt: 'pt_BR'
, ru: 'ru_RU'
};
var loc = 'en_US';
if (mapper[language]) {
loc = mapper[language];
}
return d3locales[loc];
};

module.exports = d3locales;

0 comments on commit 4ac6d80

Please sign in to comment.