Anki/ts/routes/graphs/TrueRetentionCombined.svelte
Ross Brown 5637390b50
Make the "True Retention" table pretty (#3640)
* Make the True Retention table pretty

* Hide absolute pass/fail table for 'all'

* Run './ninja format'

* Manually run prettier on Svelte 5 components

* Refactor to not use {#snippet}

* Fix lint to pass check:eslint

* Fix lint to pass check:svelte

* Rename t9n -> tr to follow code style

* Replace hard-coded string with a translation string

* Use assertUnreachable(...) for exhaustively matching enum
2024-12-19 00:41:57 +11:00

101 lines
2.6 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import * as tr from "@generated/ftl";
import { localizedNumber } from "@tslib/i18n";
import { type RevlogRange } from "./graph-helpers";
import {
calculateRetentionPercentageString,
getRowData,
type PeriodTrueRetentionData,
type RowData,
} from "./true-retention";
interface Props {
revlogRange: RevlogRange;
data: PeriodTrueRetentionData;
}
const { revlogRange, data }: Props = $props();
const rowData: RowData[] = $derived(getRowData(data, revlogRange));
</script>
<table>
<thead>
<tr>
<td></td>
<th scope="col" class="col-header young">
{tr.statisticsCountsYoungCards()}
</th>
<th scope="col" class="col-header mature">
{tr.statisticsCountsMatureCards()}
</th>
<th scope="col" class="col-header total">
{tr.statisticsCountsTotalCards()}
</th>
<th scope="col" class="col-header count">
{tr.statisticsTrueRetentionCount()}
</th>
</tr>
</thead>
<tbody>
{#each rowData as row}
{@const totalPassed = row.data.youngPassed + row.data.maturePassed}
{@const totalFailed = row.data.youngFailed + row.data.matureFailed}
<tr>
<th scope="row" class="row-header">{row.title}</th>
<td class="young">
{calculateRetentionPercentageString(
row.data.youngPassed,
row.data.youngFailed,
)}
</td>
<td class="mature">
{calculateRetentionPercentageString(
row.data.maturePassed,
row.data.matureFailed,
)}
</td>
<td class="total">
{calculateRetentionPercentageString(totalPassed, totalFailed)}
</td>
<td class="count">{localizedNumber(totalPassed + totalFailed)}</td>
</tr>
{/each}
</tbody>
</table>
<style lang="scss">
@use "true-retention-base";
.young,
.mature,
.total,
.count {
text-align: right;
}
.young {
color: #64c476;
}
.mature {
color: #31a354;
}
.total {
color: var(--fg);
}
.count {
color: var(--fg-subtle);
}
</style>