mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Merge pull request #928 from hgiesel/sunday2
Different first weekday support for Calendar View, Take 2
This commit is contained in:
commit
9e3517b480
4 changed files with 51 additions and 6 deletions
|
@ -1082,6 +1082,12 @@ message GraphsIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
message GraphsOut {
|
message GraphsOut {
|
||||||
|
enum Weekday {
|
||||||
|
SUNDAY = 0;
|
||||||
|
MONDAY = 1;
|
||||||
|
FRIDAY = 5;
|
||||||
|
SATURDAY = 6;
|
||||||
|
}
|
||||||
repeated Card cards = 1;
|
repeated Card cards = 1;
|
||||||
repeated RevlogEntry revlog = 2;
|
repeated RevlogEntry revlog = 2;
|
||||||
uint32 days_elapsed = 3;
|
uint32 days_elapsed = 3;
|
||||||
|
@ -1090,6 +1096,7 @@ message GraphsOut {
|
||||||
uint32 scheduler_version = 5;
|
uint32 scheduler_version = 5;
|
||||||
/// Seconds to add to UTC timestamps to get local time.
|
/// Seconds to add to UTC timestamps to get local time.
|
||||||
int32 local_offset_secs = 7;
|
int32 local_offset_secs = 7;
|
||||||
|
Weekday first_weekday = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RevlogEntry {
|
message RevlogEntry {
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub(crate) fn schema11_config_as_string() -> String {
|
||||||
"curDeck": 1,
|
"curDeck": 1,
|
||||||
"newSpread": 0,
|
"newSpread": 0,
|
||||||
"collapseTime": 1200,
|
"collapseTime": 1200,
|
||||||
|
"firstWeekday": 0,
|
||||||
"timeLim": 0,
|
"timeLim": 0,
|
||||||
"estTimes": true,
|
"estTimes": true,
|
||||||
"dueCounts": true,
|
"dueCounts": true,
|
||||||
|
@ -47,6 +48,7 @@ pub(crate) enum ConfigKey {
|
||||||
ShowRemainingDueCountsInStudy,
|
ShowRemainingDueCountsInStudy,
|
||||||
ShowIntervalsAboveAnswerButtons,
|
ShowIntervalsAboveAnswerButtons,
|
||||||
NewReviewMix,
|
NewReviewMix,
|
||||||
|
FirstWeekday,
|
||||||
AnswerTimeLimitSecs,
|
AnswerTimeLimitSecs,
|
||||||
ShowDayLearningCardsFirst,
|
ShowDayLearningCardsFirst,
|
||||||
LastUnburiedDay,
|
LastUnburiedDay,
|
||||||
|
@ -75,6 +77,7 @@ impl From<ConfigKey> for &'static str {
|
||||||
ConfigKey::ShowRemainingDueCountsInStudy => "dueCounts",
|
ConfigKey::ShowRemainingDueCountsInStudy => "dueCounts",
|
||||||
ConfigKey::ShowIntervalsAboveAnswerButtons => "estTimes",
|
ConfigKey::ShowIntervalsAboveAnswerButtons => "estTimes",
|
||||||
ConfigKey::NewReviewMix => "newSpread",
|
ConfigKey::NewReviewMix => "newSpread",
|
||||||
|
ConfigKey::FirstWeekday => "firstWeekday",
|
||||||
ConfigKey::AnswerTimeLimitSecs => "timeLim",
|
ConfigKey::AnswerTimeLimitSecs => "timeLim",
|
||||||
ConfigKey::ShowDayLearningCardsFirst => "dayLearnFirst",
|
ConfigKey::ShowDayLearningCardsFirst => "dayLearnFirst",
|
||||||
ConfigKey::LastUnburiedDay => "lastUnburied",
|
ConfigKey::LastUnburiedDay => "lastUnburied",
|
||||||
|
@ -227,6 +230,15 @@ impl Collection {
|
||||||
self.set_config(ConfigKey::NewReviewMix, &(mix as u8))
|
self.set_config(ConfigKey::NewReviewMix, &(mix as u8))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_first_weekday(&self) -> Weekday {
|
||||||
|
match self.get_config_default::<u8, _>(ConfigKey::FirstWeekday) {
|
||||||
|
1 => Weekday::Monday,
|
||||||
|
5 => Weekday::Friday,
|
||||||
|
6 => Weekday::Saturday,
|
||||||
|
_ => Weekday::Sunday,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_show_due_counts(&self) -> bool {
|
pub(crate) fn get_show_due_counts(&self) -> bool {
|
||||||
self.get_config_optional(ConfigKey::ShowRemainingDueCountsInStudy)
|
self.get_config_optional(ConfigKey::ShowRemainingDueCountsInStudy)
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
|
@ -309,6 +321,13 @@ pub(crate) enum NewReviewMix {
|
||||||
NewFirst = 2,
|
NewFirst = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) enum Weekday {
|
||||||
|
Sunday = 0,
|
||||||
|
Monday = 1,
|
||||||
|
Friday = 5,
|
||||||
|
Saturday = 6,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::SortKind;
|
use super::SortKind;
|
||||||
|
|
|
@ -42,6 +42,7 @@ impl Collection {
|
||||||
next_day_at_secs: timing.next_day_at as u32,
|
next_day_at_secs: timing.next_day_at as u32,
|
||||||
scheduler_version: self.sched_ver() as u32,
|
scheduler_version: self.sched_ver() as u32,
|
||||||
local_offset_secs: local_offset_secs as i32,
|
local_offset_secs: local_offset_secs as i32,
|
||||||
|
first_weekday: self.get_first_weekday() as i32,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,21 @@ 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, RevlogRange } from "./graph-helpers";
|
import { GraphBounds, setDataAvailable, RevlogRange } from "./graph-helpers";
|
||||||
import { timeDay, timeYear, timeWeek } from "d3-time";
|
import {
|
||||||
|
timeDay,
|
||||||
|
timeYear,
|
||||||
|
timeSunday,
|
||||||
|
timeMonday,
|
||||||
|
timeFriday,
|
||||||
|
timeSaturday,
|
||||||
|
} from "d3-time";
|
||||||
|
import type { CountableTimeInterval } from "d3-time";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
// indexed by day, where day is relative to today
|
// indexed by day, where day is relative to today
|
||||||
reviewCount: Map<number, number>;
|
reviewCount: Map<number, number>;
|
||||||
|
timeFunction: CountableTimeInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DayDatum {
|
interface DayDatum {
|
||||||
|
@ -45,7 +54,16 @@ export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
|
||||||
reviewCount.set(day, count + 1);
|
reviewCount.set(day, count + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { reviewCount };
|
const timeFunction =
|
||||||
|
data.firstWeekday === 1
|
||||||
|
? timeMonday
|
||||||
|
: data.firstWeekday === 5
|
||||||
|
? timeFriday
|
||||||
|
: data.firstWeekday === 6
|
||||||
|
? timeSaturday
|
||||||
|
: timeSunday;
|
||||||
|
|
||||||
|
return { reviewCount, timeFunction };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderCalendar(
|
export function renderCalendar(
|
||||||
|
@ -73,8 +91,8 @@ export function renderCalendar(
|
||||||
if (date.getFullYear() != targetYear) {
|
if (date.getFullYear() != targetYear) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const weekNumber = timeWeek.count(timeYear(date), date);
|
const weekNumber = sourceData.timeFunction.count(timeYear(date), date);
|
||||||
const weekDay = timeDay.count(timeWeek(date), date);
|
const weekDay = timeDay.count(sourceData.timeFunction(date), date);
|
||||||
const yearDay = timeDay.count(timeYear(date), date);
|
const yearDay = timeDay.count(timeYear(date), date);
|
||||||
dayMap.set(yearDay, { day, count, weekNumber, weekDay, date } as DayDatum);
|
dayMap.set(yearDay, { day, count, weekNumber, weekDay, date } as DayDatum);
|
||||||
if (count > maxCount) {
|
if (count > maxCount) {
|
||||||
|
@ -105,8 +123,8 @@ export function renderCalendar(
|
||||||
}
|
}
|
||||||
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 = sourceData.timeFunction.count(timeYear(date), date);
|
||||||
const weekDay = timeDay.count(timeWeek(date), date);
|
const weekDay = timeDay.count(sourceData.timeFunction(date), date);
|
||||||
dayMap.set(yearDay, {
|
dayMap.set(yearDay, {
|
||||||
day: yearDay,
|
day: yearDay,
|
||||||
count: 0,
|
count: 0,
|
||||||
|
|
Loading…
Reference in a new issue