Skip to content

Commit

Permalink
feat: add in localization override for time and num
Browse files Browse the repository at this point in the history
  • Loading branch information
willfarrell committed Aug 11, 2024
1 parent 91de800 commit d74aafd
Show file tree
Hide file tree
Showing 12 changed files with 593 additions and 1,113 deletions.
2 changes: 1 addition & 1 deletion demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h1>μPlot Demos</h1>
<a href="timeseries-discrete.html">Discrete &amp; shifted series w/sync</a>
<a href="update-cursor-select-resize.html">Maintains location of cursor/select/hoverPts during resize (test)</a>

<a href="months-ru.html">Russian month names on date/time axis</a>
<a href="localize-fr-ca.html">Override default localization (French Canada)</a>
<a href="add-del-series.html">Dynamically add or delete series</a>
<a href="scroll-sync.html">Sync chart position when inside a scrollable container</a>

Expand Down
17 changes: 5 additions & 12 deletions demos/months-ru.html → demos/localize-fr-ca.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Months (Russian)</title>
<title>Localize Time & Measure (French Canadian)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="../dist/uPlot.min.css">
Expand All @@ -23,26 +23,19 @@
})
});

let vals = [0,1,2,3,4,5,6,7,8,9,10];
let vals = [1000.1,1100.1,1200.2,1300.3,1400.4,1500.5,1600.6,1700.7,1800.8,1900.9,2000.10];

let data = [
ts,
ts.map((t, i) => i == 0 ? 5 : vals[Math.floor(Math.random() * vals.length)]),
ts.map((t, i) => i == 0 ? 1500 : vals[Math.floor(Math.random() * vals.length)]),
];

const ruNames = {
MMMM: ["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"],
MMM: ["Янв","Февр","Март","Апр","Май","Июнь","Июль","Авг","Сент","Окт","Нояб","Дек"],
WWWW: ["Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота"],
WWW: ["Вск","Пнд","Втр","Срд","Чтв","Птн","Сбт"],
};

const opts = {
width: 1920,
height: 600,
title: "Months",
locale: 'fr-CA',
tzDate: ts => uPlot.tzDate(new Date(ts * 1e3), 'Etc/UTC'),
fmtDate: tpl => uPlot.fmtDate(tpl, ruNames),
series: [
{},
{
Expand All @@ -54,4 +47,4 @@
let u = new uPlot(opts, data, document.body);
</script>
</body>
</html>
</html>
Loading

0 comments on commit d74aafd

Please sign in to comment.