From d495963358316cb4726d6b80736cf938b06763d8 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Thu, 15 Aug 2024 15:54:39 +0200 Subject: [PATCH] fix: display extra amount above 100% the total value of all amounts for the extra sections can be above 100. To mitigate the extra bars overflowing to the next line, the surplus is deducted from the largest extra amount. --- .../components/route-details/route-details.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/fragments/forms/map-form/components/place-and-directions/components/route-details/route-details.js b/src/fragments/forms/map-form/components/place-and-directions/components/route-details/route-details.js index e0d76637a..cc2d34d24 100644 --- a/src/fragments/forms/map-form/components/place-and-directions/components/route-details/route-details.js +++ b/src/fragments/forms/map-form/components/place-and-directions/components/route-details/route-details.js @@ -76,6 +76,18 @@ export default { // Heal stuff ends route.summary = context.getHumanizedSummary(route.summary, unit) route.summary.humanized = true + for (let item of Object.values(route.properties.extras)) { + // frontend fix for wrong total amount see https://github.com/GIScience/openrouteservice/issues/1455 + const total_amount = item.summary.reduce((a, b) => a + b.amount, 0) + if (total_amount > 100) { + const surplus = total_amount - 100 + // deduct from largest segment + const idxOfLargest = item.summary.reduce( + (maxIndex, curObj, curIndex, array) => { + return curObj.amount > array[maxIndex].amount ? curIndex : maxIndex + }, 0) + item.summary[idxOfLargest].amount -= surplus + }} context.parseSegments(route.properties.segments) this.localMapViewData.routes[key].summary = route.summary }