Improve number formatting

Use locale-aware number formatting (i.e. add grouping separators).

Use hours and minutes to format travel time.
This commit is contained in:
Henrik Fehlauer 2019-05-30 23:52:59 +02:00
parent 3ee90b5cd9
commit 9bc38fea89
3 changed files with 32 additions and 14 deletions

View file

@ -945,9 +945,9 @@
<p class="stats-label">
<span id="totaltime">-</span>
<abbr
data-i18n="[title]footer.minutes;footer.minutes-abbrev"
title="minutes"
>min</abbr
data-i18n="[title]footer.hours;footer.hours-abbrev"
title="hours"
>h</abbr
>
</p>
</li>

View file

@ -14,26 +14,44 @@ BR.TrackStats = L.Class.extend({
}
var stats = this.calcStats(polyline, segments),
length1 = L.Util.formatNum(stats.trackLength / 1000, 1),
length3 = L.Util.formatNum(stats.trackLength / 1000, 3),
length1 = L.Util.formatNum(
stats.trackLength / 1000,
1
).toLocaleString(),
length3 = L.Util.formatNum(
stats.trackLength / 1000,
3
).toLocaleString(),
formattedAscend = stats.filteredAscend.toLocaleString(),
formattedPlainAscend = stats.plainAscend.toLocaleString(),
formattedCost = stats.cost.toLocaleString(),
meanCostFactor = stats.trackLength
? L.Util.formatNum(stats.cost / stats.trackLength, 2)
? L.Util.formatNum(
stats.cost / stats.trackLength,
2
).toLocaleString()
: '0',
formattedTime = L.Util.formatNum(stats.totalTime / 60, 1),
formattedEnergy = L.Util.formatNum(stats.totalEnergy / 3600000, 2),
formattedTime =
Math.trunc(stats.totalTime / 3600) +
':' +
('0' + Math.trunc((stats.totalTime % 3600) / 60)).slice(-2),
formattedEnergy = L.Util.formatNum(
stats.totalEnergy / 3600000,
2
).toLocaleString(),
meanEnergy = stats.trackLength
? L.Util.formatNum(
stats.totalEnergy / 36 / stats.trackLength,
2
)
).toLocaleString()
: '0';
$('#distance').html(length1);
// alternative 3-digit format down to meters as tooltip
$('#distance').attr('title', length3 + ' km');
$('#ascend').html(stats.filteredAscend);
$('#plainascend').html(stats.plainAscend);
$('#cost').html(stats.cost);
$('#ascend').html(formattedAscend);
$('#plainascend').html(formattedPlainAscend);
$('#cost').html(formattedCost);
$('#meancostfactor').html(meanCostFactor);
$('#totaltime').html(formattedTime);
$('#totalenergy').html(formattedEnergy);

View file

@ -44,8 +44,8 @@
"kilowatthour-abbrev": "kWh",
"meter": "meters",
"meter-abbrev": "m",
"minutes": "minutes",
"minutes-abbrev": "min",
"hours": "hours",
"hours-abbrev": "h",
"total-energy": "Total Energy",
"energy-per-100km": "Energy per 100 km",
"travel-time": "Travel time"