c039845c16
This allows for tree shaking, and reduces the congrats page from 150k with the old enum solution to about 80k.
56 lines
1.7 KiB
Svelte
56 lines
1.7 KiB
Svelte
<script lang="typescript">
|
|
import type pb from "anki/backend_proto";
|
|
import { createEventDispatcher } from "svelte";
|
|
|
|
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 { RevlogRange, GraphRange } from "./graph-helpers";
|
|
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
|
import type { HistogramData } from "./histogram-graph";
|
|
import { gatherData, buildHistogram } from "./added";
|
|
import type { GraphData } from "./added";
|
|
import type { PreferenceStore } from "./preferences";
|
|
|
|
export let sourceData: pb.BackendProto.GraphsOut | null = null;
|
|
import * as tr from "anki/i18n";
|
|
export let preferences: PreferenceStore;
|
|
|
|
let histogramData = null as HistogramData | null;
|
|
let tableData: TableDatum[] = [];
|
|
let graphRange: GraphRange = GraphRange.Month;
|
|
let { browserLinksSupported } = preferences;
|
|
|
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
|
|
|
let addedData: GraphData | null = null;
|
|
$: if (sourceData) {
|
|
addedData = gatherData(sourceData);
|
|
}
|
|
|
|
$: if (addedData) {
|
|
[histogramData, tableData] = buildHistogram(
|
|
addedData,
|
|
graphRange,
|
|
dispatch,
|
|
$browserLinksSupported
|
|
);
|
|
}
|
|
|
|
const title = tr.statisticsAddedTitle();
|
|
const subtitle = tr.statisticsAddedSubtitle();
|
|
</script>
|
|
|
|
<Graph {title} {subtitle}>
|
|
<InputBox>
|
|
<GraphRangeRadios bind:graphRange revlogRange={RevlogRange.All} />
|
|
</InputBox>
|
|
|
|
<HistogramGraph data={histogramData} />
|
|
|
|
<TableData {tableData} />
|
|
</Graph>
|