From 7cb60303873807e3cc8c75287b74a16664a9c9c9 Mon Sep 17 00:00:00 2001 From: clerie Date: Mon, 7 Jul 2025 17:58:22 +0200 Subject: [PATCH] Sort legs by time --- web/drafting-board.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/web/drafting-board.js b/web/drafting-board.js index 22c3209..3ea04df 100644 --- a/web/drafting-board.js +++ b/web/drafting-board.js @@ -63,6 +63,36 @@ export function drawDraftingBoard() { return leg; }); + display_legs = display_legs.toSorted((leg_a, leg_b) => { + if (leg_a.origin_location_id == leg_b.origin_location_id) { + if (leg_a.origin_location.departure > leg_b.origin_location.departure) { + return 1; + } else { + return -1; + } + } else if (leg_a.destination_location_id == leg_b.destination_location_id) { + if (leg_a.destination_location.arrival > leg_b.destination_location.arrival) { + return 1; + } else { + return -1; + } + } else if (leg_a.destination_location_id == leg_b.origin_location_id) { + if (leg_a.destination_location.arrival > leg_b.origin_location.departure) { + return 1; + } else { + return -1; + } + } else if (leg_a.origin_location_id == leg_b.destination_location_id) { + if (leg_a.origin_location.departure > leg_b.destination_location.arrival) { + return 1; + } else { + return -1; + } + } else { + return 0; + } + }); + let rows = display_legs.length; element_board.style.setProperty("--drafting-board-number-locations", display_locations.length); @@ -161,6 +191,9 @@ export function getLocationWithLeastInboundTrips(locations, legs) { let n_a = numberOfInboundLegs(location_a); let n_b = numberOfInboundLegs(location_b); + // 1: b vor a + // -1: a vor b + if (n_a == n_b) { return 0; } else if (n_a > n_b) {