Skip to content

Commit 62b4c6c

Browse files
committed
From Feedback: Truncating to max 3 decimals, space before meter unit
1 parent 80e5251 commit 62b4c6c

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

packages/web-forms/src/components/controls/GeopointFormattedValue.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
GeopointNoteValue,
77
} from '@getodk/xforms-engine';
88
import { computed } from 'vue';
9+
import { truncateDecimals } from '@/lib/format/truncateDecimals.ts';
910
1011
type GeopointNode = GeopointInputNode | GeopointNoteNode;
1112
@@ -25,7 +26,7 @@ const value = computed<GeopointValue>(() => {
2526
<template>
2627
<!-- TODO: translations -->
2728
<p class="geopoint-formatted-value">
28-
<span v-if="value?.accuracy != null">Accuracy: {{ value.accuracy }}m</span>
29+
<span v-if="value?.accuracy != null">Accuracy: {{ truncateDecimals(value.accuracy) }} m</span>
2930
<span v-if="value?.latitude != null">Latitude: {{ value.latitude }}</span>
3031
<span v-if="value?.longitude != null">Longitude: {{ value.longitude }}</span>
3132
</p>

packages/web-forms/src/components/controls/Input/Geopoint/GeolocationRequestDialog.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { computed, onBeforeUnmount, ref, watchEffect } from 'vue';
33
import Button from 'primevue/button';
44
import PrimeDialog from 'primevue/dialog';
55
import PrimeProgressSpinner from 'primevue/progressspinner';
6+
import { truncateDecimals } from '@/lib/format/truncateDecimals.ts';
67
import ElapsedTime from '@/components/ElapsedTime.vue';
78
import {
89
GEOLOCATION_STATUS,
@@ -163,14 +164,14 @@ onBeforeUnmount(cleanup);
163164
<div class="geopoint-information">
164165
<!-- TODO: translations -->
165166
<strong v-if="accuracy.value != null" class="geo-quality">
166-
{{ accuracy.value }}m - {{ accuracy.label }}
167+
{{ truncateDecimals(accuracy.value) }} m - {{ accuracy.label }}
167168
</strong>
168169
<p v-if="options.accuracyThreshold > 0 && state.geopoint == null">
169-
Location will be saved at {{ options.accuracyThreshold }}m
170+
Location will be saved at {{ options.accuracyThreshold }} m
170171
</p>
171172
<p>Time taken to capture location: <ElapsedTime /></p>
172173
<p v-if="previousAccuracy.value">
173-
Previous saved location at {{ previousAccuracy.value }}m
174+
Previous saved location at {{ truncateDecimals(previousAccuracy.value) }} m
174175
</p>
175176
</div>
176177
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const truncateDecimals = (num: number, decimals = 3): string => {
2+
if (
3+
typeof num !== 'number' ||
4+
Number.isNaN(num) ||
5+
typeof decimals !== 'number' ||
6+
Number.isNaN(decimals)
7+
) {
8+
return '';
9+
}
10+
11+
if (Number.isInteger(num) || decimals <= 0) {
12+
return num.toString();
13+
}
14+
15+
const factor = Math.pow(10, decimals);
16+
const withDecimals = Math.floor(Math.abs(num) * factor) / factor;
17+
return (num < 0 ? -withDecimals : withDecimals).toString();
18+
};

0 commit comments

Comments
 (0)