Skip to content

Commit

Permalink
PB-792: Change rounding and decimal places threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJoss committed Jul 16, 2024
1 parent 572c38f commit 82e91fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/modules/infobox/components/FeatureAreaInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ const humanReadableArea = computed(() => {
const calculatedArea = area(transformIntoTurfEquivalent(geometryWgs84.value))
let result = ''
if (calculatedArea) {
result += roundValueIfGreaterThan(calculatedArea, 1000, 1000000)
if (calculatedArea > 10000) {
const unitThreshold = 1e5
const divider = 1e6
const precision = 5
const value = calculatedArea < unitThreshold ? calculatedArea : calculatedArea / divider
result += parseFloat(value.toPrecision(precision))
if (calculatedArea >= unitThreshold) {
result += ' km'
} else {
result += ' m'
}
}
return result
})
function roundValueIfGreaterThan(value, threshold, divider) {
if (value > threshold) {
return `${round(value / divider, 2)}`
}
return `${round(value, 2)}`
}
</script>
<template>
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/tests-e2e/drawing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ describe('Drawing module tests', () => {
})
cy.get('[data-cy="feature-area-information"]')
.should('be.visible')
.contains('187.22 km')
.contains('187.224 km')

// Changing the color of the polygon and checking that the KMl was updated accordingly
cy.get('[data-cy="drawing-style-line-button"]').click()
Expand Down

0 comments on commit 82e91fc

Please sign in to comment.