anki/ts/src/stats/ReviewsGraph.svelte

94 lines
2.8 KiB
Svelte
Raw Normal View History

2020-06-27 04:35:13 +02:00
<script lang="typescript">
import { HistogramData, histogramGraph } from "./histogram-graph";
import AxisLabels from "./AxisLabels.svelte";
import AxisTicks from "./AxisTicks.svelte";
2020-06-27 07:35:34 +02:00
import { defaultGraphBounds, RevlogRange } from "./graphs";
2020-06-27 04:35:13 +02:00
import { GraphData, gatherData, renderReviews, ReviewRange } from "./reviews";
import pb from "../backend/proto";
2020-06-27 14:10:56 +02:00
import { timeSpan, MONTH, YEAR } from "../time";
import { I18n } from "../i18n";
2020-06-27 04:35:13 +02:00
export let sourceData: pb.BackendProto.GraphsOut | null = null;
2020-06-27 07:35:34 +02:00
export let revlogRange: RevlogRange = RevlogRange.Month;
2020-06-27 14:10:56 +02:00
export let i18n: I18n;
2020-06-27 04:35:13 +02:00
let graphData: GraphData | null = null;
let bounds = defaultGraphBounds();
let svg = null as HTMLElement | SVGElement | null;
2020-06-27 07:35:34 +02:00
let range: ReviewRange;
2020-06-27 04:35:13 +02:00
let showTime = false;
2020-06-27 07:35:34 +02:00
$: switch (revlogRange as RevlogRange) {
case RevlogRange.Month:
range = ReviewRange.Month;
break;
case RevlogRange.Year:
range = ReviewRange.Year;
break;
case RevlogRange.All:
range = ReviewRange.AllTime;
break;
}
2020-06-27 04:35:13 +02:00
const xText = "";
const yText = "Times pressed";
$: if (sourceData) {
console.log("gathering data");
graphData = gatherData(sourceData);
}
$: if (graphData) {
2020-06-27 13:10:17 +02:00
renderReviews(svg as SVGElement, bounds, graphData, range, showTime);
2020-06-27 04:35:13 +02:00
}
2020-06-27 14:10:56 +02:00
2020-06-28 06:21:31 +02:00
const title = i18n.tr(i18n.TR.STATISTICS_REVIEWS_TITLE);
2020-06-27 14:10:56 +02:00
const month = timeSpan(i18n, 1 * MONTH);
const month3 = timeSpan(i18n, 3 * MONTH);
const year = timeSpan(i18n, 1 * YEAR);
2020-06-27 04:35:13 +02:00
</script>
<div class="graph">
2020-06-28 06:21:31 +02:00
<h1>{title}</h1>
2020-06-27 04:35:13 +02:00
<div class="range-box-inner">
<label>
<input type="checkbox" bind:checked={showTime} />
Time
</label>
2020-06-27 07:35:34 +02:00
{#if revlogRange >= RevlogRange.Year}
<label>
<input type="radio" bind:group={range} value={ReviewRange.Month} />
2020-06-27 14:10:56 +02:00
{month}
2020-06-27 07:35:34 +02:00
</label>
<label>
<input type="radio" bind:group={range} value={ReviewRange.Quarter} />
2020-06-27 14:10:56 +02:00
{month3}
2020-06-27 07:35:34 +02:00
</label>
<label>
<input type="radio" bind:group={range} value={ReviewRange.Year} />
2020-06-27 14:10:56 +02:00
{year}
2020-06-27 07:35:34 +02:00
</label>
{/if}
{#if revlogRange === RevlogRange.All}
<label>
<input type="radio" bind:group={range} value={ReviewRange.AllTime} />
All time
</label>
{/if}
2020-06-27 04:35:13 +02:00
</div>
<svg bind:this={svg} viewBox={`0 0 ${bounds.width} ${bounds.height}`}>
{#each [4, 3, 2, 1, 0] as i}
<g class="bars{i}" />
{/each}
<path class="area" />
<g class="hoverzone" />
<AxisTicks {bounds} />
<AxisLabels {bounds} {xText} {yText} />
</svg>
</div>