Leaderboard: Use chart options generator function

This commit is contained in:
2025-06-07 22:44:24 +02:00
parent e4be7c4830
commit f049805124

View File

@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import { make_chart_options } from "$lib/chart";
import { Table, type TableColumn } from "$lib/components"; import { Table, type TableColumn } from "$lib/components";
import { get_by_value } from "$lib/database"; import { get_by_value } from "$lib/database";
import type { RacePickPoints, RacePickPointsAcc, User } from "$lib/schema"; import type { RacePickPoints, RacePickPointsAcc, User } from "$lib/schema";
@ -28,11 +29,13 @@
data_value_name: "user", data_value_name: "user",
label: "User", label: "User",
valuefun: async (value: string): Promise<string> => valuefun: async (value: string): Promise<string> =>
get_by_value(await data.users, "id", value)?.firstname ?? "Invalid", `<span class='badge variant-filled-surface'>${get_by_value(await data.users, "id", value)?.firstname ?? "Invalid"}</span>`,
}, },
{ {
data_value_name: "total_points", data_value_name: "total_points",
label: "Total", label: "Total",
valuefun: async (value: string): Promise<string> =>
`<span class='badge variant-filled-surface'>${value}</span>`,
}, },
{ {
data_value_name: "total_pxx_points", data_value_name: "total_pxx_points",
@ -71,85 +74,23 @@
); );
}); });
const points_chart_options: LineChartOptions = { const points_chart_options: LineChartOptions = make_chart_options(
title: "I ❤️ CumSum", "I ❤️ CumSum",
axes: { "step",
bottom: { "points",
mapsTo: "step", );
scaleType: ScaleTypes.LABELS,
},
left: {
mapsTo: "points",
scaleType: ScaleTypes.LINEAR,
},
},
curve: "curveMonotoneX",
// toolbar: {
// enabled: false,
// },
animations: true,
// canvasZoom: {
// enabled: false,
// },
grid: {
x: {
enabled: true,
alignWithAxisTicks: true,
},
y: {
enabled: true,
alignWithAxisTicks: true,
},
},
legend: {
enabled: true,
clickable: true,
position: "top",
},
points: {
enabled: true,
radius: 5,
},
tooltip: {
showTotal: false,
},
resizable: true,
width: "100%",
height: "400px",
};
</script> </script>
<svelte:head> <svelte:head>
<title>Formula 11 - Leaderboard</title> <title>Formula 11 - Leaderboard</title>
</svelte:head> </svelte:head>
{#await Promise.all( [data.users, data.racepickpoints, data.racepickpointsacc, data.racepickpointstotal], ) then [users, racepickpoints, racepickpointsacc, racepickpointstotal]} <div class="card w-full bg-surface-100 p-2 shadow">
<div class="flex gap-2"> <LineChart data={points_chart_data} options={points_chart_options} />
<!-- Podium --> </div>
<!-- <div class="card w-60 bg-surface-100 p-2 shadow"> -->
<!-- <div class="flex h-20 w-full gap-1"></div> -->
<!-- <div class="flex h-20 w-full gap-1"> -->
<!-- <div class="w-20"> -->
<!-- <div class="h-[30%] w-full"></div> -->
<!-- <div class="h-[70%] w-full bg-surface-500"></div> -->
<!-- </div> -->
<!-- <div class="w-20"> -->
<!-- <div class="h-[100%] w-full bg-surface-500"></div> -->
<!-- </div> -->
<!-- <div class="w-20"> -->
<!-- <div class="h-[60%] w-full"></div> -->
<!-- <div class="h-[40%] w-full bg-surface-600"></div> -->
<!-- </div> -->
<!-- </div> -->
<!-- </div> -->
<!-- Points chart --> <div class="mt-2">
<div class="card w-full bg-surface-100 p-2 shadow"> {#await data.racepickpointstotal then racepickpointstotal}
<LineChart data={points_chart_data} options={points_chart_options} />
</div>
</div>
<div class="mt-2">
<Table data={racepickpointstotal} columns={leaderboard_columns} /> <Table data={racepickpointstotal} columns={leaderboard_columns} />
</div> {/await}
{/await} </div>