mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
don't fill in blanks outside of year range
This commit is contained in:
parent
d24f34c238
commit
2b1bcda937
2 changed files with 11 additions and 3 deletions
|
@ -47,7 +47,8 @@
|
||||||
graphData,
|
graphData,
|
||||||
targetYear,
|
targetYear,
|
||||||
i18n,
|
i18n,
|
||||||
nightMode
|
nightMode,
|
||||||
|
revlogRange,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import "d3-transition";
|
||||||
import { select, mouse } from "d3-selection";
|
import { select, mouse } from "d3-selection";
|
||||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
import { scaleLinear, scaleSequential } from "d3-scale";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import { GraphBounds, setDataAvailable } from "./graphs";
|
import { GraphBounds, setDataAvailable, RevlogRange } from "./graphs";
|
||||||
import { timeDay, timeYear, timeWeek } from "d3-time";
|
import { timeDay, timeYear, timeWeek } from "d3-time";
|
||||||
import { I18n } from "../i18n";
|
import { I18n } from "../i18n";
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ export function renderCalendar(
|
||||||
sourceData: GraphData,
|
sourceData: GraphData,
|
||||||
targetYear: number,
|
targetYear: number,
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
nightMode: boolean
|
nightMode: boolean,
|
||||||
|
revlogRange: RevlogRange
|
||||||
): void {
|
): void {
|
||||||
const svg = select(svgElem);
|
const svg = select(svgElem);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
@ -90,12 +91,18 @@ export function renderCalendar(
|
||||||
|
|
||||||
// fill in any blanks
|
// fill in any blanks
|
||||||
const startDate = timeYear(nowForYear);
|
const startDate = timeYear(nowForYear);
|
||||||
|
const oneYearAgoFromNow = new Date(now);
|
||||||
|
oneYearAgoFromNow.setFullYear(now.getFullYear() - 1);
|
||||||
for (let i = 0; i < 365; i++) {
|
for (let i = 0; i < 365; i++) {
|
||||||
const date = new Date(startDate.getTime() + i * 86400 * 1000);
|
const date = new Date(startDate.getTime() + i * 86400 * 1000);
|
||||||
if (date > now) {
|
if (date > now) {
|
||||||
// don't fill out future dates
|
// don't fill out future dates
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (revlogRange == RevlogRange.Year && date < oneYearAgoFromNow) {
|
||||||
|
// don't fill out dates older than a year
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const yearDay = timeDay.count(timeYear(date), date);
|
const yearDay = timeDay.count(timeYear(date), date);
|
||||||
if (!dayMap.has(yearDay)) {
|
if (!dayMap.has(yearDay)) {
|
||||||
const weekNumber = timeWeek.count(timeYear(date), date);
|
const weekNumber = timeWeek.count(timeYear(date), date);
|
||||||
|
|
Loading…
Reference in a new issue