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:
parent
3ee90b5cd9
commit
9bc38fea89
3 changed files with 32 additions and 14 deletions
|
|
@ -945,9 +945,9 @@
|
||||||
<p class="stats-label">
|
<p class="stats-label">
|
||||||
<span id="totaltime">-</span>
|
<span id="totaltime">-</span>
|
||||||
<abbr
|
<abbr
|
||||||
data-i18n="[title]footer.minutes;footer.minutes-abbrev"
|
data-i18n="[title]footer.hours;footer.hours-abbrev"
|
||||||
title="minutes"
|
title="hours"
|
||||||
>min</abbr
|
>h</abbr
|
||||||
>
|
>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
|
|
@ -14,26 +14,44 @@ BR.TrackStats = L.Class.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
var stats = this.calcStats(polyline, segments),
|
var stats = this.calcStats(polyline, segments),
|
||||||
length1 = L.Util.formatNum(stats.trackLength / 1000, 1),
|
length1 = L.Util.formatNum(
|
||||||
length3 = L.Util.formatNum(stats.trackLength / 1000, 3),
|
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
|
meanCostFactor = stats.trackLength
|
||||||
? L.Util.formatNum(stats.cost / stats.trackLength, 2)
|
? L.Util.formatNum(
|
||||||
|
stats.cost / stats.trackLength,
|
||||||
|
2
|
||||||
|
).toLocaleString()
|
||||||
: '0',
|
: '0',
|
||||||
formattedTime = L.Util.formatNum(stats.totalTime / 60, 1),
|
formattedTime =
|
||||||
formattedEnergy = L.Util.formatNum(stats.totalEnergy / 3600000, 2),
|
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
|
meanEnergy = stats.trackLength
|
||||||
? L.Util.formatNum(
|
? L.Util.formatNum(
|
||||||
stats.totalEnergy / 36 / stats.trackLength,
|
stats.totalEnergy / 36 / stats.trackLength,
|
||||||
2
|
2
|
||||||
)
|
).toLocaleString()
|
||||||
: '0';
|
: '0';
|
||||||
|
|
||||||
$('#distance').html(length1);
|
$('#distance').html(length1);
|
||||||
// alternative 3-digit format down to meters as tooltip
|
// alternative 3-digit format down to meters as tooltip
|
||||||
$('#distance').attr('title', length3 + ' km');
|
$('#distance').attr('title', length3 + ' km');
|
||||||
$('#ascend').html(stats.filteredAscend);
|
$('#ascend').html(formattedAscend);
|
||||||
$('#plainascend').html(stats.plainAscend);
|
$('#plainascend').html(formattedPlainAscend);
|
||||||
$('#cost').html(stats.cost);
|
$('#cost').html(formattedCost);
|
||||||
$('#meancostfactor').html(meanCostFactor);
|
$('#meancostfactor').html(meanCostFactor);
|
||||||
$('#totaltime').html(formattedTime);
|
$('#totaltime').html(formattedTime);
|
||||||
$('#totalenergy').html(formattedEnergy);
|
$('#totalenergy').html(formattedEnergy);
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@
|
||||||
"kilowatthour-abbrev": "kWh",
|
"kilowatthour-abbrev": "kWh",
|
||||||
"meter": "meters",
|
"meter": "meters",
|
||||||
"meter-abbrev": "m",
|
"meter-abbrev": "m",
|
||||||
"minutes": "minutes",
|
"hours": "hours",
|
||||||
"minutes-abbrev": "min",
|
"hours-abbrev": "h",
|
||||||
"total-energy": "Total Energy",
|
"total-energy": "Total Energy",
|
||||||
"energy-per-100km": "Energy per 100 km",
|
"energy-per-100km": "Energy per 100 km",
|
||||||
"travel-time": "Travel time"
|
"travel-time": "Travel time"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue