anki/ts/src/stats/GraphsPage.svelte

122 lines
3.1 KiB
Svelte
Raw Normal View History

<script context="module">
import style from "./graphs.css";
document.head.append(style);
</script>
<script lang="typescript">
import { assertUnreachable } from "../typing";
import pb from "../backend/proto";
import { getGraphData, GraphRange } from "./graphs";
import IntervalsGraph from "./IntervalsGraph.svelte";
2020-06-23 12:43:19 +02:00
import EaseGraph from "./EaseGraph.svelte";
2020-06-24 01:41:07 +02:00
import AddedGraph from "./AddedGraph.svelte";
import TodayStats from "./TodayStats.svelte";
import ButtonsGraph from "./ButtonsGraph.svelte";
import CardCounts from "./CardCounts.svelte";
2020-06-26 06:05:58 +02:00
import HourGraph from "./HourGraph.svelte";
let sourceData: pb.BackendProto.GraphsOut | null = null;
2020-06-22 12:28:36 +02:00
enum SearchRange {
Deck = 1,
Collection = 2,
Custom = 3,
}
let searchRange: SearchRange = SearchRange.Deck;
let range: GraphRange = GraphRange.Month;
let days: number = 31;
2020-06-22 12:28:36 +02:00
let search = "deck:current";
let displayedSearch = search;
2020-06-22 12:28:36 +02:00
const refresh = async () => {
2020-06-22 12:28:36 +02:00
console.log(`search is ${search}`);
sourceData = await getGraphData(search, days);
};
$: {
// refresh if either of these change
search;
days;
refresh();
}
2020-06-22 12:28:36 +02:00
$: {
switch (searchRange as SearchRange) {
case SearchRange.Deck:
search = displayedSearch = "deck:current";
2020-06-22 12:28:36 +02:00
break;
case SearchRange.Collection:
search = displayedSearch = "";
2020-06-22 12:28:36 +02:00
break;
case SearchRange.Custom:
break;
}
}
$: {
switch (range as GraphRange) {
case GraphRange.Month:
days = 31;
break;
case GraphRange.Year:
days = 365;
break;
case GraphRange.All:
days = 0;
break;
}
}
const searchKeyUp = (e: KeyboardEvent) => {
// fetch data on enter
if (e.keyCode == 13) {
search = displayedSearch;
}
};
</script>
<div class="range-box">
2020-06-22 12:28:36 +02:00
<label>
<input type="radio" bind:group={searchRange} value={SearchRange.Deck} />
Deck
</label>
<label>
<input type="radio" bind:group={searchRange} value={SearchRange.Collection} />
Collection
</label>
<label>
<input type="radio" bind:group={searchRange} value={SearchRange.Custom} />
Custom
</label>
<input type="text" bind:value={displayedSearch} on:keyup={searchKeyUp} />
2020-06-22 12:28:36 +02:00
</div>
<div class="range-box">
Review history:
<label>
<input type="radio" bind:group={range} value={GraphRange.Month} />
Month
</label>
<label>
<input type="radio" bind:group={range} value={GraphRange.Year} />
Year
</label>
<label>
<input type="radio" bind:group={range} value={GraphRange.All} />
All
</label>
</div>
<TodayStats {sourceData} />
<CardCounts {sourceData} />
<AddedGraph {sourceData} />
<IntervalsGraph {sourceData} />
<EaseGraph {sourceData} />
<ButtonsGraph {sourceData} />
2020-06-26 06:05:58 +02:00
<HourGraph {sourceData} />