feat: routes overview - fix distanceScale value

This commit is contained in:
Azgaar 2024-08-01 13:36:14 +02:00
parent 28bc6ccde6
commit 834d6f6cc7
17 changed files with 328 additions and 130 deletions

View file

@ -29,12 +29,11 @@ function overviewRoutes() {
function routesOverviewAddLines() {
body.innerHTML = "";
let lines = "";
const unit = distanceUnitInput.value;
for (const route of pack.routes) {
route.name = route.name || Routes.generateName(route);
route.length = route.length || getRouteLength(route.i);
const length = rn(route.length * distanceScale) + " " + unit;
route.length = route.length || Routes.getLength(route.i);
const length = rn(route.length * distanceScale) + " " + distanceUnitInput.value;
lines += /* html */ `<div
class="states"
@ -56,7 +55,7 @@ function overviewRoutes() {
// update footer
routesFooterNumber.innerHTML = pack.routes.length;
const averageLength = rn(d3.mean(pack.routes.map(r => r.length)));
routesFooterLength.innerHTML = averageLength * distanceScale + " " + unit;
routesFooterLength.innerHTML = averageLength * distanceScale + " " + distanceUnitInput.value;
// add listeners
body.querySelectorAll("div.states").forEach(el => el.on("mouseenter", routeHighlightOn));
@ -68,11 +67,6 @@ function overviewRoutes() {
applySorting(routesHeader);
}
function getRouteLength(routeId) {
const path = routes.select("#route" + routeId).node();
return rn(path.getTotalLength() / 2, 2);
}
function routeHighlightOn(event) {
if (!layerIsOn("toggleRoutes")) toggleRoutes();
const routeId = +event.target.dataset.id;