anki/ts/src/stats/CardCounts.svelte

46 lines
1.1 KiB
Svelte
Raw Normal View History

<script lang="typescript">
2020-07-04 05:38:46 +02:00
import { defaultGraphBounds } from "./graphs";
import { gatherData, GraphData, renderCards } from "./card-counts";
import pb from "../backend/proto";
2020-06-27 13:10:17 +02:00
import { I18n } from "../i18n";
2020-07-06 06:01:49 +02:00
export let sourceData: pb.BackendProto.GraphsOut;
2020-06-27 13:10:17 +02:00
export let i18n: I18n;
2020-07-04 05:38:46 +02:00
let svg = null as HTMLElement | SVGElement | null;
let bounds = defaultGraphBounds();
bounds.height = 20;
bounds.marginLeft = 20;
bounds.marginRight = 20;
bounds.marginTop = 0;
2020-07-06 06:01:49 +02:00
let graphData: GraphData;
$: {
2020-07-04 05:38:46 +02:00
graphData = gatherData(sourceData, i18n);
renderCards(svg as any, bounds, graphData);
2020-06-27 13:10:17 +02:00
}
2020-07-04 05:38:46 +02:00
const total = i18n.tr(i18n.TR.STATISTICS_COUNTS_TOTAL_CARDS);
</script>
2020-07-06 06:01:49 +02:00
<style>
svg {
transition: opacity 1s;
}
</style>
<div class="graph">
<h1>{graphData.title}</h1>
2020-07-04 05:38:46 +02:00
2020-07-06 06:01:49 +02:00
<svg
bind:this={svg}
viewBox={`0 0 ${bounds.width} ${bounds.height}`}
style="opacity: {graphData.totalCards ? 1 : 0}">
<g class="days" />
</svg>
2020-07-04 05:38:46 +02:00
2020-07-06 06:01:49 +02:00
<div class="centered">{total}: {graphData.totalCards}</div>
2020-07-04 05:38:46 +02:00
2020-07-06 06:01:49 +02:00
</div>