anki/ts/src/stats/GraphsPage.svelte

133 lines
3.5 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";
2020-06-26 11:25:02 +02:00
import FutureDue from "./FutureDue.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-26 07:34:21 +02:00
let refreshing = false;
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-26 07:34:21 +02:00
refreshing = true;
sourceData = await getGraphData(search, days);
2020-06-26 07:34:21 +02:00
refreshing = false;
};
$: {
// 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-26 07:34:21 +02:00
<div class="spin {refreshing ? 'active' : ''}"></div>
<div class="range-box-inner">
<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} />
</div>
<div class="range-box-inner">
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>
</div>
2020-06-26 07:34:21 +02:00
<div class="range-box-pad" />
2020-06-26 11:25:02 +02:00
<FutureDue {sourceData} />
<TodayStats {sourceData} />
<CardCounts {sourceData} />
<IntervalsGraph {sourceData} />
<EaseGraph {sourceData} />
<ButtonsGraph {sourceData} />
2020-06-26 06:05:58 +02:00
<HourGraph {sourceData} />
2020-06-26 11:25:02 +02:00
<AddedGraph {sourceData} />