2020-06-30 07:09:20 +02:00
|
|
|
<script lang="typescript">
|
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";
|
|
|
|
import { defaultGraphBounds, RevlogRange } from "./graphs";
|
2020-07-06 06:01:49 +02:00
|
|
|
import { GraphData, gatherData, renderCalendar } from "./calendar";
|
2020-06-30 07:09:20 +02:00
|
|
|
import pb from "../backend/proto";
|
|
|
|
import { timeSpan, MONTH, YEAR } from "../time";
|
|
|
|
import { I18n } from "../i18n";
|
|
|
|
|
|
|
|
export let sourceData: pb.BackendProto.GraphsOut | 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
|
|
|
|
|
|
|
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();
|
|
|
|
let minYear;
|
|
|
|
let targetYear = maxYear;
|
|
|
|
|
|
|
|
$: if (sourceData) {
|
|
|
|
graphData = gatherData(sourceData);
|
|
|
|
}
|
|
|
|
|
|
|
|
$: {
|
|
|
|
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,
|
|
|
|
targetYear,
|
|
|
|
i18n,
|
|
|
|
nightMode
|
|
|
|
);
|
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}`}>
|
|
|
|
<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>
|