2020-06-30 07:09:20 +02:00
|
|
|
<script lang="typescript">
|
2021-01-18 01:24:32 +01:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2020-07-06 06:01:49 +02:00
|
|
|
import NoDataOverlay from "./NoDataOverlay.svelte";
|
2020-06-30 07:09:20 +02:00
|
|
|
import AxisTicks from "./AxisTicks.svelte";
|
2020-11-01 05:26:58 +01:00
|
|
|
import { defaultGraphBounds, RevlogRange } from "./graph-helpers";
|
2021-01-26 12:41:22 +01:00
|
|
|
import type { SearchEventMap } from "./graph-helpers";
|
2020-11-01 05:26:58 +01:00
|
|
|
import { gatherData, renderCalendar } from "./calendar";
|
2021-01-22 19:02:05 +01:00
|
|
|
import type { PreferenceStore } from "./preferences";
|
2020-11-01 05:26:58 +01:00
|
|
|
import type { GraphData } from "./calendar";
|
2020-11-05 02:01:30 +01:00
|
|
|
import type pb from "anki/backend_proto";
|
|
|
|
import type { I18n } from "anki/i18n";
|
2020-06-30 07:09:20 +02:00
|
|
|
|
|
|
|
export let sourceData: pb.BackendProto.GraphsOut | null = null;
|
2021-01-22 19:02:05 +01:00
|
|
|
export let preferences: PreferenceStore | null = null;
|
2020-07-06 10:29:35 +02:00
|
|
|
export let revlogRange: RevlogRange;
|
2020-06-30 07:09:20 +02:00
|
|
|
export let i18n: I18n;
|
2020-06-30 08:23:46 +02:00
|
|
|
export let nightMode: boolean;
|
2020-06-30 07:09:20 +02:00
|
|
|
|
2021-01-22 14:56:41 +01:00
|
|
|
let { calendarFirstDayOfWeek } = preferences;
|
2021-01-26 12:41:22 +01:00
|
|
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
2021-01-18 01:24:32 +01:00
|
|
|
|
2020-06-30 07:09:20 +02:00
|
|
|
let graphData: GraphData | null = null;
|
|
|
|
|
|
|
|
let bounds = defaultGraphBounds();
|
|
|
|
bounds.height = 120;
|
|
|
|
bounds.marginLeft = 20;
|
|
|
|
bounds.marginRight = 20;
|
|
|
|
|
|
|
|
let svg = null as HTMLElement | SVGElement | null;
|
|
|
|
let maxYear = new Date().getFullYear();
|
2020-07-22 06:11:22 +02:00
|
|
|
let minYear = 0;
|
2020-06-30 07:09:20 +02:00
|
|
|
let targetYear = maxYear;
|
|
|
|
|
|
|
|
$: if (sourceData) {
|
2021-01-22 14:56:41 +01:00
|
|
|
graphData = gatherData(sourceData, $calendarFirstDayOfWeek);
|
2020-06-30 07:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$: {
|
|
|
|
if (revlogRange < RevlogRange.Year) {
|
|
|
|
minYear = maxYear;
|
|
|
|
} else if ((revlogRange as RevlogRange) === RevlogRange.Year) {
|
|
|
|
minYear = maxYear - 1;
|
|
|
|
} else {
|
|
|
|
minYear = 2000;
|
|
|
|
}
|
|
|
|
if (targetYear < minYear) {
|
|
|
|
targetYear = minYear;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$: if (graphData) {
|
2020-06-30 08:23:46 +02:00
|
|
|
renderCalendar(
|
|
|
|
svg as SVGElement,
|
|
|
|
bounds,
|
|
|
|
graphData,
|
2021-01-18 01:24:32 +01:00
|
|
|
dispatch,
|
2020-06-30 08:23:46 +02:00
|
|
|
targetYear,
|
|
|
|
i18n,
|
2020-08-21 05:41:34 +02:00
|
|
|
nightMode,
|
2021-01-22 17:51:15 +01:00
|
|
|
revlogRange,
|
2021-01-22 18:03:58 +01:00
|
|
|
calendarFirstDayOfWeek.set
|
|
|
|
);
|
2020-06-30 07:09:20 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 09:07:03 +02:00
|
|
|
const title = i18n.tr(i18n.TR.STATISTICS_CALENDAR_TITLE);
|
2020-06-30 07:09:20 +02:00
|
|
|
</script>
|
|
|
|
|
2020-07-16 20:44:21 +02:00
|
|
|
<div class="graph" id="graph-calendar">
|
2020-06-30 07:09:20 +02:00
|
|
|
<h1>{title}</h1>
|
|
|
|
|
|
|
|
<div class="range-box-inner">
|
|
|
|
<span>
|
|
|
|
<button on:click={() => targetYear--} disabled={minYear >= targetYear}>
|
|
|
|
◄
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<span>{targetYear}</span>
|
|
|
|
<span>
|
|
|
|
<button on:click={() => targetYear++} disabled={targetYear >= maxYear}>
|
|
|
|
►
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<svg bind:this={svg} viewBox={`0 0 ${bounds.width} ${bounds.height}`}>
|
2021-01-20 21:17:36 +01:00
|
|
|
<g class="weekdays" />
|
2020-06-30 07:09:20 +02:00
|
|
|
<g class="days" />
|
|
|
|
<AxisTicks {bounds} />
|
2020-07-06 06:01:49 +02:00
|
|
|
<NoDataOverlay {bounds} {i18n} />
|
2020-06-30 07:09:20 +02:00
|
|
|
</svg>
|
|
|
|
</div>
|