mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
Remve SeparateInactiveCheckbox and correctly use preferences values
* Expose issue with non-existing calendar value in GraphPreferences
This commit is contained in:
parent
d1ada88657
commit
b0c2e8c99c
6 changed files with 32 additions and 29 deletions
|
@ -8,10 +8,12 @@
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
export let sourceData: pb.BackendProto.GraphsOut | null = null;
|
export let sourceData: pb.BackendProto.GraphsOut | null = null;
|
||||||
|
export let preferences: pb.BackendProto.GraphsPreferencesOut | null = null;
|
||||||
export let revlogRange: RevlogRange;
|
export let revlogRange: RevlogRange;
|
||||||
export let i18n: I18n;
|
export let i18n: I18n;
|
||||||
export let nightMode: boolean;
|
export let nightMode: boolean;
|
||||||
|
|
||||||
|
let { calendarFirstDayOfWeek } = preferences;
|
||||||
let graphData: GraphData | null = null;
|
let graphData: GraphData | null = null;
|
||||||
|
|
||||||
let bounds = defaultGraphBounds();
|
let bounds = defaultGraphBounds();
|
||||||
|
@ -25,7 +27,7 @@
|
||||||
let targetYear = maxYear;
|
let targetYear = maxYear;
|
||||||
|
|
||||||
$: if (sourceData) {
|
$: if (sourceData) {
|
||||||
graphData = gatherData(sourceData);
|
graphData = gatherData(sourceData, $calendarFirstDayOfWeek);
|
||||||
}
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
import type { PreferenceStore } from "./preferences";
|
import type { PreferenceStore } from "./preferences";
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import SeparateInactiveCheckbox from "./SeparateInactiveCheckbox.svelte";
|
|
||||||
|
|
||||||
export let sourceData: pb.BackendProto.GraphsOut;
|
export let sourceData: pb.BackendProto.GraphsOut;
|
||||||
export let i18n: I18n;
|
export let i18n: I18n;
|
||||||
|
@ -26,6 +25,7 @@
|
||||||
tableData = renderCards(svg as any, bounds, graphData);
|
tableData = renderCards(svg as any, bounds, graphData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const label = i18n.tr(i18n.TR.STATISTICS_COUNTS_SEPARATE_SUSPENDED_BURIED_CARDS);
|
||||||
const total = i18n.tr(i18n.TR.STATISTICS_COUNTS_TOTAL_CARDS);
|
const total = i18n.tr(i18n.TR.STATISTICS_COUNTS_TOTAL_CARDS);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -58,7 +58,10 @@
|
||||||
<h1>{graphData.title}</h1>
|
<h1>{graphData.title}</h1>
|
||||||
|
|
||||||
<div class="range-box-inner">
|
<div class="range-box-inner">
|
||||||
<SeparateInactiveCheckbox {i18n} {cardCountsSeparateInactive} />
|
<label>
|
||||||
|
<input type="checkbox" bind:checked={$cardCountsSeparateInactive} />
|
||||||
|
{label}
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="counts-outer">
|
<div class="counts-outer">
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<script lang="typescript">
|
|
||||||
import type { I18n } from "anki/i18n";
|
|
||||||
import type { CustomStore } from "./preferences";
|
|
||||||
|
|
||||||
export let i18n: I18n;
|
|
||||||
export let cardCountsSeparateInactive: CustomStore<boolean>;
|
|
||||||
|
|
||||||
const label = i18n.tr(i18n.TR.STATISTICS_COUNTS_SEPARATE_SUSPENDED_BURIED_CARDS);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" bind:checked={$cardCountsSeparateInactive} />
|
|
||||||
{label}
|
|
||||||
</label>
|
|
|
@ -6,7 +6,7 @@
|
||||||
@typescript-eslint/no-explicit-any: "off",
|
@typescript-eslint/no-explicit-any: "off",
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type pb from "anki/backend_proto";
|
import pb from "anki/backend_proto";
|
||||||
import { interpolateBlues } from "d3-scale-chromatic";
|
import { interpolateBlues } from "d3-scale-chromatic";
|
||||||
import "d3-transition";
|
import "d3-transition";
|
||||||
import { select, mouse } from "d3-selection";
|
import { select, mouse } from "d3-selection";
|
||||||
|
@ -41,7 +41,13 @@ interface DayDatum {
|
||||||
date: Date;
|
date: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
|
type WeekdayType = pb.BackendProto.GraphsPreferencesOut.Weekday;
|
||||||
|
const Weekday = pb.BackendProto.GraphsPreferencesOut.Weekday; /* enum */
|
||||||
|
|
||||||
|
export function gatherData(
|
||||||
|
data: pb.BackendProto.GraphsOut,
|
||||||
|
firstDayOfWeek: WeekdayType
|
||||||
|
): GraphData {
|
||||||
const reviewCount = new Map<number, number>();
|
const reviewCount = new Map<number, number>();
|
||||||
|
|
||||||
for (const review of data.revlog as pb.BackendProto.RevlogEntry[]) {
|
for (const review of data.revlog as pb.BackendProto.RevlogEntry[]) {
|
||||||
|
@ -56,17 +62,17 @@ export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeFunction =
|
const timeFunction =
|
||||||
data.firstWeekday === 1
|
firstDayOfWeek === Weekday.MONDAY
|
||||||
? timeMonday
|
? timeMonday
|
||||||
: data.firstWeekday === 5
|
: data.firstWeekday === Weekday.FRIDAY
|
||||||
? timeFriday
|
? timeFriday
|
||||||
: data.firstWeekday === 6
|
: data.firstWeekday === Weekday.SATURDAY
|
||||||
? timeSaturday
|
? timeSaturday
|
||||||
: timeSunday;
|
: timeSunday;
|
||||||
|
|
||||||
const weekdayLabels: number[] = [];
|
const weekdayLabels: number[] = [];
|
||||||
for (let i = 0; i < 7; i++) {
|
for (let i = 0; i < 7; i++) {
|
||||||
weekdayLabels.push((data.firstWeekday + i) % 7);
|
weekdayLabels.push((firstDayOfWeek + i) % 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { reviewCount, timeFunction, weekdayLabels };
|
return { reviewCount, timeFunction, weekdayLabels };
|
||||||
|
|
|
@ -25,10 +25,15 @@ export async function getGraphPreferences(): Promise<pb.BackendProto.GraphsPrefe
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setGraphPreferences(prefs: pb.BackendProto.GraphsPreferencesOut): Promise<void> {
|
export async function setGraphPreferences(
|
||||||
|
prefs: pb.BackendProto.GraphsPreferencesOut
|
||||||
|
): Promise<void> {
|
||||||
return (async () => {
|
return (async () => {
|
||||||
await postRequest("/_anki/setGraphPreferences", pb.BackendProto.GraphsPreferencesOut.encode(prefs).finish())
|
await postRequest(
|
||||||
})()
|
"/_anki/setGraphPreferences",
|
||||||
|
pb.BackendProto.GraphsPreferencesOut.encode(prefs).finish()
|
||||||
|
);
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
// amount of data to fetch from backend
|
// amount of data to fetch from backend
|
||||||
|
|
|
@ -2,7 +2,6 @@ import type pb from "anki/backend_proto";
|
||||||
import { getGraphPreferences, setGraphPreferences } from "./graph-helpers";
|
import { getGraphPreferences, setGraphPreferences } from "./graph-helpers";
|
||||||
import { writable, get } from "svelte/store";
|
import { writable, get } from "svelte/store";
|
||||||
|
|
||||||
|
|
||||||
export interface CustomStore<T> {
|
export interface CustomStore<T> {
|
||||||
subscribe: (getter: (value: T) => void) => () => void;
|
subscribe: (getter: (value: T) => void) => () => void;
|
||||||
set: (value: T) => void;
|
set: (value: T) => void;
|
||||||
|
@ -29,7 +28,9 @@ function createPreference<T>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function preparePreferences(graphsPreferences: pb.BackendProto.GraphsPreferencesOut): PreferenceStore {
|
function preparePreferences(
|
||||||
|
graphsPreferences: pb.BackendProto.GraphsPreferencesOut
|
||||||
|
): PreferenceStore {
|
||||||
const preferences: Partial<PreferenceStore> = {};
|
const preferences: Partial<PreferenceStore> = {};
|
||||||
|
|
||||||
function constructPreferences(): pb.BackendProto.GraphsPreferencesOut {
|
function constructPreferences(): pb.BackendProto.GraphsPreferencesOut {
|
||||||
|
@ -53,5 +54,5 @@ function preparePreferences(graphsPreferences: pb.BackendProto.GraphsPreferences
|
||||||
|
|
||||||
export async function getPreferences() {
|
export async function getPreferences() {
|
||||||
const initialPreferences = await getGraphPreferences();
|
const initialPreferences = await getGraphPreferences();
|
||||||
return preparePreferences(initialPreferences)
|
return preparePreferences(initialPreferences);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue