anki/ts/graphs/FutureDue.svelte

66 lines
2.1 KiB
Svelte
Raw Normal View History

2020-06-26 11:25:02 +02:00
<script lang="typescript">
import { createEventDispatcher } from "svelte";
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;
import * as tr from "anki/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,
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 = tr.statisticsFutureDueTitle();
const subtitle = tr.statisticsFutureDueSubtitle();
const backlogLabel = tr.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 revlogRange={RevlogRange.All} />
</InputBox>
2020-06-26 11:25:02 +02:00
<HistogramGraph data={histogramData} />
2020-06-26 11:25:02 +02:00
<TableData {tableData} />
</Graph>