Skip to content

Commit

Permalink
Merge pull request #159 from WhyAsh5114/chart-fixes
Browse files Browse the repository at this point in the history
Chart fixes
  • Loading branch information
WhyAsh5114 authored Dec 27, 2024
2 parents 7e69f3b + 33c51fa commit 526375d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 16 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@
"@trpc/server": "^10.45.2",
"bits-ui": "^0.22.0",
"chart.js": "^4.4.3",
"chartjs-adapter-date-fns": "^3.0.0",
"clsx": "^2.1.1",
"cmdk-sv": "^0.0.18",
"date-fns": "^4.1.0",
"dompurify": "^3.2.3",
"embla-carousel-svelte": "^8.3.0",
"marked": "^15.0.4",
Expand Down
5 changes: 4 additions & 1 deletion src/routes/(components)/layout/ChangelogDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
) {
open = true;
checkingForUpdate = true;
await checkForUpdates!();
while (checkForUpdates === null) {
await new Promise((resolve) => setTimeout(resolve, 500));
}
await checkForUpdates();
checkingForUpdate = false;
loadChangelog(changelogShownOf);
}
Expand Down
15 changes: 12 additions & 3 deletions src/routes/exercise-stats/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
let selectedExercise = $state<string>();
let exerciseInstances = $state<WorkoutExercise[]>();
let filteredExercisesByMuscleGroup = $derived(
exercisesByMuscleGroup
?.filter((g) => g.exercises.some((ex) => ex.name.toLowerCase().includes(searchText)))
.map(({ group, exercises }) => ({
group,
exercises: exercises.filter((ex) => ex.name.toLowerCase().includes(searchText))
})) ?? []
);
onMount(async () => {
const exerciseList = await data.exerciseList;
exercisesByMuscleGroup = Object.entries(
Expand Down Expand Up @@ -50,7 +59,7 @@
</Button>
</Popover.Trigger>
<Popover.Content sameWidth>
<Command.Root class="mb-6 h-fit">
<Command.Root class="mb-6 h-fit" shouldFilter={false}>
<Command.Input placeholder="Type here" bind:value={searchText} />
<Command.List>
{#if exercisesByMuscleGroup === undefined}
Expand All @@ -64,7 +73,7 @@
</Command.Loading>
{:else}
<Command.Empty>No results found.</Command.Empty>
{#each exercisesByMuscleGroup as { exercises, group }}
{#each filteredExercisesByMuscleGroup as { group, exercises }}
<Command.Group heading={group}>
{#each exercises as ex}
<Command.Item onclick={() => selectExercise(ex.name)}>{ex.name}</Command.Item>
Expand All @@ -82,7 +91,7 @@
<ExerciseStatsChart {selectedExercise} exercises={exerciseInstances} />
{#if exerciseInstances}
{#each exerciseInstances as instance}
<WorkoutExerciseCard exercise={instance} />
<WorkoutExerciseCard exercise={instance} date={new Date(instance.workout.startedAt)} />
{/each}
{/if}
{/if}
Expand Down
36 changes: 27 additions & 9 deletions src/routes/exercise-stats/ExerciseStatsChart.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script lang="ts">
import type { RouterOutputs } from '$lib/trpc/router';
import * as Card from '$lib/components/ui/card';
import * as Popover from '$lib/components/ui/popover';
import { Label } from '$lib/components/ui/label';
import * as Popover from '$lib/components/ui/popover';
import * as RadioGroup from '$lib/components/ui/radio-group';
import Separator from '$lib/components/ui/separator/separator.svelte';
import * as ToggleGroup from '$lib/components/ui/toggle-group';
import type { RouterOutputs } from '$lib/trpc/router';
import { generateShadesAndTints } from '$lib/utils';
import { solveBergerFormula } from '$lib/utils/workoutUtils';
import LoaderCircle from 'virtual:icons/lucide/loader-circle';
import MenuIcon from 'virtual:icons/lucide/menu';
import {
CategoryScale,
Chart,
Expand All @@ -17,11 +16,24 @@
LineController,
LineElement,
PointElement,
TimeScale,
Title,
Tooltip
} from 'chart.js';
import Separator from '$lib/components/ui/separator/separator.svelte';
Chart.register(Tooltip, CategoryScale, LineController, LineElement, PointElement, Filler, LinearScale, Title);
import 'chartjs-adapter-date-fns';
import LoaderCircle from 'virtual:icons/lucide/loader-circle';
import MenuIcon from 'virtual:icons/lucide/menu';
Chart.register(
Tooltip,
CategoryScale,
LineController,
LineElement,
PointElement,
Filler,
TimeScale,
Title,
LinearScale
);
type WorkoutExercise = RouterOutputs['workouts']['getExerciseHistory'][number];
type PropsType = { exercises: WorkoutExercise[] | undefined; selectedExercise: string };
Expand Down Expand Up @@ -79,9 +91,7 @@
chart = new Chart(chartCanvas, {
type: 'line',
data: {
labels: exercises.map((ex) =>
new Date(ex.workout.startedAt).toLocaleDateString(undefined, { day: '2-digit', month: '2-digit' })
),
labels: exercises.map((ex) => new Date(ex.workout.startedAt)),
datasets: dataValues.map((data, idx) => ({
label: `Set ${idx + 1}`,
data,
Expand All @@ -91,6 +101,14 @@
}))
},
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'day'
}
}
},
plugins: {
legend: {
display: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
exercise: Prisma.WorkoutExerciseGetPayload<{
include: { sets: { include: { miniSets: true } } };
}>;
date?: Date;
};
let { exercise }: PropsType = $props();
let { exercise, date }: PropsType = $props();
</script>

<div class="flex flex-col gap-0.5 rounded-md border bg-card/50 p-2 backdrop-blur-sm">
<div class="flex items-start justify-between">
<div class="flex items-center justify-between">
<span class="truncate">{exercise.name}</span>
{#if date}
<span class="text-sm text-muted-foreground">
{new Date(date).toLocaleDateString()}
</span>
{/if}
</div>
<div class="flex items-center gap-0.5">
<span class="mr-auto text-sm lowercase text-muted-foreground">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
})}
</span>
</div>
<WorkoutExerciseCard {exercise} />
<WorkoutExerciseCard {exercise} date={new Date(exercise.workout.startedAt)} />
{/each}
<DefaultInfiniteLoader {loadMore} identifier={workoutRunes.exerciseHistorySheetName} entityPlural="exercises" />
</div>
Expand Down

0 comments on commit 526375d

Please sign in to comment.