30bbbaf00b
* Make eslint sort our imports * fix missing deps in eslint rule (dae) Caught on Linux due to the stricter sandboxing * Remove exports-last eslint rule (for now?) * Adjust browserslist settings - We use ResizeObserver which is not supported in browsers like KaiOS, Baidu or Android UC * Raise minimum iOS version 13.4 - It's the first version that supports ResizeObserver * Apply new eslint rules to sort imports
95 lines
2.7 KiB
Svelte
95 lines
2.7 KiB
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script lang="ts">
|
|
import { createEventDispatcher } from "svelte";
|
|
|
|
import * as tr from "../lib/ftl";
|
|
import type { Stats } from "../lib/proto";
|
|
import type { PreferenceStore } from "../sveltelib/preferences";
|
|
import AxisTicks from "./AxisTicks.svelte";
|
|
import type { GraphData } from "./calendar";
|
|
import { gatherData, renderCalendar } from "./calendar";
|
|
import Graph from "./Graph.svelte";
|
|
import type { SearchEventMap } from "./graph-helpers";
|
|
import { defaultGraphBounds, RevlogRange } from "./graph-helpers";
|
|
import InputBox from "./InputBox.svelte";
|
|
import NoDataOverlay from "./NoDataOverlay.svelte";
|
|
|
|
export let sourceData: Stats.GraphsResponse;
|
|
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
|
export let revlogRange: RevlogRange;
|
|
export let nightMode: boolean;
|
|
|
|
const { calendarFirstDayOfWeek } = preferences;
|
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
|
|
|
let graphData: GraphData | null = null;
|
|
|
|
const bounds = defaultGraphBounds();
|
|
bounds.height = 120;
|
|
bounds.marginLeft = 20;
|
|
bounds.marginRight = 20;
|
|
|
|
let svg = null as HTMLElement | SVGElement | null;
|
|
const maxYear = new Date().getFullYear();
|
|
let minYear = 0;
|
|
let targetYear = maxYear;
|
|
|
|
$: if (sourceData) {
|
|
graphData = gatherData(sourceData, $calendarFirstDayOfWeek);
|
|
}
|
|
|
|
$: {
|
|
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) {
|
|
renderCalendar(
|
|
svg as SVGElement,
|
|
bounds,
|
|
graphData,
|
|
dispatch,
|
|
targetYear,
|
|
nightMode,
|
|
revlogRange,
|
|
calendarFirstDayOfWeek.set,
|
|
);
|
|
}
|
|
|
|
const title = tr.statisticsCalendarTitle();
|
|
</script>
|
|
|
|
<Graph {title}>
|
|
<InputBox>
|
|
<span>
|
|
<button on:click={() => targetYear--} disabled={minYear >= targetYear}>
|
|
◄
|
|
</button>
|
|
</span>
|
|
<span>{targetYear}</span>
|
|
<span>
|
|
<button on:click={() => targetYear++} disabled={targetYear >= maxYear}>
|
|
►
|
|
</button>
|
|
</span>
|
|
</InputBox>
|
|
|
|
<svg bind:this={svg} viewBox={`0 0 ${bounds.width} ${bounds.height}`}>
|
|
<g class="weekdays" />
|
|
<g class="days" />
|
|
<AxisTicks {bounds} />
|
|
<NoDataOverlay {bounds} />
|
|
</svg>
|
|
</Graph>
|