Files
gpx.studio/website/src/lib/components/GPXStatistics.svelte

93 lines
3.8 KiB
Svelte
Raw Normal View History

2024-04-19 16:13:08 +02:00
<script lang="ts">
import * as Card from '$lib/components/ui/card';
import Tooltip from '$lib/components/Tooltip.svelte';
import WithUnits from '$lib/components/WithUnits.svelte';
2024-04-19 16:13:08 +02:00
2025-06-21 21:07:36 +02:00
import { MoveDownRight, MoveUpRight, Ruler, Timer, Zap } from '@lucide/svelte';
2024-04-19 16:13:08 +02:00
2025-06-21 21:07:36 +02:00
import { i18n } from '$lib/i18n.svelte';
import type { GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
2025-10-18 00:31:14 +02:00
import type { Readable } from 'svelte/store';
import { settings } from '$lib/logic/settings';
2024-06-10 20:03:57 +02:00
const { velocityUnits } = settings;
2024-07-11 18:42:49 +02:00
2026-03-28 19:31:52 +01:00
let panelHeight: number = $state(0);
let panelWidth: number = $state(0);
2025-10-18 00:31:14 +02:00
let {
gpxStatistics,
slicedGPXStatistics,
orientation,
}: {
gpxStatistics: Readable<GPXStatisticsGroup>;
slicedGPXStatistics: Readable<[GPXGlobalStatistics, number, number] | undefined>;
2025-10-18 00:31:14 +02:00
orientation: 'horizontal' | 'vertical';
} = $props();
2024-06-10 20:03:57 +02:00
2025-10-18 00:31:14 +02:00
let statistics = $derived(
$slicedGPXStatistics !== undefined ? $slicedGPXStatistics[0] : $gpxStatistics.global
2025-10-18 00:31:14 +02:00
);
2024-04-19 16:13:08 +02:00
</script>
2024-06-09 17:22:41 +02:00
<Card.Root
class="h-full {orientation === 'vertical'
2026-02-17 22:24:14 +01:00
? 'min-w-40 sm:min-w-44'
2026-03-28 19:31:52 +01:00
: 'w-full h-fit my-1'} border-none shadow-none p-0 text-sm sm:text-base bg-transparent"
2024-06-09 17:22:41 +02:00
>
2026-03-28 19:31:52 +01:00
<Card.Content class="h-full p-0">
<div
bind:clientHeight={panelHeight}
bind:clientWidth={panelWidth}
class="flex {orientation === 'vertical'
? 'flex-col h-full justify-center'
: 'flex-row w-full justify-evenly'} gap-4"
>
<Tooltip label={i18n._('quantities.distance')}>
<span class="flex flex-row items-center">
2026-03-28 19:31:52 +01:00
<Ruler size="16" class="mr-1" />
<WithUnits value={statistics.distance.total} type="distance" />
</span>
</Tooltip>
2026-03-28 19:31:52 +01:00
<Tooltip label={i18n._('quantities.elevation_gain_loss')}>
<span class="flex flex-row items-center">
2026-03-28 19:31:52 +01:00
<MoveUpRight size="16" class="mr-1" />
<WithUnits value={statistics.elevation.gain} type="elevation" />
<MoveDownRight size="16" class="mx-1" />
<WithUnits value={statistics.elevation.loss} type="elevation" />
</span>
</Tooltip>
2026-03-28 19:31:52 +01:00
{#if panelHeight > 120 || (orientation === 'horizontal' && panelWidth > 450)}
<Tooltip
label="{$velocityUnits === 'speed'
? i18n._('quantities.speed')
: i18n._('quantities.pace')} ({i18n._('quantities.moving')} / {i18n._(
'quantities.total'
)})"
>
<span class="flex flex-row items-center">
<Zap size="16" class="mr-1" />
<WithUnits value={statistics.speed.moving} type="speed" showUnits={false} />
<span class="mx-1">/</span>
<WithUnits value={statistics.speed.total} type="speed" />
</span>
</Tooltip>
{/if}
{#if panelHeight > 160 || (orientation === 'horizontal' && panelWidth > 620)}
<Tooltip
label="{i18n._('quantities.time')} ({i18n._('quantities.moving')} / {i18n._(
'quantities.total'
)})"
>
<span class="flex flex-row items-center">
<Timer size="16" class="mr-1" />
<WithUnits value={statistics.time.moving} type="time" />
<span class="mx-1">/</span>
<WithUnits value={statistics.time.total} type="time" />
</span>
</Tooltip>
{/if}
</div>
</Card.Content>
2024-04-19 16:13:08 +02:00
</Card.Root>