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
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue