From fc89efb1d954ce331002b4dd0b464109938b8a35 Mon Sep 17 00:00:00 2001 From: Luc Mcgrady Date: Sun, 13 Jul 2025 21:04:54 +0100 Subject: [PATCH] dont clear points on mode swap --- ts/routes/deck-options/SimulatorModal.svelte | 35 ++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/ts/routes/deck-options/SimulatorModal.svelte b/ts/routes/deck-options/SimulatorModal.svelte index 2fa3d8e70..40f680d9a 100644 --- a/ts/routes/deck-options/SimulatorModal.svelte +++ b/ts/routes/deck-options/SimulatorModal.svelte @@ -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);