anki/ts/src/stats/HourGraph.svelte

45 lines
1.4 KiB
Svelte
Raw Normal View History

2020-06-26 06:05:58 +02:00
<script lang="typescript">
import { timeSpan, MONTH, YEAR } from "../time";
import { defaultGraphBounds, RevlogRange, GraphRange } from "./graphs";
2020-06-26 06:05:58 +02:00
import AxisTicks from "./AxisTicks.svelte";
import { renderHours } from "./hours";
2020-06-26 06:05:58 +02:00
import pb from "../backend/proto";
2020-06-28 06:21:31 +02:00
import { I18n } from "../i18n";
2020-07-06 06:01:49 +02:00
import NoDataOverlay from "./NoDataOverlay.svelte";
import GraphRangeRadios from "./GraphRangeRadios.svelte";
2020-06-26 06:05:58 +02:00
export let sourceData: pb.BackendProto.GraphsOut | null = null;
2020-06-28 06:21:31 +02:00
export let i18n: I18n;
export let revlogRange: RevlogRange;
let graphRange: GraphRange = GraphRange.Year;
2020-06-26 06:05:58 +02:00
const bounds = defaultGraphBounds();
let svg = null as HTMLElement | SVGElement | null;
$: if (sourceData) {
renderHours(svg as SVGElement, bounds, sourceData, i18n, graphRange);
2020-06-26 06:05:58 +02:00
}
2020-06-28 06:21:31 +02:00
const title = i18n.tr(i18n.TR.STATISTICS_HOURS_TITLE);
const subtitle = i18n.tr(i18n.TR.STATISTICS_HOURS_SUBTITLE);
2020-06-26 06:05:58 +02:00
</script>
<div class="graph" id="graph-hour">
2020-06-28 06:21:31 +02:00
<h1>{title}</h1>
2020-06-26 06:05:58 +02:00
<div class="range-box-inner">
<GraphRangeRadios bind:graphRange {i18n} {revlogRange} />
</div>
<div class="subtitle">{subtitle}</div>
2020-06-26 06:05:58 +02:00
<svg bind:this={svg} viewBox={`0 0 ${bounds.width} ${bounds.height}`}>
<g class="bars" />
2020-06-27 04:35:13 +02:00
<path class="area" />
2020-06-26 06:05:58 +02:00
<g class="hoverzone" />
<AxisTicks {bounds} />
2020-07-06 06:01:49 +02:00
<NoDataOverlay {bounds} {i18n} />
2020-06-26 06:05:58 +02:00
</svg>
</div>