Skip to content

Commit

Permalink
fix: display extra amount above 100%
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheGreatRefrigerator committed Aug 21, 2024
1 parent 48c25f0 commit 8fb1ff6
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8fb1ff6

Please sign in to comment.