dont clear points on mode swap

This commit is contained in:
Luc Mcgrady 2025-07-13 21:04:54 +01:00
parent b9b39452cb
commit fc89efb1d9
No known key found for this signature in database
GPG key ID: 4F3D7A0B17CC3D9C

View file

@ -64,7 +64,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let svg: HTMLElement | SVGElement | null = null;
let simulationNumber = 0;
let workloadSimulationNumber = 0;
let points: Point[] = [];
let workloadPoints: Point[] = [];
const newCardsIgnoreReviewLimit = state.newCardsIgnoreReviewLimit;
let smooth = true;
let suspendLeeches = $config.leechAction == DeckConfig_Config_LeechAction.SUSPEND;
@ -78,6 +80,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: deckSize = 0;
$: windowSize = Math.ceil(daysToSimulate / 365);
$: processing = simulating || computingRetention;
$: currentPoints = workload ? workloadPoints : points;
$: currentSimulationNumber = workload ? workloadSimulationNumber : simulationNumber;
function movingAverage(y: number[], windowSize: number): number[] {
const result: number[] = [];
@ -163,8 +167,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} finally {
simulating = false;
if (resp) {
// Clear the graph if transitioning from workload to simulation
simulationNumber += 1;
const dailyTotalCount = addArrays(
resp.dailyReviewCount,
@ -207,22 +209,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} finally {
simulating = false;
if (resp) {
simulationNumber += 1;
workloadSimulationNumber += 1;
points = points.concat(
workloadPoints = workloadPoints.concat(
Object.entries(resp.memorized).map(([dr, v]) => ({
x: parseInt(dr),
timeCost: resp!.cost[dr],
memorized: v,
count: -1,
label: simulationNumber,
label: workloadSimulationNumber,
})),
);
tableData = renderWorkloadChart(
svg as SVGElement,
bounds,
points,
workloadPoints,
simulateWorkloadSubgraph,
);
}
@ -230,12 +232,21 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
function clearSimulation() {
points = points.filter((p) => p.label !== simulationNumber);
simulationNumber = Math.max(0, simulationNumber - 1);
const newPoints = currentPoints.filter(
(p) => p.label !== currentSimulationNumber,
);
const newSimulationNumber = Math.max(0, currentSimulationNumber - 1);
if (workload) {
workloadPoints = newPoints;
workloadSimulationNumber = newSimulationNumber;
} else {
points = newPoints;
simulationNumber = newSimulationNumber;
}
tableData = renderSimulationChart(
svg as SVGElement,
bounds,
points,
newPoints,
simulateSubgraph,
);
}
@ -260,16 +271,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
function switchModes() {
points = [];
simulationNumber = 0;
workload = !workload;
}
$: if (svg) {
let pointsToRender = points;
let pointsToRender = currentPoints;
if (smooth) {
// Group points by label (simulation number)
const groupedPoints = points.reduce(
const groupedPoints = currentPoints.reduce(
(acc, point) => {
acc[point.label] = acc[point.label] || [];
acc[point.label].push(point);