2020-06-22 11:11:50 +02:00
|
|
|
<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";
|
2020-06-22 11:11:50 +02:00
|
|
|
|
|
|
|
let data: 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;
|
2020-06-22 11:11:50 +02:00
|
|
|
let range: GraphRange = GraphRange.Month;
|
|
|
|
let days: number = 31;
|
|
|
|
|
2020-06-22 12:28:36 +02:00
|
|
|
let search = "deck:current";
|
2020-06-22 13:39:16 +02:00
|
|
|
let displayedSearch = search;
|
2020-06-22 12:28:36 +02:00
|
|
|
|
2020-06-22 11:11:50 +02:00
|
|
|
const refresh = async () => {
|
2020-06-22 12:28:36 +02:00
|
|
|
console.log(`search is ${search}`);
|
2020-06-22 11:11:50 +02:00
|
|
|
data = await getGraphData(search, days);
|
|
|
|
};
|
|
|
|
|
2020-06-22 13:39:16 +02:00
|
|
|
$: {
|
|
|
|
// refresh if either of these change
|
|
|
|
search;
|
|
|
|
days;
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2020-06-22 12:28:36 +02:00
|
|
|
$: {
|
|
|
|
switch (searchRange as SearchRange) {
|
|
|
|
case SearchRange.Deck:
|
2020-06-22 13:39:16 +02:00
|
|
|
search = displayedSearch = "deck:current";
|
2020-06-22 12:28:36 +02:00
|
|
|
break;
|
|
|
|
case SearchRange.Collection:
|
2020-06-22 13:39:16 +02:00
|
|
|
search = displayedSearch = "";
|
2020-06-22 12:28:36 +02:00
|
|
|
break;
|
|
|
|
case SearchRange.Custom:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 11:11:50 +02:00
|
|
|
$: {
|
2020-06-22 13:39:16 +02:00
|
|
|
switch (range as GraphRange) {
|
2020-06-22 11:11:50 +02:00
|
|
|
case GraphRange.Month:
|
|
|
|
days = 31;
|
|
|
|
break;
|
|
|
|
case GraphRange.Year:
|
|
|
|
days = 365;
|
|
|
|
break;
|
|
|
|
case GraphRange.All:
|
|
|
|
days = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 13:39:16 +02:00
|
|
|
const searchKeyUp = (e: KeyboardEvent) => {
|
|
|
|
// fetch data on enter
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
search = displayedSearch;
|
|
|
|
}
|
|
|
|
};
|
2020-06-22 11:11:50 +02:00
|
|
|
</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>
|
|
|
|
|
2020-06-22 13:39:16 +02:00
|
|
|
<input type="text" bind:value={displayedSearch} on:keyup={searchKeyUp} />
|
2020-06-22 12:28:36 +02:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="range-box">
|
|
|
|
Review history:
|
2020-06-22 11:11:50 +02:00
|
|
|
<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>
|
|
|
|
|
2020-06-24 01:41:07 +02:00
|
|
|
<AddedGraph {data} />
|
2020-06-22 11:11:50 +02:00
|
|
|
<IntervalsGraph {data} />
|
2020-06-23 12:43:19 +02:00
|
|
|
<EaseGraph {data} />
|