Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion ts/routes/deck-options/SimulatorModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Warning from "./Warning.svelte";
import type { ComputeRetentionProgress } from "@generated/anki/collection_pb";
import Modal from "bootstrap/js/dist/modal";
import { onMount } from "svelte";

export let state: DeckOptionsState;
export let simulateFsrsRequest: SimulateFsrsReviewRequest;
Expand Down Expand Up @@ -320,6 +321,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
},
};
}

let font_scale = 1;
function updateFontScale() {
font_scale = bounds.height / (svg?.clientHeight ?? bounds.height);
}

$: if (svg?.clientHeight) {
updateFontScale();
}

onMount(() => {
const observer = new ResizeObserver(() => {
updateFontScale();
});
observer.observe(svg!);
return () => {
observer.disconnect();
};
});
Comment thread
Luc-Mcgrady marked this conversation as resolved.
</script>

<div class="modal" tabindex="-1" use:setupModal>
Expand Down Expand Up @@ -605,6 +625,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<svg
bind:this={svg}
viewBox={`0 0 ${bounds.width} ${bounds.height}`}
style:--font-scale={font_scale}
>
<CumulativeOverlay />
<HoverColumns />
Expand All @@ -620,7 +641,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</div>
</div>

<style>
<style lang="scss">
.modal {
background-color: rgba(0, 0, 0, 0.5);
--bs-modal-margin: 0;
Expand Down Expand Up @@ -663,4 +684,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
summary {
margin-bottom: 0.5em;
}

.svg-container svg {
:global(.tick text),
:global(.legend) {
font-size: calc(1rem * var(--font-scale));
}
}
</style>
20 changes: 10 additions & 10 deletions ts/routes/graphs/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,22 +376,22 @@ function _renderSimulationChart<
.selectAll("g")
.data(Array.from(groups.keys()))
.join("g")
.attr("transform", (d, i) => `translate(0,${i * 20})`)
.attr("cursor", "pointer")
.on("click", (event, d) => toggleGroup(event, d))
.on("mousemove", legendMouseMove)
.on("mouseout", hideTooltip);

legend.append("rect")
.attr("x", bounds.width - bounds.marginRight + 36)
.attr("width", 12)
.attr("height", 12)
.attr("fill", (d, i) => color[i % color.length]);

legend.append("text")
const legendText = legend.append("text")
.attr("x", bounds.width - bounds.marginRight + 52)
.attr("y", 7)
.attr("dy", "0.3em")
.attr("y", 14)
.attr("dy", (d, i) => `${i * 1.2}em`);

legendText
.insert("tspan")
.attr("fill", (d, i) => color[i % color.length])
.text("■ ");

legendText.append("tspan")
.attr("fill", "currentColor")
.text(d => `#${d}`);

Expand Down
Loading