From f37635e34182446390eb8e37928cffa4a529da51 Mon Sep 17 00:00:00 2001 From: gka Date: Tue, 27 May 2025 01:12:46 +0200 Subject: [PATCH 1/4] add jitter examples --- src/routes/transforms/jitter/+page.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/routes/transforms/jitter/+page.md b/src/routes/transforms/jitter/+page.md index d5b4348c..5965679d 100644 --- a/src/routes/transforms/jitter/+page.md +++ b/src/routes/transforms/jitter/+page.md @@ -121,7 +121,7 @@ Jittering also works for temporal data. When jittering Date objects, random time })) ); - let type = $state('uniform'); + let type = $state('normal'); let width = $state('1 month'); const timeIntervals = [ @@ -163,6 +163,25 @@ Jittering also works for temporal data. When jittering Date objects, random time ``` +```svelte + + + +``` + +[fork](https://svelte.dev/playground/6938e854283d4e56893ceca748393f6f?version=5) + This example shows how jittering can be applied to date values in the x-axis, which can be useful when multiple events occur at the same date and would otherwise overlap. ## Custom random sources @@ -190,6 +209,8 @@ For reproducible jittering or specialized random distributions, you can provide ``` +[fork](https://svelte.dev/playground/ef02e12058354e53a9da72ae249ad359?version=5.30.2) + This is particularly useful for: - Testing and debugging visualizations From 29330620992482c5a8453ee3a4135abe5419fe7c Mon Sep 17 00:00:00 2001 From: gka Date: Tue, 27 May 2025 08:32:30 +0200 Subject: [PATCH 2/4] fix: repaint canvas layers on colorMode changes --- .vscode/settings.json | 14 ++------- src/lib/marks/helpers/CanvasLayer.svelte | 38 +++++++++++++++++++----- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 46d9035f..21800944 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,23 +13,13 @@ "[svelte]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, - "eslint.validate": [ - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "svelte" - ], + "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "svelte"], "prettier.useTabs": false, "prettier.singleQuote": true, "prettier.tabWidth": 4, "prettier.trailingComma": "none", "prettier.printWidth": 100, "svelte.plugin.svelte.format.enable": false, - "eslint.probe": [ - "javascript", - "typescript", - "svelte" - ], + "eslint.probe": ["javascript", "typescript", "svelte"], "eslint.experimental.useFlatConfig": true } diff --git a/src/lib/marks/helpers/CanvasLayer.svelte b/src/lib/marks/helpers/CanvasLayer.svelte index 16431f13..9bbaf502 100644 --- a/src/lib/marks/helpers/CanvasLayer.svelte +++ b/src/lib/marks/helpers/CanvasLayer.svelte @@ -2,6 +2,27 @@ import { getContext } from 'svelte'; import type { PlotContext } from 'svelteplot/types'; import { devicePixelRatio } from 'svelte/reactivity/window'; + import { MediaQuery } from 'svelte/reactivity'; + import type { Attachment } from 'svelte/attachments'; + + const darkMode = new MediaQuery('prefers-color-scheme: dark'); + let colorScheme = $state(); + + /** + * we need to repaint on dark mode changes in case the user + * is using any css variables or currentColor that changes + * with the color scheme + */ + const watchColorScheme: Attachment = (element: Element) => { + const htmlElement = element.ownerDocument.documentElement; + const observer = new MutationObserver(() => { + colorScheme = getComputedStyle(htmlElement).colorScheme; + }); + observer.observe(htmlElement, { attributes: true }); + return () => { + observer.disconnect(); + }; + }; let restProps: {} = $props(); @@ -14,14 +35,15 @@ canvas element inside a foreignObject for use in a plot and takes care of scaling it to the device pixel ratio. --> - - - + + {#key [colorScheme, darkMode.current]} + + {/key}