2024-04-24 16:12:50 +02:00
|
|
|
<script lang="ts">
|
2024-05-04 15:10:30 +02:00
|
|
|
import { settings } from '$lib/db';
|
2024-04-24 16:12:50 +02:00
|
|
|
import {
|
|
|
|
celsiusToFahrenheit,
|
2024-08-26 03:51:05 -07:00
|
|
|
getConvertedDistance,
|
|
|
|
getConvertedElevation,
|
|
|
|
getConvertedVelocity,
|
|
|
|
getDistanceUnits,
|
|
|
|
getElevationUnits,
|
|
|
|
getVelocityUnits,
|
2024-04-24 16:12:50 +02:00
|
|
|
secondsToHHMMSS
|
|
|
|
} from '$lib/units';
|
|
|
|
|
|
|
|
import { _ } from 'svelte-i18n';
|
|
|
|
|
|
|
|
export let value: number;
|
|
|
|
export let type: 'distance' | 'elevation' | 'speed' | 'temperature' | 'time';
|
2024-04-24 18:02:35 +02:00
|
|
|
export let showUnits: boolean = true;
|
2024-06-11 19:08:46 +02:00
|
|
|
export let decimals: number | undefined = undefined;
|
2024-05-04 15:10:30 +02:00
|
|
|
|
|
|
|
const { distanceUnits, velocityUnits, temperatureUnits } = settings;
|
2024-04-24 16:12:50 +02:00
|
|
|
</script>
|
|
|
|
|
2024-05-13 19:43:10 +02:00
|
|
|
<span class={$$props.class}>
|
|
|
|
{#if type === 'distance'}
|
2024-08-26 03:51:05 -07:00
|
|
|
{getConvertedDistance(value, $distanceUnits).toFixed(decimals ?? 2)}
|
|
|
|
{showUnits ? getDistanceUnits($distanceUnits) : ''}
|
2024-05-13 19:43:10 +02:00
|
|
|
{:else if type === 'elevation'}
|
2024-08-26 03:51:05 -07:00
|
|
|
{getConvertedElevation(value, $distanceUnits).toFixed(decimals ?? 0)}
|
|
|
|
{showUnits ? getElevationUnits($distanceUnits) : ''}
|
2024-05-13 19:43:10 +02:00
|
|
|
{:else if type === 'speed'}
|
2024-08-26 03:51:05 -07:00
|
|
|
{#if $velocityUnits === 'speed'}
|
|
|
|
{getConvertedVelocity(value, $velocityUnits, $distanceUnits).toFixed(decimals ?? 2)}
|
|
|
|
{showUnits ? getVelocityUnits($velocityUnits, $distanceUnits) : ''}
|
2024-05-13 19:43:10 +02:00
|
|
|
{:else}
|
2024-08-26 03:51:05 -07:00
|
|
|
{secondsToHHMMSS(getConvertedVelocity(value, $velocityUnits, $distanceUnits))}
|
|
|
|
{showUnits ? getVelocityUnits($velocityUnits, $distanceUnits) : ''}
|
2024-05-13 19:43:10 +02:00
|
|
|
{/if}
|
|
|
|
{:else if type === 'temperature'}
|
|
|
|
{#if $temperatureUnits === 'celsius'}
|
|
|
|
{value} {showUnits ? $_('units.celsius') : ''}
|
|
|
|
{:else}
|
|
|
|
{celsiusToFahrenheit(value)} {showUnits ? $_('units.fahrenheit') : ''}
|
|
|
|
{/if}
|
|
|
|
{:else if type === 'time'}
|
|
|
|
{secondsToHHMMSS(value)}
|
2024-04-24 16:12:50 +02:00
|
|
|
{/if}
|
2024-05-13 19:43:10 +02:00
|
|
|
</span>
|