anki/ts/graphs/FutureDue.svelte
Damien Elmes 7d8f19e6e4 merge in Henrik's TS/Svelte refactor with some changes
- The previous commits moved the majority of the remaining global css
into components; move the remaining @emotion/css references into
ticks.scss and the styling of the Graph.svelte. This is not as elegant
as the emotion solution, but builds a whole lot faster, and most of
our styling can be scoped to a component anyway.
- Leave the .html files in ts/ for now. AnkiMobile uses them, and
AnkiDroid likely will in the future too. In the long run we'll likely
move to loading the JS into an existing page instead of loading a
separate page, but at that point we can just exclude the .html file from
copy_files_into_group() without affecting other clients.

Closes #1074
2021-03-21 23:01:18 +10:00

67 lines
2.2 KiB
Svelte

<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";
import type { PreferenceStore } from "./preferences";
export let sourceData: pb.BackendProto.GraphsOut | null = null;
export let i18n: I18n;
export let preferences: PreferenceStore;
const dispatch = createEventDispatcher<SearchEventMap>();
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;
$: if (sourceData) {
graphData = gatherData(sourceData);
}
$: if (graphData) {
({ histogramData, tableData } = buildHistogram(
graphData,
graphRange,
$futureDueShowBacklog,
i18n,
dispatch,
$browserLinksSupported
));
}
const title = i18n.tr(i18n.TR.STATISTICS_FUTURE_DUE_TITLE);
const subtitle = i18n.tr(i18n.TR.STATISTICS_FUTURE_DUE_SUBTITLE);
const backlogLabel = i18n.tr(i18n.TR.STATISTICS_BACKLOG_CHECKBOX);
</script>
<Graph {title} {subtitle}>
<InputBox>
{#if graphData && graphData.haveBacklog}
<label>
<input type="checkbox" bind:checked={$futureDueShowBacklog} />
{backlogLabel}
</label>
{/if}
<GraphRangeRadios bind:graphRange {i18n} revlogRange={RevlogRange.All} />
</InputBox>
<HistogramGraph data={histogramData} {i18n} />
<TableData {i18n} {tableData} />
</Graph>