anki/ts/graphs/FutureDue.svelte

67 lines
2.2 KiB
Svelte
Raw Normal View History

2020-06-26 11:25:02 +02:00
<script lang="typescript">
import { createEventDispatcher } from "svelte";
import type { I18n } from "anki/i18n";
import type pb from "anki/backend_proto";
import Graph from "./Graph.svelte";
import InputBox from "./InputBox.svelte";
import HistogramGraph from "./HistogramGraph.svelte";
import GraphRangeRadios from "./GraphRangeRadios.svelte";
import TableData from "./TableData.svelte";
import type { HistogramData } from "./histogram-graph";
import { GraphRange, RevlogRange } from "./graph-helpers";
import type { TableDatum, SearchEventMap } from "./graph-helpers";
import { gatherData, buildHistogram } from "./future-due";
import type { GraphData } from "./future-due";
2021-01-25 17:36:04 +01:00
import type { PreferenceStore } from "./preferences";
2020-06-26 11:25:02 +02:00
export let sourceData: pb.BackendProto.GraphsOut | null = null;
2020-06-27 14:10:56 +02:00
export let i18n: I18n;
2021-01-25 17:36:04 +01:00
export let preferences: PreferenceStore;
2020-06-27 14:10:56 +02:00
const dispatch = createEventDispatcher<SearchEventMap>();
2020-06-26 11:25:02 +02:00
let graphData = null as GraphData | null;
let histogramData = null as HistogramData | null;
let tableData: TableDatum[] = [] as any;
let graphRange: GraphRange = GraphRange.Month;
let { browserLinksSupported, futureDueShowBacklog } = preferences;
2020-06-26 11:25:02 +02:00
$: if (sourceData) {
graphData = gatherData(sourceData);
}
$: if (graphData) {
({ histogramData, tableData } = buildHistogram(
graphData,
graphRange,
$futureDueShowBacklog,
i18n,
dispatch,
2021-01-25 17:36:04 +01:00
$browserLinksSupported
));
2020-06-26 11:25:02 +02:00
}
2020-06-27 14:10:56 +02:00
const title = i18n.statisticsFutureDueTitle();
const subtitle = i18n.statisticsFutureDueSubtitle();
const backlogLabel = i18n.statisticsBacklogCheckbox();
2020-06-26 11:25:02 +02:00
</script>
<Graph {title} {subtitle}>
<InputBox>
{#if graphData && graphData.haveBacklog}
<label>
<input type="checkbox" bind:checked={$futureDueShowBacklog} />
{backlogLabel}
</label>
{/if}
2020-06-26 11:25:02 +02:00
<GraphRangeRadios bind:graphRange {i18n} revlogRange={RevlogRange.All} />
</InputBox>
2020-06-26 11:25:02 +02:00
2021-01-25 17:36:04 +01:00
<HistogramGraph data={histogramData} {i18n} />
2020-06-26 11:25:02 +02:00
<TableData {i18n} {tableData} />
</Graph>