mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Get weekday labels via Date.prototype.toLocaleString
This commit is contained in:
parent
d961e61f2b
commit
d1980aae68
2 changed files with 12 additions and 7 deletions
|
@ -28,7 +28,7 @@ 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;
|
timeFunction: CountableTimeInterval;
|
||||||
weekdayLabels: string[];
|
weekdayLabels: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DayDatum {
|
interface DayDatum {
|
||||||
|
@ -64,11 +64,9 @@ export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
|
||||||
? timeSaturday
|
? timeSaturday
|
||||||
: timeSunday;
|
: timeSunday;
|
||||||
|
|
||||||
const weekdayLabels = ["S", "M", "T", "W", "T", "F", "S"];
|
const weekdayLabels: number[] = [];
|
||||||
|
for (let i = 0; i < 7; i++) {
|
||||||
for (let i = 0; i < data.firstWeekday; i++) {
|
weekdayLabels.push((data.firstWeekday + i) % 7);
|
||||||
const shifted = weekdayLabels.shift() as string;
|
|
||||||
weekdayLabels.push(shifted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { reviewCount, timeFunction, weekdayLabels };
|
return { reviewCount, timeFunction, weekdayLabels };
|
||||||
|
@ -168,7 +166,7 @@ export function renderCalendar(
|
||||||
.selectAll("text")
|
.selectAll("text")
|
||||||
.data(sourceData.weekdayLabels)
|
.data(sourceData.weekdayLabels)
|
||||||
.join("text")
|
.join("text")
|
||||||
.text((d) => d)
|
.text((d: number) => i18n.weekdayLabel(d))
|
||||||
.attr("width", x(-1)! - 2)
|
.attr("width", x(-1)! - 2)
|
||||||
.attr("height", height - 2)
|
.attr("height", height - 2)
|
||||||
.attr("x", x(1)! - 3)
|
.attr("x", x(1)! - 3)
|
||||||
|
|
|
@ -59,6 +59,13 @@ export class I18n {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
weekdayLabel(n: number): string {
|
||||||
|
const firstLang = this.bundles[0].locales[0];
|
||||||
|
return new Date(86_400_000 * (3 + n)).toLocaleDateString(firstLang, {
|
||||||
|
weekday: "narrow",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private keyName(msg: pb.FluentProto.FluentString): string {
|
private keyName(msg: pb.FluentProto.FluentString): string {
|
||||||
return this.TR[msg].toLowerCase().replace(/_/g, "-");
|
return this.TR[msg].toLowerCase().replace(/_/g, "-");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue