Use "x | y" format instead "x (y)"
(The old format was a bit confusing, e.g. the second part of the label
could be mistaken for an "explanation" of the first part, while it
actually is an entirely separate label.)
Repeat unit for every metric.
Use plural for units.
Use "-" everywhere when a metric is not yet available instead of mixing
"-" and "0".
Properly revert to initial "-" when removing route instead of showing
"0".
Show "0" instead of "" when route length cannot be calculated yet.
Slightly change wording ("Energy per 100km").
72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
BR.TrackStats = L.Class.extend({
|
|
update: function(polyline, segments) {
|
|
if (segments.length == 0) {
|
|
$('#distance').html('-');
|
|
$('#distance').attr('title', '');
|
|
$('#ascend').html('-');
|
|
$('#plainascend').html('-');
|
|
$('#cost').html('-');
|
|
$('#meancostfactor').html('-');
|
|
$('#totaltime').html('-');
|
|
$('#totalenergy').html('-');
|
|
$('#meanenergy').html('-');
|
|
return;
|
|
}
|
|
|
|
var stats = this.calcStats(polyline, segments),
|
|
length1 = L.Util.formatNum(stats.trackLength / 1000, 1),
|
|
length3 = L.Util.formatNum(stats.trackLength / 1000, 3),
|
|
meanCostFactor = stats.trackLength
|
|
? L.Util.formatNum(stats.cost / stats.trackLength, 2)
|
|
: '0',
|
|
formattedTime = L.Util.formatNum(stats.totalTime / 60, 1),
|
|
formattedEnergy = L.Util.formatNum(stats.totalEnergy / 3600000, 2),
|
|
meanEnergy = stats.trackLength
|
|
? L.Util.formatNum(
|
|
stats.totalEnergy / 36 / stats.trackLength,
|
|
2
|
|
)
|
|
: '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);
|
|
$('#meancostfactor').html(meanCostFactor);
|
|
$('#totaltime').html(formattedTime);
|
|
$('#totalenergy').html(formattedEnergy);
|
|
$('#meanenergy').html(meanEnergy);
|
|
document.getElementById(
|
|
'totaltime'
|
|
).parentElement.parentElement.hidden = !stats.totalTime;
|
|
document.getElementById(
|
|
'totalenergy'
|
|
).parentElement.parentElement.hidden = !stats.totalEnergy;
|
|
},
|
|
|
|
calcStats: function(polyline, segments) {
|
|
var stats = {
|
|
trackLength: 0,
|
|
filteredAscend: 0,
|
|
plainAscend: 0,
|
|
totalTime: 0,
|
|
totalEnergy: 0,
|
|
cost: 0
|
|
};
|
|
var i, props;
|
|
|
|
for (i = 0; segments && i < segments.length; i++) {
|
|
props = segments[i].feature.properties;
|
|
stats.trackLength += +props['track-length'];
|
|
stats.filteredAscend += +props['filtered ascend'];
|
|
stats.plainAscend += +props['plain-ascend'];
|
|
stats.totalTime += +props['total-time'];
|
|
stats.totalEnergy += +props['total-energy'];
|
|
stats.cost += +props['cost'];
|
|
}
|
|
|
|
return stats;
|
|
}
|
|
});
|