Utils
diff --git a/docs/src/lib/components/Example.svelte b/docs/src/lib/components/Example.svelte
index 1de7cb6a10..d184417884 100644
--- a/docs/src/lib/components/Example.svelte
+++ b/docs/src/lib/components/Example.svelte
@@ -46,9 +46,11 @@
const settings = getSettings();
import { movable } from '$lib/actions/movable';
+ import { nativeWebGLExamples, webglExamples } from 'virtual:webgl-examples';
+ import LayerSetting from '$lib/components/LayerSetting.svelte';
let {
- // The page's component: its folder under `src/examples/components` (ex. `webgl/Points`)
+ // The page's component: its folder under `src/examples/components` (ex. `Points`)
component = (page.data.componentName as string | undefined) ?? page.params.name!,
name,
path,
@@ -77,7 +79,7 @@
const examplesCtx = examples.get();
// Use $state + $effect to break potential infinite reactivity loops during HMR
- let example = $state<{ component: any; source: string } | undefined>(undefined);
+ let loadedExample = $state<{ component: any; source: string } | undefined>(undefined);
$effect(() => {
const current = examplesCtx?.current;
@@ -99,12 +101,43 @@
// Only assign if the reference actually changed to avoid unnecessary downstream reactivity
// Untrack both the read and write to prevent this effect from depending on its own output
untrack(() => {
- if (example !== next) {
- example = next;
+ if (loadedExample !== next) {
+ loadedExample = next;
}
});
});
+ /**
+ * With the layer toggle on `WebGL`, this example's WebGL version (its components imported from
+ * `@layerchart/webgl`), if it has one. Examples without one draw with Canvas, as LayerChart's
+ * `Layer` would.
+ */
+ const loadWebGL = $derived(
+ settings.layer === 'webgl' && component && name && !path
+ ? webglExamples[`${component}/${name}`]
+ : undefined
+ );
+ let webglExample = $state<{ component: any; source: string } | undefined>(undefined);
+ $effect(() => {
+ const load = loadWebGL;
+ webglExample = undefined;
+ if (!load) return;
+ let current = true;
+ load().then((loaded) => {
+ if (current) webglExample = loaded;
+ });
+ return () => {
+ current = false;
+ };
+ });
+ const example = $derived(webglExample ?? loadedExample);
+ /** Written with `@layerchart/webgl`, so drawn with WebGL whatever the layer */
+ const nativeWebGL = $derived(
+ !!component && !!name && !path && nativeWebGLExamples.has(`${component}/${name}`)
+ );
+ /** Drawn with Canvas while the layer is `webgl`: no WebGL version (or not loaded yet) */
+ const canvasInstead = $derived(settings.layer === 'webgl' && !webglExample && !nativeWebGL);
+
/**
* Code beside the preview rather than below it. Only offered with room for both, and
* only while the code is showing; the toggle is in the code panel's menu.
@@ -322,7 +355,13 @@
>
{/if}
{#if !sandbox.showing && example}
-
+ {#if canvasInstead}
+
+
+
+ {:else}
+
+ {/if}
{/if}
{#snippet failed(error, reset)}
@@ -378,7 +417,12 @@
bind:lineNumbers
{highlight}
onopenstackblitz={component && name
- ? () => openInStackBlitz(component, name, sandbox.dirty ? sandbox.source : undefined)
+ ? () =>
+ openInStackBlitz(
+ component,
+ name,
+ sandbox.dirty ? sandbox.source : webglExample?.source
+ )
: undefined}
{split}
onsplitchange={wide.current ? setSplit : undefined}
@@ -467,7 +511,7 @@
openPngDialog('export')}>
Export as PNG
- {#if settings.layer !== 'canvas'}
+ {#if settings.layer !== 'canvas' && settings.layer !== 'webgl' && !nativeWebGL}
Copy as SVG
Export as SVG
@@ -476,6 +520,12 @@
+
+ {#if settings.layer === 'webgl' && !loadWebGL && !nativeWebGL}
+ No WebGL version: drawn with Canvas
+ {/if}
{/if}
{:else}
diff --git a/docs/src/lib/components/LayerSetting.svelte b/docs/src/lib/components/LayerSetting.svelte
new file mode 100644
index 0000000000..50c956ea9f
--- /dev/null
+++ b/docs/src/lib/components/LayerSetting.svelte
@@ -0,0 +1,20 @@
+
+
+{@render children()}
diff --git a/docs/src/lib/components/PageHeader.svelte b/docs/src/lib/components/PageHeader.svelte
index d609b67a7f..794846e759 100644
--- a/docs/src/lib/components/PageHeader.svelte
+++ b/docs/src/lib/components/PageHeader.svelte
@@ -1,7 +1,6 @@
\n\n${markup}\n`;
+
+describe('toWebGL', () => {
+ it('imports the components `@layerchart/webgl` has from it, and the rest as before', () => {
+ const source = example(
+ "\timport { Axis, Chart, Layer, Points, format, type ChartState } from 'layerchart';"
+ );
+ expect(toWebGL(source, webgl)).toBe(
+ example(
+ "\timport { Axis, Chart, Layer, Points } from '@layerchart/webgl';\n\timport { format, type ChartState } from 'layerchart';"
+ )
+ );
+ });
+
+ it('rewrites `layerchart/geo` imports, across lines', () => {
+ const source = example(
+ "\timport { Chart, Layer } from 'layerchart';\n\timport {\n\t\tGeoPath\n\t} from 'layerchart/geo';",
+ ' '
+ );
+ expect(toWebGL(source, webgl)).toContain("import { GeoPath } from '@layerchart/webgl';");
+ });
+
+ it("skips an example drawing a component `@layerchart/webgl` doesn't have", () => {
+ const source = example(
+ "\timport { Chart, Layer, Labels, Points } from 'layerchart';",
+ ' '
+ );
+ expect(toWebGL(source, webgl)).toBeNull();
+ });
+
+ it('keeps other names it imports from `layerchart` (ex. a type, or a component unused)', () => {
+ const source = example(
+ "\timport { Chart, ChartState, Labels, Layer, Points } from 'layerchart';"
+ );
+ expect(toWebGL(source, webgl)).toContain("import { ChartState, Labels } from 'layerchart';");
+ });
+
+ it('skips an example drawn in a layer of its own', () => {
+ const imports = "\timport { Chart, Layer, Points, Svg } from 'layerchart';";
+ expect(toWebGL(example(imports, ' '), webgl)).toBeNull();
+ expect(
+ toWebGL(example(imports, ' '), webgl)
+ ).toBeNull();
+ });
+
+ it('skips an example with components of its own, which could draw core marks', () => {
+ const source = example(
+ "\timport { Chart, Layer, Points } from 'layerchart';\n\timport Marks from './Marks.svelte';"
+ );
+ expect(toWebGL(source, webgl)).toBeNull();
+ });
+});
+
+describe('isNativeWebGL', () => {
+ it('is an example written with `@layerchart/webgl`, which draws with WebGL whatever the layer', () => {
+ expect(
+ isNativeWebGL(example("\timport { Chart, WebGL, Points } from '@layerchart/webgl';"))
+ ).toBe(true);
+ expect(isNativeWebGL(example("\timport { Points } from '@layerchart/webgl/webgl';"))).toBe(
+ true
+ );
+ expect(isNativeWebGL(example("\timport { Chart, Layer, Points } from 'layerchart';"))).toBe(
+ false
+ );
+ });
+});
diff --git a/docs/src/routes/docs/components/[name]/+layout.svelte b/docs/src/routes/docs/components/[name]/+layout.svelte
index a01b495644..6206556805 100644
--- a/docs/src/routes/docs/components/[name]/+layout.svelte
+++ b/docs/src/routes/docs/components/[name]/+layout.svelte
@@ -3,8 +3,10 @@
import { examples } from '@layerstack/docs/context';
import PageHeader from '$lib/components/PageHeader.svelte';
import { intersectExampleLayers } from '$lib/utils/layers.js';
- import { webglCategories } from '$lib/webglCategories.js';
+ import { nativeWebGLExamples, webglExamples } from 'virtual:webgl-examples';
import { page } from '$app/state';
+ import { untrack } from 'svelte';
+ import { getSettings, type SettingsOptions } from 'layerchart';
import LucideBlocks from '~icons/lucide/blocks';
@@ -67,13 +69,42 @@
? intersectExampleLayers(exampleInfo.components, metadata.layers ?? [])
: null;
});
- // `@layerchart/webgl`'s pages draw in a `WebGL` layer only, shown (selected) on its own
+ // Whether this page has examples drawn with WebGL (see `vite-plugin-webgl-examples.ts`): the
+ // example's own, or any of the component's, either a WebGL version of one of LayerChart's or one
+ // written with `@layerchart/webgl`
+ const withWebGL = (key: string) => key in webglExamples || nativeWebGLExamples.has(key);
+ const hasWebGLExamples = $derived(
+ page.params.example
+ ? withWebGL(`${data.componentName}/${page.params.example}`)
+ : [...Object.keys(webglExamples), ...nativeWebGLExamples].some((key) =>
+ key.startsWith(`${data.componentName}/`)
+ )
+ );
+ // An example written with `@layerchart/webgl` draws in a `WebGL` layer only, shown (selected) on
+ // its own
let layers = $derived(
- data.componentName.startsWith('webgl/')
+ page.params.example && nativeWebGLExamples.has(`${data.componentName}/${page.params.example}`)
? ['webgl']
- : (pageExample?.module?.layers ?? computedExampleLayers ?? metadata.layers ?? [])
+ : [
+ ...new Set([
+ ...(pageExample?.module?.layers ?? computedExampleLayers ?? metadata.layers ?? []),
+ ...(hasWebGLExamples ? ['webgl'] : [])
+ ])
+ ]
);
+ // A link's `?layer=` (ex. from the examples page filtered to WebGL) opens the page in that layer,
+ // when it has it. Once per visit, so the layer toggle changes it from there.
+ const settings = getSettings();
+ $effect(() => {
+ const requested = page.url.searchParams.get('layer');
+ untrack(() => {
+ if (requested && layers.includes(requested)) {
+ settings.layer = requested as NonNullable;
+ }
+ });
+ });
+
// Component names as-is (ex. `ArcChart`), example names in sentence case (ex. `Axis labels inside`)
const exampleTitle = $derived(page.params.example?.replaceAll('-', ' '));
const title = $derived(
@@ -81,16 +112,8 @@
(exampleTitle ? exampleTitle[0].toUpperCase() + exampleTitle.slice(1) : metadata.name)
);
- // `@layerchart/webgl`'s pages sit under WebGL, in their group there (as in the menu)
- const webglCategory = $derived(
- data.componentName.startsWith('webgl/')
- ? webglCategories[metadata.category?.toLowerCase() ?? '']
- : undefined
- );
const breadcrumbs = $derived([
- ...(webglCategory
- ? [{ label: 'WebGL', href: '/docs/guides/webgl' }, { label: webglCategory }]
- : [{ label: metadata.category }]),
+ { label: metadata.category },
...(page.params.example
? [{ label: metadata.name, href: `/docs/components/${data.componentName}` }]
: [])
@@ -103,7 +126,6 @@
{breadcrumbs}
{layers}
{metadata}
- counterpart={data.counterpart}
description={pageExample?.module?.description ??
(page.params.example == null ? metadata.description : undefined)}
/>
diff --git a/docs/src/routes/docs/components/[name]/+page.svelte b/docs/src/routes/docs/components/[name]/+page.svelte
index b7687a2a31..d03ac59d2e 100644
--- a/docs/src/routes/docs/components/[name]/+page.svelte
+++ b/docs/src/routes/docs/components/[name]/+page.svelte
@@ -1,5 +1,6 @@
-
-
diff --git a/docs/src/routes/docs/components/webgl/[name]/+layout.ts b/docs/src/routes/docs/components/webgl/[name]/+layout.ts
deleted file mode 100644
index 1128900ca4..0000000000
--- a/docs/src/routes/docs/components/webgl/[name]/+layout.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { loadComponentPage } from '$lib/componentPage.js';
-
-// `@layerchart/webgl`'s components, whose names repeat LayerChart's (ex. `Points`)
-export const load = async (event) => loadComponentPage(`webgl/${event.params.name}`, event);
diff --git a/docs/src/routes/docs/components/webgl/[name]/+page.svelte b/docs/src/routes/docs/components/webgl/[name]/+page.svelte
deleted file mode 100644
index 3a2bcfa4d9..0000000000
--- a/docs/src/routes/docs/components/webgl/[name]/+page.svelte
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
diff --git a/docs/src/routes/docs/components/webgl/[name]/[example]/+page.svelte b/docs/src/routes/docs/components/webgl/[name]/[example]/+page.svelte
deleted file mode 100644
index d35a6c44f7..0000000000
--- a/docs/src/routes/docs/components/webgl/[name]/[example]/+page.svelte
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
diff --git a/docs/src/routes/docs/components/webgl/[name]/[example]/+page.ts b/docs/src/routes/docs/components/webgl/[name]/[example]/+page.ts
deleted file mode 100644
index 74905ca925..0000000000
--- a/docs/src/routes/docs/components/webgl/[name]/[example]/+page.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { load } from '../../../[name]/[example]/+page.js';
diff --git a/docs/src/routes/docs/components/webgl/[name]/examples/+page.svelte b/docs/src/routes/docs/components/webgl/[name]/examples/+page.svelte
deleted file mode 100644
index 008db61358..0000000000
--- a/docs/src/routes/docs/components/webgl/[name]/examples/+page.svelte
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
diff --git a/docs/src/routes/docs/components/webgl/[name]/examples/+page.ts b/docs/src/routes/docs/components/webgl/[name]/examples/+page.ts
deleted file mode 100644
index ac84029a6f..0000000000
--- a/docs/src/routes/docs/components/webgl/[name]/examples/+page.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { load } from '../../../[name]/examples/+page.js';
diff --git a/docs/src/routes/docs/components/webgl/[name]/llms.txt/+server.ts b/docs/src/routes/docs/components/webgl/[name]/llms.txt/+server.ts
deleted file mode 100644
index 0c0741a384..0000000000
--- a/docs/src/routes/docs/components/webgl/[name]/llms.txt/+server.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { error } from '@sveltejs/kit';
-import type { RequestHandler } from './$types';
-import { allComponents } from 'content-collections';
-import { generateComponentMarkdown, markdownResponse } from '$lib/llms/utils.js';
-
-export const GET: RequestHandler = async ({ params, url }) => {
- const slug = `webgl/${params.name}`;
-
- const component = allComponents.find((c) => c.slug === slug);
- if (!component) {
- error(404, `Component "${slug}" not found`);
- }
-
- const markdown = generateComponentMarkdown(component, {
- baseUrl: url.origin,
- inlineExamples: true
- });
-
- return markdownResponse(markdown, `${params.name}.md`);
-};
diff --git a/docs/src/routes/docs/examples/+page.server.ts b/docs/src/routes/docs/examples/+page.server.ts
index bf67135ba2..654d8edbf3 100644
--- a/docs/src/routes/docs/examples/+page.server.ts
+++ b/docs/src/routes/docs/examples/+page.server.ts
@@ -1,12 +1,15 @@
import { allComponents } from 'content-collections';
import type { ComponentCatalog } from '@layerstack/docs/catalog';
+import { nativeWebGLExamples, webglExamples } from 'virtual:webgl-examples';
+
+import { componentLayers, intersectExampleLayers } from '$lib/utils/layers.js';
import { metadata } from './metadata';
interface ExampleInfo {
- /** The component's slug, as its route and screenshots use it (ex. `Area`, `webgl/Area`) */
+ /** The component's slug, as its route and screenshots use it (ex. `Area`) */
component: string;
- /** What to call the component (ex. `Area`, `Area (WebGL)`) */
+ /** What to call the component (ex. `Area`) */
label: string;
category?: string;
examples: Array<{
@@ -15,11 +18,14 @@ interface ExampleInfo {
path: string;
/** The commit that first added the example's file (absent until it's committed) */
createdAt?: string;
+ /** The layers it draws in (ex. `['svg', 'canvas', 'webgl']`), as its page's layer toggle offers */
+ layers: string[];
}>;
}
export async function load() {
- // `@layerchart/webgl`'s catalogs sit in `webgl/`, as their names repeat LayerChart's (ex. `Area`)
+ // `@layerchart/webgl`'s catalogs sit in `webgl/`, used for its own components (ex. `Surface`):
+ // LayerChart's catalogs list every example of theirs, whichever package draws it
const catalogModules = import.meta.glob('/src/examples/catalog/**/*.json', {
eager: true,
import: 'default'
@@ -34,27 +40,35 @@ export async function load() {
}
// Build components list from catalog data
+ const slugOf = (path: string) => path.replace(/^.*\//, '').replace(/\.json$/, '');
+ const core = new Set(
+ Object.keys(catalogModules)
+ .filter((path) => !path.includes('/catalog/webgl/'))
+ .map(slugOf)
+ );
const components: ExampleInfo[] = Object.entries(catalogModules)
- .filter(([, catalog]) => catalog.examples.length > 0)
+ .filter(([path, catalog]) => {
+ if (!catalog.examples.length) return false;
+ // `@layerchart/webgl`'s own only, with a page of their own
+ if (!path.includes('/catalog/webgl/')) return true;
+ const slug = slugOf(path);
+ return !core.has(slug) && componentCategoryMap.has(slug);
+ })
.map(([path, catalog]) => {
- const slug = path.replace('/src/examples/catalog/', '').replace(/\.json$/, '');
- const isWebGL = slug.startsWith('webgl/');
+ const slug = slugOf(path);
return {
component: slug,
- label:
- isWebGL && catalog.component !== 'WebGL'
- ? `${catalog.component} (WebGL)`
- : catalog.component,
+ label: catalog.component,
category: componentCategoryMap.get(slug),
examples: catalog.examples.map((example) => ({
name: example.name,
title: example.title,
path: `/docs/components/${slug}/${example.name}`,
- createdAt: example.createdAt
+ createdAt: example.createdAt,
+ layers: exampleLayers(slug, catalog.component, example)
}))
};
})
- // Each WebGL component right after its LayerChart namesake
.sort((a, b) => a.label.localeCompare(b.label));
return {
@@ -62,3 +76,19 @@ export async function load() {
metadata
};
}
+
+/**
+ * The layers an example draws in, as its page's layer toggle offers them: those every component
+ * it uses can draw in, and `webgl` when it has a WebGL version. One written with
+ * `@layerchart/webgl` draws in a `WebGL` layer only.
+ */
+function exampleLayers(
+ slug: string,
+ component: string,
+ example: ComponentCatalog['examples'][number]
+): string[] {
+ const key = `${slug}/${example.name}`;
+ if (nativeWebGLExamples.has(key)) return ['webgl'];
+ const layers = intersectExampleLayers(example.components ?? [], componentLayers[component] ?? []);
+ return key in webglExamples ? [...layers, 'webgl'] : layers;
+}
diff --git a/docs/src/routes/docs/examples/+page.svelte b/docs/src/routes/docs/examples/+page.svelte
index 084b1d51a7..fd8381f955 100644
--- a/docs/src/routes/docs/examples/+page.svelte
+++ b/docs/src/routes/docs/examples/+page.svelte
@@ -1,5 +1,12 @@
-
-
diff --git a/docs/src/routes/docs/screenshot/webgl/[component]/[example]/+page.svelte b/docs/src/routes/docs/screenshot/webgl/[component]/[example]/+page.svelte
deleted file mode 100644
index 95e132ef0d..0000000000
--- a/docs/src/routes/docs/screenshot/webgl/[component]/[example]/+page.svelte
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- {component} - {example} - LayerChart Examples
-
-
-
-
-
diff --git a/docs/src/routes/docs/search/searchContent.ts b/docs/src/routes/docs/search/searchContent.ts
index e4643a0911..cae61aeac6 100644
--- a/docs/src/routes/docs/search/searchContent.ts
+++ b/docs/src/routes/docs/search/searchContent.ts
@@ -2,7 +2,8 @@ import { allComponents, allGuides, allUtils } from 'content-collections';
import type { ComponentCatalog } from '@layerstack/docs/catalog';
import { buildSearchEntries, type SearchEntry } from '@layerstack/docs/search';
-// Load all catalog JSON files (`webgl/` holds `@layerchart/webgl`'s)
+// Load all catalog JSON files (`webgl/` holds `@layerchart/webgl`'s, used for its own components,
+// ex. `Surface`: LayerChart's list every example of theirs, whichever package draws it)
const catalogModules = import.meta.glob('/src/examples/catalog/**/*.json', {
eager: true,
import: 'default'
@@ -11,17 +12,26 @@ const catalogModules = import.meta.glob('/src/examples/catalog
// Convert catalog entries to search entries
function catalogToEntries(): SearchEntry[] {
const entries: SearchEntry[] = [];
+ const core = new Set(
+ Object.entries(catalogModules)
+ .filter(([file]) => !file.includes('/catalog/webgl/'))
+ .map(([, catalog]) => catalog.component)
+ );
+ const pages = new Set(allComponents.map((c) => c.slug));
for (const [file, catalog] of Object.entries(catalogModules)) {
- // `@layerchart/webgl`'s examples are on its pages, `webgl/`
- const webgl = file.includes('/catalog/webgl/');
- const component = webgl ? `webgl/${catalog.component}` : catalog.component;
+ const component = catalog.component;
+ if (file.includes('/catalog/webgl/') && (core.has(component) || !pages.has(component))) {
+ continue;
+ }
for (const example of catalog.examples) {
+ // Drawn in a `WebGL` layer, found searching for it
+ const webgl = example.components?.some((usage) => usage.component === 'WebGL');
entries.push({
title: example.title,
- slug: webgl ? `docs/components/${component}/${example.name}` : example.path.slice(1), // Remove leading slash
+ slug: `docs/components/${component}/${example.name}`,
content: [
- catalog.component,
+ component,
webgl ? 'WebGL' : '',
example.name.replaceAll('-', ' '),
...(example.tags ?? [])
@@ -37,19 +47,6 @@ function catalogToEntries(): SearchEntry[] {
return entries;
}
-const WEBGL_PAGES = 'docs/components/webgl/';
-
-/**
- * `@layerchart/webgl`'s pages repeat LayerChart's names (ex. `Arc`), so their results (and their
- * sections' and examples') say they're WebGL's
- */
-function markWebGL(entry: SearchEntry): SearchEntry {
- const slug = entry.type === 'heading' ? entry.parentSlug : entry.slug;
- if (!slug?.startsWith(WEBGL_PAGES)) return entry;
- if (entry.type === 'heading') return { ...entry, parent: `${entry.parent} (WebGL)` };
- return { ...entry, title: `${entry.title} (WebGL)` };
-}
-
// Top-level documentation pages
const topLevelPages: SearchEntry[] = [
{
@@ -91,4 +88,4 @@ export const searchContent: SearchEntry[] = [
...catalogToEntries(),
...buildSearchEntries(allGuides, { type: 'guide', slugPrefix: 'docs/guides' }),
...buildSearchEntries(allUtils, { type: 'util', slugPrefix: 'docs/utils' })
-].map(markWebGL);
+];
diff --git a/docs/src/routes/og/[...path]/+server.ts b/docs/src/routes/og/[...path]/+server.ts
index abaa33abff..1745d4f6fb 100644
--- a/docs/src/routes/og/[...path]/+server.ts
+++ b/docs/src/routes/og/[...path]/+server.ts
@@ -64,9 +64,13 @@ function sentence(text: string) {
return words[0].toUpperCase() + words.slice(1);
}
+/** LayerChart's catalog of `slug`, else `@layerchart/webgl`'s (for its own, ex. `Surface`) */
async function catalogOf(slug: string) {
- const path = `/src/examples/catalog/${slug}.json`;
- return path in catalogs ? await catalogs[path]() : null;
+ const path = [
+ `/src/examples/catalog/${slug}.json`,
+ `/src/examples/catalog/webgl/${slug}.json`
+ ].find((path) => path in catalogs);
+ return path ? await catalogs[path]() : null;
}
/**
@@ -114,10 +118,8 @@ async function draw(path: string, load: Load): Promise {
example ? await screenshot(example.component, example.name, load) : null;
if (section === 'components') {
- // `webgl/Points` is `@layerchart/webgl`'s, whose names repeat LayerChart's
- const webgl = rest[0] === 'webgl';
- const [name, example] = webgl ? rest.slice(1) : rest;
- const slug = webgl ? `webgl/${name}` : name;
+ const [name, example] = rest;
+ const slug = name;
const component = allComponents.find((c) => c.slug === slug);
if (!component) return null;
@@ -127,14 +129,14 @@ async function draw(path: string, load: Load): Promise {
if (example && example !== 'examples') {
if (!catalog?.examples.some((e) => e.name === example)) return null;
return {
- eyebrow: `${webgl ? 'WebGL ' : ''}${title} example`,
+ eyebrow: `${title} example`,
title: sentence(example),
shot: await screenshot(slug, example, load)
};
}
const category = sentence(component.category ?? 'Component');
- const label = webgl ? `WebGL · ${category}` : category;
+ const label = category;
const lead =
firstExample(component.content, slug) ??
(catalog?.examples[0] ? { component: slug, name: catalog.examples[0].name } : null);
diff --git a/docs/src/routes/og/[...path]/screenshot.ts b/docs/src/routes/og/[...path]/screenshot.ts
index 29a76856f5..8f7f9bfe77 100644
--- a/docs/src/routes/og/[...path]/screenshot.ts
+++ b/docs/src/routes/og/[...path]/screenshot.ts
@@ -37,8 +37,7 @@ async function loadDecoder() {
}
/**
- * The dark theme screenshot of `component`'s `example` (ex. `AreaChart`, `basic`, or
- * `webgl/Points`, `basic`), or `null` when it has none. `load` fetches a static file by its path,
+ * The dark theme screenshot of `component`'s `example` (ex. `AreaChart`, `basic`), or `null` when it has none. `load` fetches a static file by its path,
* and `size` picks one of the widths `generate:screenshots` writes.
*/
export async function screenshot(
diff --git a/docs/src/webgl-examples.d.ts b/docs/src/webgl-examples.d.ts
new file mode 100644
index 0000000000..a5c124fa8d
--- /dev/null
+++ b/docs/src/webgl-examples.d.ts
@@ -0,0 +1,13 @@
+// LayerChart's examples drawn with WebGL (see `vite-plugin-webgl-examples.ts`)
+declare module 'virtual:webgl-examples' {
+ import type { Component } from 'svelte';
+
+ /** `/` (ex. `Points/basic`) to a loader of its WebGL version */
+ export const webglExamples: Record<
+ string,
+ () => Promise<{ component: Component; source: string }>
+ >;
+
+ /** `/` of the examples written with `@layerchart/webgl` (ex. `Points/galaxy`) */
+ export const nativeWebGLExamples: Set;
+}
diff --git a/docs/static/remote-sources.json b/docs/static/remote-sources.json
index 85f4fd0456..f2f24733bd 100644
--- a/docs/static/remote-sources.json
+++ b/docs/static/remote-sources.json
@@ -1,5 +1,5 @@
{
"data.remote.ts": "import { celsiusToFahrenheit } from 'layerchart';\nimport { parse, sortFunc } from '@layerstack/utils';\nimport { ascending, flatGroup, max, mean, min } from 'd3-array';\nimport { csvParse, csvParseRows, autoType } from 'd3-dsv';\n\nimport { prerender, getRequestEvent, query } from '$app/server';\nimport { z } from 'zod';\n\nimport type { PenguinsData } from '$static/data/examples/penguins.js';\nimport type { IrisData } from '$static/data/examples/iris.js';\nimport type { AppleStockData } from '$static/data/examples/date/apple-stock.js';\nimport type { USSenatorsData } from '$static/data/examples/us-senators';\nimport type { CivilizationTimeline } from '$static/data/examples/date/civilization-timeline.js';\nimport type { HydroData } from '$static/data/examples/date/hydro.js';\nimport type { AppleTickerData } from '$static/data/examples/date/apple-ticker.js';\nimport type { NewPassengerCars } from '$static/data/examples/new-passenger-cars.js';\n\nexport const getGroupData = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/group-data.json').then((r) => r.json())) as {\n\t\tx: number;\n\t\ty: number;\n\t\tgroup: string;\n\t}[];\n\treturn data;\n});\n\nexport const getAppleStock = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/date/apple-stock.json').then(async (r) =>\n\t\tparse(await r.text())\n\t);\n\treturn data;\n});\n\nexport const getAppleStockRange = query(\n\tz.object({\n\t\tstart: z.string().optional(),\n\t\tend: z.string().optional(),\n\t\tmaxPoints: z.number().optional().default(300)\n\t}),\n\tasync ({ start, end, maxPoints }) => {\n\t\tconst { fetch } = getRequestEvent();\n\t\tlet data = await fetch('/data/examples/date/apple-stock.json').then(async (r) =>\n\t\t\tparse(await r.text())\n\t\t);\n\n\t\tif (start || end) {\n\t\t\tconst startDate = start ? new Date(start) : undefined;\n\t\t\tconst endDate = end ? new Date(end) : undefined;\n\t\t\tdata = data.filter(\n\t\t\t\t(d) => (!startDate || d.date >= startDate) && (!endDate || d.date <= endDate)\n\t\t\t);\n\t\t}\n\n\t\tif (data.length > maxPoints) {\n\t\t\tconst step = (data.length - 1) / (maxPoints - 1);\n\t\t\tdata = Array.from({ length: maxPoints }, (_, i) => data![Math.round(i * step)]);\n\t\t}\n\n\t\treturn data;\n\t}\n);\n\nexport const getDailyTemperature = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/date/daily-temperature.json').then(async (r) =>\n\t\tparse<{ date: Date; value: number }[]>(await r.text())\n\t);\n\treturn data;\n});\n\nexport const getDailyTemperatures = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/dailyTemperatures.csv').then(async (r) => {\n\t\treturn csvParse<{ dayOfYear: number; year: number; value: number | 'NA' }>(\n\t\t\tawait r.text(),\n\t\t\t// @ts-expect-error - autoType\n\t\t\tautoType\n\t\t)\n\t\t\t.filter((d) => d.value !== 'NA' && d.dayOfYear <= 365 /* Ignore 366th day */)\n\t\t\t.map((d) => {\n\t\t\t\tconst origDate = new Date(d.year, 0, d.dayOfYear);\n\t\t\t\treturn {\n\t\t\t\t\t...d,\n\t\t\t\t\tdate: new Date(Date.UTC(2000, origDate.getUTCMonth(), origDate.getUTCDate())),\n\t\t\t\t\tvalue: d.value !== 'NA' ? celsiusToFahrenheit(d.value) : 'NA'\n\t\t\t\t};\n\t\t\t});\n\t});\n\treturn data;\n});\n\nexport const getSfoTemperatures = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/sfoTemperatures.csv').then(async (r) => {\n\t\treturn flatGroup(\n\t\t\t// @ts-expect-error - autoType\n\t\t\tcsvParse<{ date: Date; tavg: number; tmax: number; tmin: number }>(await r.text(), autoType),\n\t\t\t(d) => new Date(Date.UTC(2000, d.date.getUTCMonth(), d.date.getUTCDate())) // group by day of year\n\t\t)\n\t\t\t.sort(([a], [b]) => ascending(a, b)) // sort chronologically\n\t\t\t.map(([date, v]) => ({\n\t\t\t\tdate,\n\t\t\t\tavg: mean(v, (d) => d.tavg || NaN),\n\t\t\t\tmin: mean(v, (d) => d.tmin || NaN),\n\t\t\t\tmax: mean(v, (d) => d.tmax || NaN),\n\t\t\t\tminmin: min(v, (d) => d.tmin || NaN),\n\t\t\t\tmaxmax: max(v, (d) => d.tmax || NaN)\n\t\t\t}));\n\t});\n\treturn data;\n});\n\nexport const getPenguins = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/penguins.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as PenguinsData;\n\treturn data;\n});\n\nexport const getIris = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/iris.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as IrisData;\n\treturn data;\n});\n\nexport const getFlare = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/hierarchy/flare.json').then((r) => r.json());\n\treturn data;\n});\n\nexport const getSimpleTree = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/hierarchy/simple-tree.json').then((r) => r.json());\n\treturn data;\n});\n\nexport const getFlameGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\t// \"folded\"/\"collapsed\" stacks — the de-facto profiler interchange format. Parsed into a\n\t// hierarchy in the example via `parseFoldedStacks()`.\n\tconst data = await fetch('/data/examples/hierarchy/flame-graph.folded.txt').then((r) => r.text());\n\treturn data;\n});\n\nexport type TraceSpan = { name: string; start: number; duration: number; children?: TraceSpan[] };\n\nexport const getRequestTrace = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\t// A traced (not sampled) profile — nested spans with real start/duration times, including\n\t// idle gaps. Rendered as a time-based flame chart.\n\tconst data = (await fetch('/data/examples/hierarchy/request-trace.json').then((r) =>\n\t\tr.json()\n\t)) as TraceSpan;\n\treturn data;\n});\n\nexport type MetroData = {\n\tMetro: string;\n\tPOP_1980: number;\n\tLPOP_1980: number;\n\tR90_10_1980: number;\n\tPOP_2015: number;\n\tLPOP_2015: number;\n\tR90_10_2015: number;\n\tnyt_display: string;\n\tstate_display: string;\n\thighlight: number;\n};\n\nexport const getMetros = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = csvParse(\n\t\tawait (await fetch('/data/examples/metros.csv')).text(),\n\t\tautoType\n\t) as unknown as MetroData[];\n\treturn data;\n});\n\nexport const getUsSenators = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/us-senators.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as USSenatorsData;\n\treturn data;\n});\n\nexport type UsPresident = {\n\tname: string;\n\tinaugurationDate: Date;\n\tportraitUrl: string;\n\tveryFavorable: number;\n\tveryUnfavorable: number;\n};\n\nexport const getUsPresidents = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/us-presidents.csv').then(async (r) => {\n\t\tconst rows = csvParse(await r.text(), autoType) as Array>;\n\t\treturn rows.map(\n\t\t\t(d) =>\n\t\t\t\t({\n\t\t\t\t\tname: d['Name'],\n\t\t\t\t\tinaugurationDate: d['First Inauguration Date'],\n\t\t\t\t\tportraitUrl: d['Portrait URL'],\n\t\t\t\t\tveryFavorable: d['Very Favorable %'],\n\t\t\t\t\tveryUnfavorable: d['Very Unfavorable %']\n\t\t\t\t}) satisfies UsPresident\n\t\t);\n\t});\n\treturn data;\n});\n\nexport const getAlphabet = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/alphabet.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { letter: string; frequency: number }[];\n\treturn data;\n});\n\nexport const getOlympians = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/olympians.json').then((r) => r.json())) as {\n\t\tname: string;\n\t\tnationality: string;\n\t\tsex: 'male' | 'female';\n\t\tdate_of_birth: string;\n\t\tweight: number;\n\t\theight: number;\n\t\tsport: string;\n\t\tgold: number;\n\t\tsilver: number;\n\t\tbronze: number;\n\t}[];\n\treturn data;\n});\n\nexport const getUsEvents = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/date/us-events.csv').then(async (r) => {\n\t\treturn csvParse(await r.text(), autoType).map((d: any) => {\n\t\t\treturn {\n\t\t\t\tstartDate: new Date(d.startYear, 0, 1),\n\t\t\t\tendDate: new Date(d.endYear, 11, 31),\n\t\t\t\tevent: d.event\n\t\t\t};\n\t\t});\n\t});\n\treturn data;\n});\n\nexport const getCivilizationEvents = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/date/civilization-timeline.csv').then(async (r) => {\n\t\treturn csvParse(\n\t\t\tawait r.text(),\n\t\t\t// @ts-expect-error - shh\n\t\t\tautoType\n\t\t).sort(sortFunc('start'));\n\t});\n\n\treturn data;\n});\n\nexport type SvelteCount = {\n\tdate: Date;\n\tn: number;\n\tcumsum: number;\n\tcategory: 'svelte' | 'sveltekit';\n};\n\nexport const getSvelteCounts = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/date/svelte-counts.csv').then(async (r) =>\n\t\t// @ts-expect-error - autoType\n\t\tcsvParse(await r.text(), autoType)\n\t);\n\treturn data;\n});\n\nexport type SvelteMilestone = {\n\tdate: Date;\n\tcategory: 'svelte' | 'sveltekit' | 'ecosystem';\n\tlabel: string;\n\t/** Pixel x-offset of the label from the dot (calibrated for an 860px-wide chart). */\n\tdx: number;\n\t/** Pixel y-offset of the label from the dot (calibrated for an 860px-wide chart). */\n\tdy: number;\n};\n\nexport const getSvelteMilestones = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/date/svelte-milestones.csv').then(async (r) =>\n\t\t// @ts-expect-error - autoType\n\t\tcsvParse(await r.text(), autoType)\n\t);\n\treturn data;\n});\n\nexport const getAppleTicker = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/date/apple-ticker.json').then(async (r) =>\n\t\tparse(await r.text())\n\t);\n\treturn data;\n});\n\nexport const getCars = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/cars.csv').then(async (r) =>\n\t\t// @ts-expect-error - shh\n\t\tcsvParse(await r.text(), autoType)\n\t);\n\treturn data;\n});\n\nexport const getNewPassengerCars = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/new-passenger-cars.csv').then(async (r) =>\n\t\t// @ts-expect-error - shh\n\t\tcsvParse(await r.text(), autoType)\n\t);\n\treturn data;\n});\n\nexport const getHydro = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/date/hydro.json').then(async (r) =>\n\t\tparse(await r.text())\n\t)) as HydroData;\n\treturn data;\n});\n\nexport type Country2020 = {\n\tname: string;\n\tcode: string;\n\tcode2: string;\n\tlifeExpectancy: number;\n\tgdpPerCapita: number;\n\tpopulation: number;\n\tcontinent: string;\n};\n\nexport const getCountries2020 = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst text = await fetch('/data/examples/countries_2020.csv').then((r) => r.text());\n\tconst rows = csvParse(text, autoType) as Array>;\n\treturn rows.map(\n\t\t(d): Country2020 => ({\n\t\t\tname: d.Entity,\n\t\t\tcode: d.Code,\n\t\t\tcode2: d.Code2,\n\t\t\tlifeExpectancy: d['Life expectancy'],\n\t\t\tgdpPerCapita: d['GDP per capita'],\n\t\t\tpopulation: d.Population,\n\t\t\tcontinent: d.Continent\n\t\t})\n\t);\n});\n\nexport type BankFailure = {\n\tname: string;\n\tfailDate: Date;\n\tassets: number; // in $thousands (FDIC reporting unit)\n\tdeposits: number;\n\tcity: string;\n\tstate: string;\n\tcost: number | null;\n\ttype: string;\n};\n\nexport const getBankFailures = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst text = await fetch('/data/examples/bank-failures.csv').then((r) => r.text());\n\tconst rows = csvParse(text) as Array>;\n\treturn rows\n\t\t.map((d): BankFailure => {\n\t\t\tconst [m, day, y] = d.FAILDATE.split('/').map((s) => Number(s));\n\t\t\treturn {\n\t\t\t\tname: d.NAME,\n\t\t\t\tfailDate: new Date(Date.UTC(y, m - 1, day)),\n\t\t\t\tassets: Number(d.QBFASSET) || 0,\n\t\t\t\tdeposits: Number(d.QBFDEP) || 0,\n\t\t\t\tcity: d.CITY,\n\t\t\t\tstate: d.PSTALP,\n\t\t\t\tcost: d.COST ? Number(d.COST) : null,\n\t\t\t\ttype: d.RESTYPE\n\t\t\t};\n\t\t})\n\t\t.filter((d) => Number.isFinite(d.failDate.getTime()) && d.assets > 0);\n});\n\nexport type Layoff = {\n\tcompany: string;\n\tlocation: string;\n\ttotalLaidOff: number | null;\n\tdate: Date;\n\tpercentageLaidOff: number | null;\n\tindustry: string;\n\tstage: string;\n\tfundsRaised: number | null;\n\tcountry: string;\n};\n\nexport const getLayoffs = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst text = await fetch('/data/examples/layoffs.csv').then((r) => r.text());\n\tconst rows = csvParse(text) as Array>;\n\treturn rows\n\t\t.map((d): Layoff | null => {\n\t\t\tif (!d.date) return null;\n\t\t\tconst [m, day, y] = d.date.split('/').map((s) => Number(s));\n\t\t\tif (!y) return null;\n\t\t\treturn {\n\t\t\t\tcompany: d.company,\n\t\t\t\tlocation: d.location,\n\t\t\t\ttotalLaidOff: d.total_laid_off ? Number(d.total_laid_off) : null,\n\t\t\t\tdate: new Date(Date.UTC(y, m - 1, day)),\n\t\t\t\tpercentageLaidOff: d.percentage_laid_off ? Number(d.percentage_laid_off) : null,\n\t\t\t\tindustry: d.industry,\n\t\t\t\tstage: d.stage,\n\t\t\t\tfundsRaised: d.funds_raised ? Number(d.funds_raised) : null,\n\t\t\t\tcountry: d.country\n\t\t\t};\n\t\t})\n\t\t.filter((d): d is Layoff => d !== null);\n});\n\nexport type GamesLayoff = {\n\tstudio: string;\n\tdate: Date;\n\theadcount: number | null;\n\tparent: string;\n\ttype: string;\n\tstudioLocation: string;\n\tparentLocation: string;\n};\n\nexport const getGamesLayoffs = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst text = await fetch('/data/examples/games-layoffs.csv').then((r) => r.text());\n\tconst rows = csvParse(text) as Array>;\n\treturn rows\n\t\t.map((d): GamesLayoff | null => {\n\t\t\tif (!d.Date) return null;\n\t\t\treturn {\n\t\t\t\tstudio: d.Studio,\n\t\t\t\tdate: new Date(d.Date),\n\t\t\t\theadcount: d.Headcount ? Number(d.Headcount) : null,\n\t\t\t\tparent: d.Parent,\n\t\t\t\ttype: d.Type,\n\t\t\t\tstudioLocation: d['Studio Location'],\n\t\t\t\tparentLocation: d['Parent Location']\n\t\t\t};\n\t\t})\n\t\t.filter((d): d is GamesLayoff => d !== null && Number.isFinite(d.date.getTime()));\n});\n\nexport const getForceGroupDots = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/force-group-dots.json').then((r) => r.json())) as {\n\t\tcategory: string;\n\t\tvalue: number;\n\t}[];\n\treturn data;\n});\n\nexport const getWideData = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/bench/wide_data/data.json').then((r) => r.json())) as {\n\t\tepoch: number;\n\t\tidl: number;\n\t\trecv: number;\n\t\tsend: number;\n\t\twrit: number;\n\t\tused: number;\n\t\tfree: number;\n\t}[];\n\treturn data;\n});\n\nexport const getDimensionArrays = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/bench/dimension_arrays/data.json').then((r) =>\n\t\tr.json()\n\t)) as {\n\t\tdate: number[];\n\t\tcpu: number[];\n\t\tram: number[];\n\t\ttcp: number[];\n\t};\n\treturn data;\n});\n\nexport const getSeriesArrays = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/bench/series_arrays/data.json').then((r) =>\n\t\tr.json()\n\t)) as {\n\t\tcpu: {\n\t\t\tx: Date;\n\t\t\ty: number;\n\t\t}[];\n\t\tram: {\n\t\t\tx: Date;\n\t\t\ty: number;\n\t\t}[];\n\t\ttcp: {\n\t\t\tx: Date;\n\t\t\ty: number;\n\t\t}[];\n\t};\n\treturn data;\n});\n\nexport type VolcanoData = {\n\twidth: number;\n\theight: number;\n\tvalues: number[];\n};\n\nexport const getVolcano = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/volcano.json').then((r) => r.json())) as VolcanoData;\n\treturn data;\n});\n\nexport type WaterVaporData = {\n\twidth: number;\n\theight: number;\n\tvalues: number[];\n};\n\nexport const getWaterVapor = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst rows = csvParseRows(\n\t\tawait fetch('/data/examples/geo/water-vapor.csv').then((r) => r.text())\n\t);\n\treturn {\n\t\twidth: rows[0]?.length ?? 0,\n\t\theight: rows.length,\n\t\tvalues: rows.flat().map((value) => (value === '99999.0' ? NaN : +value))\n\t} satisfies WaterVaporData;\n});\n\nexport type FaithfulData = { eruptions: number; waiting: number };\n\nexport const getFaithful = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/faithful.json').then((r) =>\n\t\tr.json()\n\t)) as FaithfulData[];\n\treturn data;\n});\n\nexport type CategoryBrand = {\n\tdate: Date;\n\tname: string;\n\tcategory: string;\n\tvalue: number;\n};\n\nexport const getCategoryBrands = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/category-brands.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as unknown as CategoryBrand[];\n\n\t// Ensure dates are Date objects\n\tfor (const d of data) {\n\t\td.date = new Date(d.date as unknown as string);\n\t}\n\n\treturn data;\n});\n\nexport type ProgrammingLanguage = {\n\tdate: Date;\n\tname: string;\n\tvalue: number;\n};\n\nexport const getProgrammingLanguages = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/programming-languages.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as unknown as ProgrammingLanguage[];\n\n\tfor (const d of data) {\n\t\td.date = new Date(d.date as unknown as string);\n\t}\n\n\treturn data;\n});\n\nexport type TdfStageData = { long: number; lat: number; elev: number }[];\n\nexport const getTdfStage = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/tdf-stage.json').then((r) =>\n\t\tr.json()\n\t)) as TdfStageData;\n\treturn data;\n});\n",
- "geo.remote.ts": "import { prerender, getRequestEvent } from '$app/server';\nimport { z } from 'zod';\n\nimport type { GeometryCollection, Topology } from 'topojson-specification';\nimport { geoCentroid } from 'd3-geo';\nimport { csvParse, autoType } from 'd3-dsv';\nimport { parse } from '@layerstack/utils';\n\nimport type { USStateCapitalsData } from '$static/data/examples/geo/us-state-capitals.js';\nimport type { WorldLinksData } from '$static/data/examples/geo/world-links.js';\nimport type { Admin0Topology, Admin1Topology } from '$static/data/examples/geo/admin.js';\nimport admin1Countries from '$static/data/examples/geo/admin1/countries.json';\nimport populationStates from '$static/data/examples/geo/kontur-population/states.json';\n\nexport const getUsStatesTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('https://cdn.jsdelivr.net/npm/us-atlas@3/states-10m.json').then((r) =>\n\t\tr.json()\n\t)) as Topology<{\n\t\tstates: GeometryCollection<{ name: string }>;\n\t\tnation: GeometryCollection;\n\t}>;\n\treturn data;\n});\n\nexport const getUsCountiesTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('https://cdn.jsdelivr.net/npm/us-atlas@3/counties-10m.json').then((r) =>\n\t\tr.json()\n\t)) as Topology<{\n\t\tstates: GeometryCollection<{ name: string }>;\n\t\tcounties: GeometryCollection<{ name: string }>;\n\t}>;\n\treturn data;\n});\n\nexport const getUsCountiesAlbersTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch(\n\t\t'https://cdn.jsdelivr.net/npm/us-atlas@3/counties-albers-10m.json'\n\t).then((r) => r.json())) as Topology<{\n\t\tstates: GeometryCollection<{ name: string }>;\n\t\tcounties: GeometryCollection<{ name: string }>;\n\t}>;\n\treturn data;\n});\n\nexport const getCountriesTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst geojson = (await fetch(\n\t\t'https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json'\n\t).then((r) => r.json())) as Topology<{\n\t\tcountries: GeometryCollection<{ name: string }>;\n\t\tland: GeometryCollection;\n\t}>;\n\treturn geojson;\n});\n\nexport const getCountriesDetailTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst geojson = (await fetch(\n\t\t'https://cdn.jsdelivr.net/npm/world-atlas@2/countries-50m.json'\n\t).then((r) => r.json())) as Topology<{\n\t\tcountries: GeometryCollection<{ name: string }>;\n\t\tland: GeometryCollection;\n\t}>;\n\treturn geojson;\n});\n\n/**\n * Points about 0.5° apart over the whole sphere (closer in longitude toward the poles, to stay even)\n * that fall on land — for binning into cells that fill wherever there is land. Tested once against\n * world-atlas' 110m `land` with `geoContains` (each landmass' `geoBounds` first), as it takes a while.\n */\nexport const getWorldLandPoints = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-land-points.json').then((r) => r.json())) as [\n\t\tlongitude: number,\n\t\tlatitude: number\n\t][];\n\treturn data;\n});\n\n/**\n * People in each 15′ (0.25°) cell of the contiguous US in 2020, as `[longitude, latitude, count]` at\n * the cell's center — cells inside a state with anyone in them.\n *\n * From CIESIN's Gridded Population of the World, Version 4 (GPWv4): Population Count, Revision 11\n * (NASA SEDAC, 2018, https://doi.org/10.7927/H4JW8BX5), CC BY 4.0.\n */\nexport const getUsPopulationGrid = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-population-grid.json').then((r) =>\n\t\tr.json()\n\t)) as [longitude: number, latitude: number, count: number][];\n\treturn data;\n});\n\n/**\n * People in each 1° cell of the world in 2020, as `[longitude, latitude, count]` at the cell's\n * center — GPWv4's 15′ counts summed, cells with anyone in them.\n *\n * From CIESIN's Gridded Population of the World, Version 4 (GPWv4): Population Count, Revision 11\n * (NASA SEDAC, 2018, https://doi.org/10.7927/H4JW8BX5), CC BY 4.0.\n */\nexport const getWorldPopulationGrid = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-population-grid.json').then((r) =>\n\t\tr.json()\n\t)) as [longitude: number, latitude: number, count: number][];\n\treturn data;\n});\n\nexport const getEclipses = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/eclipses.json').then(async (r) =>\n\t\tparse(await r.text())\n\t)) as Topology<{\n\t\teclipses: GeometryCollection<{ ID: string; Date: Date }>;\n\t}>;\n\treturn data;\n});\n\nexport const getSubmarineCables = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/geo/submarine-cables.json').then((r) => r.json());\n\treturn data;\n});\n\nexport const getSubmarineCablesLandingPoints = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/geo/submarine-cables-landing-points.json').then((r) =>\n\t\tr.json()\n\t);\n\treturn data;\n});\n\nexport const getTectonicPlates = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch(\n\t\t'https://raw.githubusercontent.com/fraxen/tectonicplates/master/GeoJSON/PB2002_boundaries.json'\n\t).then((r) => r.json());\n\treturn data;\n});\n\nexport const getEarthquakes = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch(\n\t\t'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson'\n\t)\n\t\t.then((r) => r.json())\n\t\t.then((d: GeoJSON.FeatureCollection) =>\n\t\t\td.features.map((f) => {\n\t\t\t\tconst c = geoCentroid(f);\n\t\t\t\treturn {\n\t\t\t\t\tplace: f.properties.place,\n\t\t\t\t\tmagnitude: f.properties.mag,\n\t\t\t\t\tlongitude: c[0],\n\t\t\t\t\tlatitude: c[1]\n\t\t\t\t};\n\t\t\t})\n\t\t);\n\treturn data;\n});\n\nexport const getTimezones = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/timezones.json').then((r) =>\n\t\tr.json()\n\t)) as Topology<{\n\t\ttimezones: GeometryCollection<{\n\t\t\tobjectid: number;\n\t\t\tscalerank: number;\n\t\t\tfeaturecla: string;\n\t\t\tname: string;\n\t\t\tmap_color6: number;\n\t\t\tmap_color8: number;\n\t\t\tnote: any;\n\t\t\tzone: number;\n\t\t\tutc_format: string;\n\t\t\ttime_zone: string;\n\t\t\tiso_8601: string;\n\t\t\tplaces: string;\n\t\t\tdst_places: any;\n\t\t\ttz_name1st: any;\n\t\t\ttz_namesum: number;\n\t\t}>;\n\t}>;\n\treturn data;\n});\n\nexport const getUsCapitals = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-state-capitals.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as USStateCapitalsData;\n\treturn data;\n});\n\nexport const getUsAirports = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-airports.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { name: string; latitude: number; longitude: number }[];\n\treturn data;\n});\n\nexport const getWalmarts = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst raw = (await fetch('/data/examples/geo/walmarts.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { long: number; lat: number; opendate: Date; city: string; state: string; type: string }[];\n\tconst data = raw.map((d) => ({\n\t\tlongitude: d.long,\n\t\tlatitude: d.lat,\n\t\tdate: d.opendate,\n\t\tcity: d.city,\n\t\tstate: d.state,\n\t\ttype: d.type\n\t}));\n\treturn data;\n});\n\nexport const getUsCountyPopulation = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-county-population-2020.json').then((r) =>\n\t\tr.json()\n\t)) as Array<{\n\t\tstate: string;\n\t\tcounty: string;\n\t\tDP05_0001E: string;\n\t\tDP05_0019E: string;\n\t\tDP05_0019PE: string;\n\t}>;\n\treturn data;\n});\n\nexport const getUsPresidentialElection2020 = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-presidential-election-2020.csv').then(\n\t\tasync (r) => csvParse(await r.text(), autoType)\n\t)) as Array<{\n\t\tstate_name: string;\n\t\tcounty_fips: number;\n\t\tcounty_name: string;\n\t\tvotes_gop: number;\n\t\tvotes_dem: number;\n\t\ttotal_votes: number;\n\t\tdiff: number;\n\t\tper_gop: number;\n\t\tper_dem: number;\n\t\tper_point_diff: number;\n\t}>;\n\treturn data;\n});\n\nexport const getWind = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/wind.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as Array<{\n\t\tlongitude: number;\n\t\tlatitude: number;\n\t\tu: number;\n\t\tv: number;\n\t}>;\n\treturn data;\n});\n\nexport const getWorldCapitals = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-capitals.json').then(async (r) =>\n\t\tr.json()\n\t)) as { label: string; latitude: number; longitude: number }[];\n\treturn data;\n});\n\nexport const getWorldAirports = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-airports.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { name: string; latitude: number; longitude: number }[];\n\treturn data;\n});\n\nexport const getD1FootballTeams = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/d1-football-teams.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as {\n\t\tteam: string;\n\t\tcollege: string;\n\t\tconference: string;\n\t\tcity: string;\n\t\tstate: string;\n\t\tlatitude: number;\n\t\tlongitude: number;\n\t\tespn_id: number;\n\t}[];\n\treturn data;\n});\n\nexport const getBeagleVoyage = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/beagle-voyage.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { longitude: number; latitude: number }[];\n\treturn data;\n});\n\nexport const getWorldLinks = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-links.json').then((r) =>\n\t\tr.json()\n\t)) as WorldLinksData;\n\treturn data;\n});\n\n/**\n * Every country, merged from Natural Earth's 10m admin-1 states and provinces (public domain) by\n * `scripts/natural-earth-admin.mjs`, so its borders line up with `getAdmin1Topology`'s.\n */\nexport const getAdmin0Topology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/admin0.json').then((r) =>\n\t\tr.json()\n\t)) as Admin0Topology;\n\treturn data;\n});\n\n/**\n * One country's admin-1 states and provinces (by its `adm0_a3`, e.g. \"ITA\"), with its `regions`\n * where Natural Earth's admin-1 is the second level down.\n */\nexport const getAdmin1Topology = prerender(\n\tz.string(),\n\tasync (country) => {\n\t\tconst { fetch } = getRequestEvent();\n\t\tconst data = (await fetch(`/data/examples/geo/admin1/${country}.json`).then((r) =>\n\t\t\tr.json()\n\t\t)) as Admin1Topology;\n\t\treturn data;\n\t},\n\t{ inputs: () => admin1Countries }\n);\n\n/**\n * The people living in one US state (by its file, ex. `west-virginia`, as `getPopulationStates`\n * lists them), as `[longitude, latitude, people]` in cells of about 160 across the state, and its\n * largest places to label as `[name, longitude, latitude]`.\n *\n * From Kontur Population (November 2023, CC BY 4.0, https://data.humdata.org/dataset/kontur-population-united-states-of-america),\n * its 400m H3 hexagons summed into the cells and clipped to us-atlas' 1:10m state outlines, and\n * Natural Earth's populated places (public domain). Built by `scripts/kontur-population.mjs`.\n */\nexport const getStatePopulation = prerender(\n\tz.string().regex(/^[a-z-]+$/),\n\tasync (state) => {\n\t\tconst { fetch } = getRequestEvent();\n\t\t// Stored as whole steps from the state's southwest corner, `[i, j, people]` flattened\n\t\tconst { origin, step, cells, cities } = (await fetch(\n\t\t\t`/data/examples/geo/kontur-population/${state}.json`\n\t\t).then((r) => r.json())) as {\n\t\t\torigin: [number, number];\n\t\t\tstep: [number, number];\n\t\t\tcells: number[];\n\t\t\tcities: [name: string, longitude: number, latitude: number][];\n\t\t};\n\t\tconst data: [longitude: number, latitude: number, people: number][] = [];\n\t\tfor (let k = 0; k < cells.length; k += 3) {\n\t\t\tdata.push([origin[0] + cells[k] * step[0], origin[1] + cells[k + 1] * step[1], cells[k + 2]]);\n\t\t}\n\t\treturn { cells: data, cities };\n\t},\n\t{ inputs: () => populationStates.map((s) => s.value) }\n);\n\n/** The states `getStatePopulation` has, alphabetically: their files (`value`) and names */\nexport const getPopulationStates = prerender(async () => populationStates);\n\n/**\n * Lower Manhattan's buildings: footprints, with heights in meters where they're tagged (or 3.5m a\n * floor where only floors are), and names.\n *\n * From OpenStreetMap (© OpenStreetMap contributors, ODbL), fetched through the Overpass API in\n * October 2026.\n */\nexport const getLowerManhattanBuildings = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/lower-manhattan-buildings.json').then((r) =>\n\t\tr.json()\n\t)) as import('geojson').FeatureCollection<\n\t\timport('geojson').Polygon,\n\t\t{ height: number | null; name: string | null }\n\t>;\n\treturn data;\n});\n",
+ "geo.remote.ts": "import { prerender, getRequestEvent } from '$app/server';\nimport { z } from 'zod';\n\nimport type { GeometryCollection, Topology } from 'topojson-specification';\nimport { geoCentroid } from 'd3-geo';\nimport { csvParse, autoType } from 'd3-dsv';\nimport { parse } from '@layerstack/utils';\n\nimport type { USStateCapitalsData } from '$static/data/examples/geo/us-state-capitals.js';\nimport type { WorldLinksData } from '$static/data/examples/geo/world-links.js';\nimport type { Admin0Topology, Admin1Topology } from '$static/data/examples/geo/admin.js';\nimport admin1Countries from '$static/data/examples/geo/admin1/countries.json';\nimport populationStates from '$static/data/examples/geo/kontur-population/states.json';\n\nexport const getUsStatesTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('https://cdn.jsdelivr.net/npm/us-atlas@3/states-10m.json').then((r) =>\n\t\tr.json()\n\t)) as Topology<{\n\t\tstates: GeometryCollection<{ name: string }>;\n\t\tnation: GeometryCollection;\n\t}>;\n\treturn data;\n});\n\nexport const getUsCountiesTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('https://cdn.jsdelivr.net/npm/us-atlas@3/counties-10m.json').then((r) =>\n\t\tr.json()\n\t)) as Topology<{\n\t\tstates: GeometryCollection<{ name: string }>;\n\t\tcounties: GeometryCollection<{ name: string }>;\n\t}>;\n\treturn data;\n});\n\nexport const getUsCountiesAlbersTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch(\n\t\t'https://cdn.jsdelivr.net/npm/us-atlas@3/counties-albers-10m.json'\n\t).then((r) => r.json())) as Topology<{\n\t\tstates: GeometryCollection<{ name: string }>;\n\t\tcounties: GeometryCollection<{ name: string }>;\n\t}>;\n\treturn data;\n});\n\nexport const getCountriesTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst geojson = (await fetch(\n\t\t'https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json'\n\t).then((r) => r.json())) as Topology<{\n\t\tcountries: GeometryCollection<{ name: string }>;\n\t\tland: GeometryCollection;\n\t}>;\n\treturn geojson;\n});\n\nexport const getCountriesDetailTopology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst geojson = (await fetch(\n\t\t'https://cdn.jsdelivr.net/npm/world-atlas@2/countries-50m.json'\n\t).then((r) => r.json())) as Topology<{\n\t\tcountries: GeometryCollection<{ name: string }>;\n\t\tland: GeometryCollection;\n\t}>;\n\treturn geojson;\n});\n\n/**\n * Points about 0.5° apart over the whole sphere (closer in longitude toward the poles, to stay even)\n * that fall on land — for binning into cells that fill wherever there is land. Tested once against\n * world-atlas' 110m `land` with `geoContains` (each landmass' `geoBounds` first), as it takes a while.\n */\nexport const getWorldLandPoints = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-land-points.json').then((r) => r.json())) as [\n\t\tlongitude: number,\n\t\tlatitude: number\n\t][];\n\treturn data;\n});\n\n/**\n * People in each 15′ (0.25°) cell of the contiguous US in 2020, as `[longitude, latitude, count]` at\n * the cell's center — cells inside a state with anyone in them.\n *\n * From CIESIN's Gridded Population of the World, Version 4 (GPWv4): Population Count, Revision 11\n * (NASA SEDAC, 2018, https://doi.org/10.7927/H4JW8BX5), CC BY 4.0.\n */\nexport const getUsPopulationGrid = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-population-grid.json').then((r) =>\n\t\tr.json()\n\t)) as [longitude: number, latitude: number, count: number][];\n\treturn data;\n});\n\n/**\n * People in each 1° cell of the world in 2020, as `[longitude, latitude, count]` at the cell's\n * center — GPWv4's 15′ counts summed, cells with anyone in them.\n *\n * From CIESIN's Gridded Population of the World, Version 4 (GPWv4): Population Count, Revision 11\n * (NASA SEDAC, 2018, https://doi.org/10.7927/H4JW8BX5), CC BY 4.0.\n */\nexport const getWorldPopulationGrid = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-population-grid.json').then((r) =>\n\t\tr.json()\n\t)) as [longitude: number, latitude: number, count: number][];\n\treturn data;\n});\n\nexport const getEclipses = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/eclipses.json').then(async (r) =>\n\t\tparse(await r.text())\n\t)) as Topology<{\n\t\teclipses: GeometryCollection<{ ID: string; Date: Date }>;\n\t}>;\n\treturn data;\n});\n\nexport const getSubmarineCables = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/geo/submarine-cables.json').then((r) => r.json());\n\treturn data;\n});\n\nexport const getSubmarineCablesLandingPoints = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch('/data/examples/geo/submarine-cables-landing-points.json').then((r) =>\n\t\tr.json()\n\t);\n\treturn data;\n});\n\nexport const getTectonicPlates = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch(\n\t\t'https://raw.githubusercontent.com/fraxen/tectonicplates/master/GeoJSON/PB2002_boundaries.json'\n\t).then((r) => r.json());\n\treturn data;\n});\n\nexport const getEarthquakes = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = await fetch(\n\t\t'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson'\n\t)\n\t\t.then((r) => r.json())\n\t\t.then((d: GeoJSON.FeatureCollection) =>\n\t\t\td.features.map((f) => {\n\t\t\t\tconst c = geoCentroid(f);\n\t\t\t\treturn {\n\t\t\t\t\tplace: f.properties.place,\n\t\t\t\t\tmagnitude: f.properties.mag,\n\t\t\t\t\tlongitude: c[0],\n\t\t\t\t\tlatitude: c[1]\n\t\t\t\t};\n\t\t\t})\n\t\t);\n\treturn data;\n});\n\nexport const getTimezones = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/timezones.json').then((r) =>\n\t\tr.json()\n\t)) as Topology<{\n\t\ttimezones: GeometryCollection<{\n\t\t\tobjectid: number;\n\t\t\tscalerank: number;\n\t\t\tfeaturecla: string;\n\t\t\tname: string;\n\t\t\tmap_color6: number;\n\t\t\tmap_color8: number;\n\t\t\tnote: any;\n\t\t\tzone: number;\n\t\t\tutc_format: string;\n\t\t\ttime_zone: string;\n\t\t\tiso_8601: string;\n\t\t\tplaces: string;\n\t\t\tdst_places: any;\n\t\t\ttz_name1st: any;\n\t\t\ttz_namesum: number;\n\t\t}>;\n\t}>;\n\treturn data;\n});\n\nexport const getUsCapitals = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-state-capitals.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as USStateCapitalsData;\n\treturn data;\n});\n\nexport const getUsAirports = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-airports.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { name: string; latitude: number; longitude: number }[];\n\treturn data;\n});\n\nexport const getWalmarts = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst raw = (await fetch('/data/examples/geo/walmarts.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { long: number; lat: number; opendate: Date; city: string; state: string; type: string }[];\n\tconst data = raw.map((d) => ({\n\t\tlongitude: d.long,\n\t\tlatitude: d.lat,\n\t\tdate: d.opendate,\n\t\tcity: d.city,\n\t\tstate: d.state,\n\t\ttype: d.type\n\t}));\n\treturn data;\n});\n\nexport const getUsCountyPopulation = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-county-population-2020.json').then((r) =>\n\t\tr.json()\n\t)) as Array<{\n\t\tstate: string;\n\t\tcounty: string;\n\t\tDP05_0001E: string;\n\t\tDP05_0019E: string;\n\t\tDP05_0019PE: string;\n\t}>;\n\treturn data;\n});\n\nexport const getUsPresidentialElection2020 = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/us-presidential-election-2020.csv').then(\n\t\tasync (r) => csvParse(await r.text(), autoType)\n\t)) as Array<{\n\t\tstate_name: string;\n\t\tcounty_fips: number;\n\t\tcounty_name: string;\n\t\tvotes_gop: number;\n\t\tvotes_dem: number;\n\t\ttotal_votes: number;\n\t\tdiff: number;\n\t\tper_gop: number;\n\t\tper_dem: number;\n\t\tper_point_diff: number;\n\t}>;\n\treturn data;\n});\n\nexport const getWind = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/wind.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as Array<{\n\t\tlongitude: number;\n\t\tlatitude: number;\n\t\tu: number;\n\t\tv: number;\n\t}>;\n\treturn data;\n});\n\nexport const getWorldCapitals = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-capitals.json').then(async (r) =>\n\t\tr.json()\n\t)) as { label: string; latitude: number; longitude: number }[];\n\treturn data;\n});\n\nexport const getWorldAirports = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-airports.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { name: string; latitude: number; longitude: number }[];\n\treturn data;\n});\n\nexport const getD1FootballTeams = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/d1-football-teams.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as {\n\t\tteam: string;\n\t\tcollege: string;\n\t\tconference: string;\n\t\tcity: string;\n\t\tstate: string;\n\t\tlatitude: number;\n\t\tlongitude: number;\n\t\tespn_id: number;\n\t}[];\n\treturn data;\n});\n\n/** `cfb` is Division I college football (FBS and FCS), `cfb2` and `cfb3` Divisions II and III */\nexport type SportsLeague =\n\t| 'mlb'\n\t| 'nfl'\n\t| 'nba'\n\t| 'nhl'\n\t| 'wnba'\n\t| 'cfb'\n\t| 'cfb2'\n\t| 'cfb3'\n\t| 'cbb'\n\t| 'wcbb';\n\nexport type SportsTeam = {\n\tleague: SportsLeague;\n\t/** ESPN team id (a college's is the same in every sport) */\n\tid: number;\n\tname: string;\n\tshort_name: string;\n\tabbreviation: string;\n\t/** College football only (`FBS` or `FCS`) */\n\tsubdivision: string | null;\n\tconference: string;\n\t/** Pro leagues only */\n\tdivision: string | null;\n\t/** College's name (ex. \"University of Florida\") */\n\tcampus: string | null;\n\tvenue: string | null;\n\tcity: string | null;\n\t/** State or province code (ex. `TX`, `ON`) */\n\tstate: string;\n\t/** Campus (college) or venue (pro) location */\n\tlatitude: number;\n\tlongitude: number;\n\t/** Primary brand color */\n\tcolor: string;\n\talt_color: string;\n\t/** ESPN logo ids, for `sportsLogo()` (`$lib/utils/sports`), empty for teams without a logo */\n\tlogo_key: string | number;\n\tlogo_guid: string | null;\n};\n\n/**\n * MLB, NFL, NBA, NHL and WNBA teams, Division I, II and III college football teams, and Division I\n * men's and women's college basketball teams, built by `scripts/sports-teams.mjs` from ESPN (teams),\n * NCES IPEDS (campus locations) and Wikidata (venue locations).\n */\nexport const getSportsTeams = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/sports-teams.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as SportsTeam[];\n\treturn data;\n});\n\nexport const getBeagleVoyage = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/beagle-voyage.csv').then(async (r) =>\n\t\tcsvParse(await r.text(), autoType)\n\t)) as { longitude: number; latitude: number }[];\n\treturn data;\n});\n\nexport const getWorldLinks = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/world-links.json').then((r) =>\n\t\tr.json()\n\t)) as WorldLinksData;\n\treturn data;\n});\n\n/**\n * Every country, merged from Natural Earth's 10m admin-1 states and provinces (public domain) by\n * `scripts/natural-earth-admin.mjs`, so its borders line up with `getAdmin1Topology`'s.\n */\nexport const getAdmin0Topology = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/admin0.json').then((r) =>\n\t\tr.json()\n\t)) as Admin0Topology;\n\treturn data;\n});\n\n/**\n * One country's admin-1 states and provinces (by its `adm0_a3`, e.g. \"ITA\"), with its `regions`\n * where Natural Earth's admin-1 is the second level down.\n */\nexport const getAdmin1Topology = prerender(\n\tz.string(),\n\tasync (country) => {\n\t\tconst { fetch } = getRequestEvent();\n\t\tconst data = (await fetch(`/data/examples/geo/admin1/${country}.json`).then((r) =>\n\t\t\tr.json()\n\t\t)) as Admin1Topology;\n\t\treturn data;\n\t},\n\t{ inputs: () => admin1Countries }\n);\n\n/**\n * The people living in one US state (by its file, ex. `west-virginia`, as `getPopulationStates`\n * lists them), as `[longitude, latitude, people]` in cells of about 160 across the state, and its\n * largest places to label as `[name, longitude, latitude]`.\n *\n * From Kontur Population (November 2023, CC BY 4.0, https://data.humdata.org/dataset/kontur-population-united-states-of-america),\n * its 400m H3 hexagons summed into the cells and clipped to us-atlas' 1:10m state outlines, and\n * Natural Earth's populated places (public domain). Built by `scripts/kontur-population.mjs`.\n */\nexport const getStatePopulation = prerender(\n\tz.string().regex(/^[a-z-]+$/),\n\tasync (state) => {\n\t\tconst { fetch } = getRequestEvent();\n\t\t// Stored as whole steps from the state's southwest corner, `[i, j, people]` flattened\n\t\tconst { origin, step, cells, cities } = (await fetch(\n\t\t\t`/data/examples/geo/kontur-population/${state}.json`\n\t\t).then((r) => r.json())) as {\n\t\t\torigin: [number, number];\n\t\t\tstep: [number, number];\n\t\t\tcells: number[];\n\t\t\tcities: [name: string, longitude: number, latitude: number][];\n\t\t};\n\t\tconst data: [longitude: number, latitude: number, people: number][] = [];\n\t\tfor (let k = 0; k < cells.length; k += 3) {\n\t\t\tdata.push([origin[0] + cells[k] * step[0], origin[1] + cells[k + 1] * step[1], cells[k + 2]]);\n\t\t}\n\t\treturn { cells: data, cities };\n\t},\n\t{ inputs: () => populationStates.map((s) => s.value) }\n);\n\n/** The states `getStatePopulation` has, alphabetically: their files (`value`) and names */\nexport const getPopulationStates = prerender(async () => populationStates);\n\n/**\n * Lower Manhattan's buildings: footprints, with heights in meters where they're tagged (or 3.5m a\n * floor where only floors are), and names.\n *\n * From OpenStreetMap (© OpenStreetMap contributors, ODbL), fetched through the Overpass API in\n * October 2026.\n */\nexport const getLowerManhattanBuildings = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/geo/lower-manhattan-buildings.json').then((r) =>\n\t\tr.json()\n\t)) as import('geojson').FeatureCollection<\n\t\timport('geojson').Polygon,\n\t\t{ height: number | null; name: string | null }\n\t>;\n\treturn data;\n});\n",
"graph.remote.ts": "import { prerender, getRequestEvent, query } from '$app/server';\nimport { range } from 'd3-array';\nimport { randomInteger } from '@layerstack/utils';\nimport { unique } from '@layerstack/utils/array';\nimport { z } from 'zod';\n\nconst alpha = [...Array(26)].map((val, i) => String.fromCharCode(i + 65));\n\nexport const getGraph = query(z.string(), async (name) => {\n\tswitch (name) {\n\t\tcase 'basic': {\n\t\t\treturn getBasicGraph();\n\t\t}\n\t\tcase 'simple': {\n\t\t\treturn getSimpleGraph();\n\t\t}\n\t\tcase 'medium': {\n\t\t\treturn getMediumDag();\n\t\t}\n\t\tcase 'large': {\n\t\t\treturn getLargeDag();\n\t\t}\n\t\tcase 'complex': {\n\t\t\treturn getComplexGraph();\n\t\t}\n\t\tcase 'miserables': {\n\t\t\treturn getMiserablesGraph();\n\t\t}\n\t\tcase 'tcp-state': {\n\t\t\treturn getTcpStateGraph();\n\t\t}\n\t\tcase 'software-user-flow': {\n\t\t\treturn getSoftwareUserFlowGraph();\n\t\t}\n\t\tcase 'cluster': {\n\t\t\treturn getClusterGraph();\n\t\t}\n\t\tcase 'dag-medium': {\n\t\t\treturn getMediumDag();\n\t\t}\n\t\tcase 'dag-large': {\n\t\t\treturn getLargeDag();\n\t\t}\n\t\tcase 'disjoint-graph': {\n\t\t\treturn getDisjointGraph();\n\t\t}\n\t\tcase 'simple-generated': {\n\t\t\treturn getSimpleGeneratedGraph();\n\t\t}\n\t\tcase 'complex-generated': {\n\t\t\treturn getComplexGeneratedGraph();\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(`Unknown graph: ${name}`);\n\t\t}\n\t}\n});\n\nexport const getBasicGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/basic.json').then((r) => r.json())) as {\n\t\tnodes: { id: string }[];\n\t\tlinks: { source: string; target: string }[];\n\t};\n\treturn data;\n});\n\nexport const getSimpleGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/simple.json').then((r) => r.json())) as {\n\t\tnodes: { id: string }[];\n\t\tlinks: { source: string; target: string }[];\n\t};\n\treturn data;\n});\n\nexport const getComplexGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/complex.json').then((r) => r.json())) as {\n\t\tnodes: { id: string }[];\n\t\tlinks: { source: string; target: string }[];\n\t};\n\treturn data;\n});\n\nexport const getMiserablesGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/miserables.json').then((r) => r.json())) as {\n\t\tnodes: { id: string; group: number }[];\n\t\tlinks: { source: string; target: string; value: number }[];\n\t};\n\treturn data;\n});\n\nexport const getTcpStateGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/tcp-state.json').then((r) => r.json())) as {\n\t\tnodes: { id: string }[];\n\t\tlinks: { source: string; target: string; label: string }[];\n\t};\n\treturn data;\n});\n\nexport const getSoftwareUserFlowGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/software-user-flow.json').then((r) =>\n\t\tr.json()\n\t)) as {\n\t\tnodes: { id: string }[];\n\t\tlinks: { source: string; target: string; label: string }[];\n\t};\n\treturn data;\n});\n\nexport const getClusterGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/cluster.json').then((r) => r.json())) as {\n\t\tnodes: { id: string; parent?: string }[];\n\t\tlinks: { source: string; target: string }[];\n\t};\n\treturn data;\n});\n\nexport const getMediumDag = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/dag-medium.json').then((r) => r.json())) as {\n\t\tnodes: { id: string; name: string }[];\n\t\tlinks: { source: string; target: string }[];\n\t};\n\treturn data;\n});\n\nexport const getLargeDag = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/dag-large.json').then((r) => r.json())) as {\n\t\tnodes: { id: string; name: string }[];\n\t\tlinks: { source: string; target: string }[];\n\t};\n\treturn data;\n});\n\nexport const getDisjointGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/disjoint-graph.json').then((r) => r.json())) as {\n\t\tnodes: { id: string; group: number }[];\n\t\tlinks: { source: string; target: string; value: number }[];\n\t};\n\treturn data;\n});\n\nexport const getSimpleGeneratedGraph = prerender(async () => {\n\tconst data = {\n\t\tnodes: alpha.map((a) => ({\n\t\t\tid: a\n\t\t})),\n\t\tlinks: alpha.flatMap((a, i) => {\n\t\t\tif (i === 25) {\n\t\t\t\treturn [];\n\t\t\t} else {\n\t\t\t\tconst randomDownstreamId = randomInteger(i + 1, 25);\n\t\t\t\tconst edge = { source: a, target: alpha[randomDownstreamId] };\n\t\t\t\treturn [edge];\n\t\t\t}\n\t\t})\n\t};\n\treturn data;\n});\n\nexport const getComplexGeneratedGraph = prerender(async () => {\n\tfunction getRandomDownstreamIds(index: number) {\n\t\treturn unique(range(randomInteger(1, 3)).map(() => randomInteger(index + 1, 25)));\n\t}\n\n\tconst data = {\n\t\tnodes: alpha.map((a) => ({\n\t\t\tid: a\n\t\t})),\n\t\tlinks: alpha.flatMap((a, i) => {\n\t\t\tif (i === 25) {\n\t\t\t\treturn [];\n\t\t\t} else {\n\t\t\t\treturn getRandomDownstreamIds(i).map((id) => {\n\t\t\t\t\treturn { source: a, target: alpha[id] };\n\t\t\t\t});\n\t\t\t}\n\t\t})\n\t};\n\treturn data;\n});\n\nexport const getGreenhouseGraph = prerender(async () => {\n\tconst { fetch } = getRequestEvent();\n\tconst data = (await fetch('/data/examples/graph/greenhouse.json').then((r) => r.json())) as {\n\t\tnodes: { id: string }[];\n\t\tlinks: { source: string; target: string }[];\n\t};\n\treturn data;\n});\n"
}
\ No newline at end of file
diff --git a/docs/static/screenshots/webgl/Arc/concentric-dark-240w.webp b/docs/static/screenshots/Arc/concentric-3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/concentric-dark-240w.webp
rename to docs/static/screenshots/Arc/concentric-3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Arc/concentric-dark-400w.webp b/docs/static/screenshots/Arc/concentric-3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/concentric-dark-400w.webp
rename to docs/static/screenshots/Arc/concentric-3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Arc/concentric-dark-800w.webp b/docs/static/screenshots/Arc/concentric-3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/concentric-dark-800w.webp
rename to docs/static/screenshots/Arc/concentric-3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Arc/concentric-light-240w.webp b/docs/static/screenshots/Arc/concentric-3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/concentric-light-240w.webp
rename to docs/static/screenshots/Arc/concentric-3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Arc/concentric-light-400w.webp b/docs/static/screenshots/Arc/concentric-3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/concentric-light-400w.webp
rename to docs/static/screenshots/Arc/concentric-3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Arc/concentric-light-800w.webp b/docs/static/screenshots/Arc/concentric-3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/concentric-light-800w.webp
rename to docs/static/screenshots/Arc/concentric-3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Arc/pie-dark-240w.webp b/docs/static/screenshots/Arc/pie-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/pie-dark-240w.webp
rename to docs/static/screenshots/Arc/pie-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Arc/pie-dark-400w.webp b/docs/static/screenshots/Arc/pie-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/pie-dark-400w.webp
rename to docs/static/screenshots/Arc/pie-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Arc/pie-dark-800w.webp b/docs/static/screenshots/Arc/pie-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/pie-dark-800w.webp
rename to docs/static/screenshots/Arc/pie-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Arc/pie-light-240w.webp b/docs/static/screenshots/Arc/pie-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/pie-light-240w.webp
rename to docs/static/screenshots/Arc/pie-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Arc/pie-light-400w.webp b/docs/static/screenshots/Arc/pie-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/pie-light-400w.webp
rename to docs/static/screenshots/Arc/pie-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Arc/pie-light-800w.webp b/docs/static/screenshots/Arc/pie-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Arc/pie-light-800w.webp
rename to docs/static/screenshots/Arc/pie-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Area/areas-dark-240w.webp b/docs/static/screenshots/Area/areas-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/areas-dark-240w.webp
rename to docs/static/screenshots/Area/areas-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Area/areas-dark-400w.webp b/docs/static/screenshots/Area/areas-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/areas-dark-400w.webp
rename to docs/static/screenshots/Area/areas-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Area/areas-dark-800w.webp b/docs/static/screenshots/Area/areas-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/areas-dark-800w.webp
rename to docs/static/screenshots/Area/areas-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Area/areas-light-240w.webp b/docs/static/screenshots/Area/areas-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/areas-light-240w.webp
rename to docs/static/screenshots/Area/areas-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Area/areas-light-400w.webp b/docs/static/screenshots/Area/areas-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/areas-light-400w.webp
rename to docs/static/screenshots/Area/areas-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Area/areas-light-800w.webp b/docs/static/screenshots/Area/areas-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/areas-light-800w.webp
rename to docs/static/screenshots/Area/areas-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Area/ridgeline-dark-240w.webp b/docs/static/screenshots/Area/ridgeline-3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/ridgeline-dark-240w.webp
rename to docs/static/screenshots/Area/ridgeline-3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Area/ridgeline-dark-400w.webp b/docs/static/screenshots/Area/ridgeline-3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/ridgeline-dark-400w.webp
rename to docs/static/screenshots/Area/ridgeline-3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Area/ridgeline-dark-800w.webp b/docs/static/screenshots/Area/ridgeline-3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/ridgeline-dark-800w.webp
rename to docs/static/screenshots/Area/ridgeline-3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Area/ridgeline-light-240w.webp b/docs/static/screenshots/Area/ridgeline-3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/ridgeline-light-240w.webp
rename to docs/static/screenshots/Area/ridgeline-3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Area/ridgeline-light-400w.webp b/docs/static/screenshots/Area/ridgeline-3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/ridgeline-light-400w.webp
rename to docs/static/screenshots/Area/ridgeline-3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Area/ridgeline-light-800w.webp b/docs/static/screenshots/Area/ridgeline-3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Area/ridgeline-light-800w.webp
rename to docs/static/screenshots/Area/ridgeline-3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/calendar-dark-240w.webp b/docs/static/screenshots/Bars/calendar-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/calendar-dark-240w.webp
rename to docs/static/screenshots/Bars/calendar-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/calendar-dark-400w.webp b/docs/static/screenshots/Bars/calendar-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/calendar-dark-400w.webp
rename to docs/static/screenshots/Bars/calendar-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/calendar-dark-800w.webp b/docs/static/screenshots/Bars/calendar-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/calendar-dark-800w.webp
rename to docs/static/screenshots/Bars/calendar-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/calendar-light-240w.webp b/docs/static/screenshots/Bars/calendar-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/calendar-light-240w.webp
rename to docs/static/screenshots/Bars/calendar-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/calendar-light-400w.webp b/docs/static/screenshots/Bars/calendar-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/calendar-light-400w.webp
rename to docs/static/screenshots/Bars/calendar-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/calendar-light-800w.webp b/docs/static/screenshots/Bars/calendar-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/calendar-light-800w.webp
rename to docs/static/screenshots/Bars/calendar-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/columns-dark-240w.webp b/docs/static/screenshots/Bars/columns-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/columns-dark-240w.webp
rename to docs/static/screenshots/Bars/columns-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/columns-dark-400w.webp b/docs/static/screenshots/Bars/columns-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/columns-dark-400w.webp
rename to docs/static/screenshots/Bars/columns-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/columns-dark-800w.webp b/docs/static/screenshots/Bars/columns-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/columns-dark-800w.webp
rename to docs/static/screenshots/Bars/columns-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/columns-light-240w.webp b/docs/static/screenshots/Bars/columns-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/columns-light-240w.webp
rename to docs/static/screenshots/Bars/columns-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/columns-light-400w.webp b/docs/static/screenshots/Bars/columns-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/columns-light-400w.webp
rename to docs/static/screenshots/Bars/columns-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/columns-light-800w.webp b/docs/static/screenshots/Bars/columns-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/columns-light-800w.webp
rename to docs/static/screenshots/Bars/columns-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/heatmap-dark-240w.webp b/docs/static/screenshots/Bars/heatmap-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/heatmap-dark-240w.webp
rename to docs/static/screenshots/Bars/heatmap-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/heatmap-dark-400w.webp b/docs/static/screenshots/Bars/heatmap-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/heatmap-dark-400w.webp
rename to docs/static/screenshots/Bars/heatmap-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/heatmap-dark-800w.webp b/docs/static/screenshots/Bars/heatmap-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/heatmap-dark-800w.webp
rename to docs/static/screenshots/Bars/heatmap-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/heatmap-light-240w.webp b/docs/static/screenshots/Bars/heatmap-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/heatmap-light-240w.webp
rename to docs/static/screenshots/Bars/heatmap-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/heatmap-light-400w.webp b/docs/static/screenshots/Bars/heatmap-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/heatmap-light-400w.webp
rename to docs/static/screenshots/Bars/heatmap-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/heatmap-light-800w.webp b/docs/static/screenshots/Bars/heatmap-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/heatmap-light-800w.webp
rename to docs/static/screenshots/Bars/heatmap-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/stacked-columns-dark-240w.webp b/docs/static/screenshots/Bars/stacked-columns-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/stacked-columns-dark-240w.webp
rename to docs/static/screenshots/Bars/stacked-columns-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/stacked-columns-dark-400w.webp b/docs/static/screenshots/Bars/stacked-columns-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/stacked-columns-dark-400w.webp
rename to docs/static/screenshots/Bars/stacked-columns-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/stacked-columns-dark-800w.webp b/docs/static/screenshots/Bars/stacked-columns-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/stacked-columns-dark-800w.webp
rename to docs/static/screenshots/Bars/stacked-columns-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Bars/stacked-columns-light-240w.webp b/docs/static/screenshots/Bars/stacked-columns-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/stacked-columns-light-240w.webp
rename to docs/static/screenshots/Bars/stacked-columns-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Bars/stacked-columns-light-400w.webp b/docs/static/screenshots/Bars/stacked-columns-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/stacked-columns-light-400w.webp
rename to docs/static/screenshots/Bars/stacked-columns-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Bars/stacked-columns-light-800w.webp b/docs/static/screenshots/Bars/stacked-columns-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bars/stacked-columns-light-800w.webp
rename to docs/static/screenshots/Bars/stacked-columns-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Bin/hexbin-dark-240w.webp b/docs/static/screenshots/Bin/hexbin-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/hexbin-dark-240w.webp
rename to docs/static/screenshots/Bin/hexbin-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Bin/hexbin-dark-400w.webp b/docs/static/screenshots/Bin/hexbin-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/hexbin-dark-400w.webp
rename to docs/static/screenshots/Bin/hexbin-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Bin/hexbin-dark-800w.webp b/docs/static/screenshots/Bin/hexbin-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/hexbin-dark-800w.webp
rename to docs/static/screenshots/Bin/hexbin-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Bin/hexbin-light-240w.webp b/docs/static/screenshots/Bin/hexbin-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/hexbin-light-240w.webp
rename to docs/static/screenshots/Bin/hexbin-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Bin/hexbin-light-400w.webp b/docs/static/screenshots/Bin/hexbin-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/hexbin-light-400w.webp
rename to docs/static/screenshots/Bin/hexbin-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Bin/hexbin-light-800w.webp b/docs/static/screenshots/Bin/hexbin-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/hexbin-light-800w.webp
rename to docs/static/screenshots/Bin/hexbin-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Bin/state-population-dark-240w.webp b/docs/static/screenshots/Bin/state-population-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/state-population-dark-240w.webp
rename to docs/static/screenshots/Bin/state-population-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Bin/state-population-dark-400w.webp b/docs/static/screenshots/Bin/state-population-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/state-population-dark-400w.webp
rename to docs/static/screenshots/Bin/state-population-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Bin/state-population-dark-800w.webp b/docs/static/screenshots/Bin/state-population-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/state-population-dark-800w.webp
rename to docs/static/screenshots/Bin/state-population-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Bin/state-population-light-240w.webp b/docs/static/screenshots/Bin/state-population-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/state-population-light-240w.webp
rename to docs/static/screenshots/Bin/state-population-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Bin/state-population-light-400w.webp b/docs/static/screenshots/Bin/state-population-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/state-population-light-400w.webp
rename to docs/static/screenshots/Bin/state-population-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Bin/state-population-light-800w.webp b/docs/static/screenshots/Bin/state-population-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/state-population-light-800w.webp
rename to docs/static/screenshots/Bin/state-population-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Bin/walmart-dark-240w.webp b/docs/static/screenshots/Bin/walmart-3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/walmart-dark-240w.webp
rename to docs/static/screenshots/Bin/walmart-3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Bin/walmart-dark-400w.webp b/docs/static/screenshots/Bin/walmart-3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/walmart-dark-400w.webp
rename to docs/static/screenshots/Bin/walmart-3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Bin/walmart-dark-800w.webp b/docs/static/screenshots/Bin/walmart-3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/walmart-dark-800w.webp
rename to docs/static/screenshots/Bin/walmart-3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Bin/walmart-light-240w.webp b/docs/static/screenshots/Bin/walmart-3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/walmart-light-240w.webp
rename to docs/static/screenshots/Bin/walmart-3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Bin/walmart-light-400w.webp b/docs/static/screenshots/Bin/walmart-3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/walmart-light-400w.webp
rename to docs/static/screenshots/Bin/walmart-3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Bin/walmart-light-800w.webp b/docs/static/screenshots/Bin/walmart-3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Bin/walmart-light-800w.webp
rename to docs/static/screenshots/Bin/walmart-3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Contour/basic-dark-240w.webp b/docs/static/screenshots/Contour/basic-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Contour/basic-dark-240w.webp
rename to docs/static/screenshots/Contour/basic-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Contour/basic-dark-400w.webp b/docs/static/screenshots/Contour/basic-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Contour/basic-dark-400w.webp
rename to docs/static/screenshots/Contour/basic-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Contour/basic-dark-800w.webp b/docs/static/screenshots/Contour/basic-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Contour/basic-dark-800w.webp
rename to docs/static/screenshots/Contour/basic-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Contour/basic-light-240w.webp b/docs/static/screenshots/Contour/basic-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Contour/basic-light-240w.webp
rename to docs/static/screenshots/Contour/basic-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Contour/basic-light-400w.webp b/docs/static/screenshots/Contour/basic-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Contour/basic-light-400w.webp
rename to docs/static/screenshots/Contour/basic-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Contour/basic-light-800w.webp b/docs/static/screenshots/Contour/basic-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Contour/basic-light-800w.webp
rename to docs/static/screenshots/Contour/basic-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoPath/election-dark-240w.webp b/docs/static/screenshots/GeoPath/election-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoPath/election-dark-240w.webp
rename to docs/static/screenshots/GeoPath/election-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoPath/election-dark-400w.webp b/docs/static/screenshots/GeoPath/election-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoPath/election-dark-400w.webp
rename to docs/static/screenshots/GeoPath/election-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoPath/election-dark-800w.webp b/docs/static/screenshots/GeoPath/election-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoPath/election-dark-800w.webp
rename to docs/static/screenshots/GeoPath/election-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoPath/election-light-240w.webp b/docs/static/screenshots/GeoPath/election-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoPath/election-light-240w.webp
rename to docs/static/screenshots/GeoPath/election-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoPath/election-light-400w.webp b/docs/static/screenshots/GeoPath/election-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoPath/election-light-400w.webp
rename to docs/static/screenshots/GeoPath/election-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoPath/election-light-800w.webp b/docs/static/screenshots/GeoPath/election-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoPath/election-light-800w.webp
rename to docs/static/screenshots/GeoPath/election-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-dark-240w.webp b/docs/static/screenshots/GeoRaster/globe-3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-dark-240w.webp
rename to docs/static/screenshots/GeoRaster/globe-3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-dark-400w.webp b/docs/static/screenshots/GeoRaster/globe-3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-dark-400w.webp
rename to docs/static/screenshots/GeoRaster/globe-3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-dark-800w.webp b/docs/static/screenshots/GeoRaster/globe-3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-dark-800w.webp
rename to docs/static/screenshots/GeoRaster/globe-3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-light-240w.webp b/docs/static/screenshots/GeoRaster/globe-3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-light-240w.webp
rename to docs/static/screenshots/GeoRaster/globe-3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-light-400w.webp b/docs/static/screenshots/GeoRaster/globe-3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-light-400w.webp
rename to docs/static/screenshots/GeoRaster/globe-3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-light-800w.webp b/docs/static/screenshots/GeoRaster/globe-3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-light-800w.webp
rename to docs/static/screenshots/GeoRaster/globe-3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-textures-dark-240w.webp b/docs/static/screenshots/GeoRaster/globe-textures-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-textures-dark-240w.webp
rename to docs/static/screenshots/GeoRaster/globe-textures-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-textures-dark-400w.webp b/docs/static/screenshots/GeoRaster/globe-textures-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-textures-dark-400w.webp
rename to docs/static/screenshots/GeoRaster/globe-textures-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-textures-dark-800w.webp b/docs/static/screenshots/GeoRaster/globe-textures-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-textures-dark-800w.webp
rename to docs/static/screenshots/GeoRaster/globe-textures-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-textures-light-240w.webp b/docs/static/screenshots/GeoRaster/globe-textures-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-textures-light-240w.webp
rename to docs/static/screenshots/GeoRaster/globe-textures-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-textures-light-400w.webp b/docs/static/screenshots/GeoRaster/globe-textures-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-textures-light-400w.webp
rename to docs/static/screenshots/GeoRaster/globe-textures-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-textures-light-800w.webp b/docs/static/screenshots/GeoRaster/globe-textures-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-textures-light-800w.webp
rename to docs/static/screenshots/GeoRaster/globe-textures-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-tiles-dark-240w.webp b/docs/static/screenshots/GeoRaster/globe-tiles-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-tiles-dark-240w.webp
rename to docs/static/screenshots/GeoRaster/globe-tiles-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-tiles-dark-400w.webp b/docs/static/screenshots/GeoRaster/globe-tiles-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-tiles-dark-400w.webp
rename to docs/static/screenshots/GeoRaster/globe-tiles-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-tiles-dark-800w.webp b/docs/static/screenshots/GeoRaster/globe-tiles-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-tiles-dark-800w.webp
rename to docs/static/screenshots/GeoRaster/globe-tiles-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-tiles-light-240w.webp b/docs/static/screenshots/GeoRaster/globe-tiles-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-tiles-light-240w.webp
rename to docs/static/screenshots/GeoRaster/globe-tiles-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-tiles-light-400w.webp b/docs/static/screenshots/GeoRaster/globe-tiles-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-tiles-light-400w.webp
rename to docs/static/screenshots/GeoRaster/globe-tiles-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/globe-tiles-light-800w.webp b/docs/static/screenshots/GeoRaster/globe-tiles-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/globe-tiles-light-800w.webp
rename to docs/static/screenshots/GeoRaster/globe-tiles-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/planets-dark-240w.webp b/docs/static/screenshots/GeoRaster/planets-3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/planets-dark-240w.webp
rename to docs/static/screenshots/GeoRaster/planets-3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/planets-dark-400w.webp b/docs/static/screenshots/GeoRaster/planets-3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/planets-dark-400w.webp
rename to docs/static/screenshots/GeoRaster/planets-3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/planets-dark-800w.webp b/docs/static/screenshots/GeoRaster/planets-3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/planets-dark-800w.webp
rename to docs/static/screenshots/GeoRaster/planets-3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/planets-light-240w.webp b/docs/static/screenshots/GeoRaster/planets-3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/planets-light-240w.webp
rename to docs/static/screenshots/GeoRaster/planets-3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/planets-light-400w.webp b/docs/static/screenshots/GeoRaster/planets-3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/planets-light-400w.webp
rename to docs/static/screenshots/GeoRaster/planets-3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/planets-light-800w.webp b/docs/static/screenshots/GeoRaster/planets-3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/planets-light-800w.webp
rename to docs/static/screenshots/GeoRaster/planets-3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/projections-dark-240w.webp b/docs/static/screenshots/GeoRaster/projections-3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/projections-dark-240w.webp
rename to docs/static/screenshots/GeoRaster/projections-3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/projections-dark-400w.webp b/docs/static/screenshots/GeoRaster/projections-3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/projections-dark-400w.webp
rename to docs/static/screenshots/GeoRaster/projections-3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/projections-dark-800w.webp b/docs/static/screenshots/GeoRaster/projections-3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/projections-dark-800w.webp
rename to docs/static/screenshots/GeoRaster/projections-3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/projections-light-240w.webp b/docs/static/screenshots/GeoRaster/projections-3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/projections-light-240w.webp
rename to docs/static/screenshots/GeoRaster/projections-3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/projections-light-400w.webp b/docs/static/screenshots/GeoRaster/projections-3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/projections-light-400w.webp
rename to docs/static/screenshots/GeoRaster/projections-3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/projections-light-800w.webp b/docs/static/screenshots/GeoRaster/projections-3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/projections-light-800w.webp
rename to docs/static/screenshots/GeoRaster/projections-3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/terrain-dark-240w.webp b/docs/static/screenshots/GeoRaster/terrain-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/terrain-dark-240w.webp
rename to docs/static/screenshots/GeoRaster/terrain-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/terrain-dark-400w.webp b/docs/static/screenshots/GeoRaster/terrain-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/terrain-dark-400w.webp
rename to docs/static/screenshots/GeoRaster/terrain-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/terrain-dark-800w.webp b/docs/static/screenshots/GeoRaster/terrain-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/terrain-dark-800w.webp
rename to docs/static/screenshots/GeoRaster/terrain-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/terrain-light-240w.webp b/docs/static/screenshots/GeoRaster/terrain-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/terrain-light-240w.webp
rename to docs/static/screenshots/GeoRaster/terrain-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/terrain-light-400w.webp b/docs/static/screenshots/GeoRaster/terrain-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/terrain-light-400w.webp
rename to docs/static/screenshots/GeoRaster/terrain-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoRaster/terrain-light-800w.webp b/docs/static/screenshots/GeoRaster/terrain-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoRaster/terrain-light-800w.webp
rename to docs/static/screenshots/GeoRaster/terrain-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/globe-dark-240w.webp b/docs/static/screenshots/GeoTile/globe-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/globe-dark-240w.webp
rename to docs/static/screenshots/GeoTile/globe-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/globe-dark-400w.webp b/docs/static/screenshots/GeoTile/globe-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/globe-dark-400w.webp
rename to docs/static/screenshots/GeoTile/globe-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/globe-dark-800w.webp b/docs/static/screenshots/GeoTile/globe-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/globe-dark-800w.webp
rename to docs/static/screenshots/GeoTile/globe-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/globe-light-240w.webp b/docs/static/screenshots/GeoTile/globe-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/globe-light-240w.webp
rename to docs/static/screenshots/GeoTile/globe-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/globe-light-400w.webp b/docs/static/screenshots/GeoTile/globe-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/globe-light-400w.webp
rename to docs/static/screenshots/GeoTile/globe-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/globe-light-800w.webp b/docs/static/screenshots/GeoTile/globe-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/globe-light-800w.webp
rename to docs/static/screenshots/GeoTile/globe-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/terrain-dark-240w.webp b/docs/static/screenshots/GeoTile/terrain-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/terrain-dark-240w.webp
rename to docs/static/screenshots/GeoTile/terrain-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/terrain-dark-400w.webp b/docs/static/screenshots/GeoTile/terrain-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/terrain-dark-400w.webp
rename to docs/static/screenshots/GeoTile/terrain-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/terrain-dark-800w.webp b/docs/static/screenshots/GeoTile/terrain-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/terrain-dark-800w.webp
rename to docs/static/screenshots/GeoTile/terrain-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/terrain-light-240w.webp b/docs/static/screenshots/GeoTile/terrain-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/terrain-light-240w.webp
rename to docs/static/screenshots/GeoTile/terrain-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/terrain-light-400w.webp b/docs/static/screenshots/GeoTile/terrain-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/terrain-light-400w.webp
rename to docs/static/screenshots/GeoTile/terrain-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/terrain-light-800w.webp b/docs/static/screenshots/GeoTile/terrain-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/terrain-light-800w.webp
rename to docs/static/screenshots/GeoTile/terrain-light-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/zoomable-dark-240w.webp b/docs/static/screenshots/GeoTile/zoomable-webgl-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/zoomable-dark-240w.webp
rename to docs/static/screenshots/GeoTile/zoomable-webgl-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/zoomable-dark-400w.webp b/docs/static/screenshots/GeoTile/zoomable-webgl-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/zoomable-dark-400w.webp
rename to docs/static/screenshots/GeoTile/zoomable-webgl-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/zoomable-dark-800w.webp b/docs/static/screenshots/GeoTile/zoomable-webgl-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/zoomable-dark-800w.webp
rename to docs/static/screenshots/GeoTile/zoomable-webgl-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/zoomable-light-240w.webp b/docs/static/screenshots/GeoTile/zoomable-webgl-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/zoomable-light-240w.webp
rename to docs/static/screenshots/GeoTile/zoomable-webgl-light-240w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/zoomable-light-400w.webp b/docs/static/screenshots/GeoTile/zoomable-webgl-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/zoomable-light-400w.webp
rename to docs/static/screenshots/GeoTile/zoomable-webgl-light-400w.webp
diff --git a/docs/static/screenshots/webgl/GeoTile/zoomable-light-800w.webp b/docs/static/screenshots/GeoTile/zoomable-webgl-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/GeoTile/zoomable-light-800w.webp
rename to docs/static/screenshots/GeoTile/zoomable-webgl-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Light/buildings-dark-240w.webp b/docs/static/screenshots/Light/buildings-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Light/buildings-dark-240w.webp
rename to docs/static/screenshots/Light/buildings-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Light/buildings-dark-400w.webp b/docs/static/screenshots/Light/buildings-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Light/buildings-dark-400w.webp
rename to docs/static/screenshots/Light/buildings-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Light/buildings-dark-800w.webp b/docs/static/screenshots/Light/buildings-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Light/buildings-dark-800w.webp
rename to docs/static/screenshots/Light/buildings-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Light/buildings-light-240w.webp b/docs/static/screenshots/Light/buildings-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Light/buildings-light-240w.webp
rename to docs/static/screenshots/Light/buildings-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Light/buildings-light-400w.webp b/docs/static/screenshots/Light/buildings-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Light/buildings-light-400w.webp
rename to docs/static/screenshots/Light/buildings-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Light/buildings-light-800w.webp b/docs/static/screenshots/Light/buildings-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Light/buildings-light-800w.webp
rename to docs/static/screenshots/Light/buildings-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Link/pin-map-dark-240w.webp b/docs/static/screenshots/Link/pin-map-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Link/pin-map-dark-240w.webp
rename to docs/static/screenshots/Link/pin-map-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Link/pin-map-dark-400w.webp b/docs/static/screenshots/Link/pin-map-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Link/pin-map-dark-400w.webp
rename to docs/static/screenshots/Link/pin-map-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Link/pin-map-dark-800w.webp b/docs/static/screenshots/Link/pin-map-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Link/pin-map-dark-800w.webp
rename to docs/static/screenshots/Link/pin-map-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Link/pin-map-light-240w.webp b/docs/static/screenshots/Link/pin-map-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Link/pin-map-light-240w.webp
rename to docs/static/screenshots/Link/pin-map-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Link/pin-map-light-400w.webp b/docs/static/screenshots/Link/pin-map-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Link/pin-map-light-400w.webp
rename to docs/static/screenshots/Link/pin-map-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Link/pin-map-light-800w.webp b/docs/static/screenshots/Link/pin-map-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Link/pin-map-light-800w.webp
rename to docs/static/screenshots/Link/pin-map-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/galaxy-dark-240w.webp b/docs/static/screenshots/Points/galaxy-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/galaxy-dark-240w.webp
rename to docs/static/screenshots/Points/galaxy-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/galaxy-dark-400w.webp b/docs/static/screenshots/Points/galaxy-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/galaxy-dark-400w.webp
rename to docs/static/screenshots/Points/galaxy-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/galaxy-dark-800w.webp b/docs/static/screenshots/Points/galaxy-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/galaxy-dark-800w.webp
rename to docs/static/screenshots/Points/galaxy-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/galaxy-light-240w.webp b/docs/static/screenshots/Points/galaxy-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/galaxy-light-240w.webp
rename to docs/static/screenshots/Points/galaxy-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/galaxy-light-400w.webp b/docs/static/screenshots/Points/galaxy-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/galaxy-light-400w.webp
rename to docs/static/screenshots/Points/galaxy-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/galaxy-light-800w.webp b/docs/static/screenshots/Points/galaxy-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/galaxy-light-800w.webp
rename to docs/static/screenshots/Points/galaxy-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-3d-dark-240w.webp b/docs/static/screenshots/Points/scatter-3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-3d-dark-240w.webp
rename to docs/static/screenshots/Points/scatter-3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-3d-dark-400w.webp b/docs/static/screenshots/Points/scatter-3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-3d-dark-400w.webp
rename to docs/static/screenshots/Points/scatter-3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-3d-dark-800w.webp b/docs/static/screenshots/Points/scatter-3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-3d-dark-800w.webp
rename to docs/static/screenshots/Points/scatter-3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-3d-light-240w.webp b/docs/static/screenshots/Points/scatter-3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-3d-light-240w.webp
rename to docs/static/screenshots/Points/scatter-3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-3d-light-400w.webp b/docs/static/screenshots/Points/scatter-3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-3d-light-400w.webp
rename to docs/static/screenshots/Points/scatter-3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-3d-light-800w.webp b/docs/static/screenshots/Points/scatter-3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-3d-light-800w.webp
rename to docs/static/screenshots/Points/scatter-3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-dark-240w.webp b/docs/static/screenshots/Points/scatter-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-dark-240w.webp
rename to docs/static/screenshots/Points/scatter-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-dark-400w.webp b/docs/static/screenshots/Points/scatter-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-dark-400w.webp
rename to docs/static/screenshots/Points/scatter-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-dark-800w.webp b/docs/static/screenshots/Points/scatter-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-dark-800w.webp
rename to docs/static/screenshots/Points/scatter-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-light-240w.webp b/docs/static/screenshots/Points/scatter-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-light-240w.webp
rename to docs/static/screenshots/Points/scatter-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-light-400w.webp b/docs/static/screenshots/Points/scatter-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-light-400w.webp
rename to docs/static/screenshots/Points/scatter-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-light-800w.webp b/docs/static/screenshots/Points/scatter-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-light-800w.webp
rename to docs/static/screenshots/Points/scatter-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-with-svg-dark-240w.webp b/docs/static/screenshots/Points/scatter-with-svg-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-with-svg-dark-240w.webp
rename to docs/static/screenshots/Points/scatter-with-svg-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-with-svg-dark-400w.webp b/docs/static/screenshots/Points/scatter-with-svg-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-with-svg-dark-400w.webp
rename to docs/static/screenshots/Points/scatter-with-svg-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-with-svg-dark-800w.webp b/docs/static/screenshots/Points/scatter-with-svg-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-with-svg-dark-800w.webp
rename to docs/static/screenshots/Points/scatter-with-svg-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-with-svg-light-240w.webp b/docs/static/screenshots/Points/scatter-with-svg-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-with-svg-light-240w.webp
rename to docs/static/screenshots/Points/scatter-with-svg-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-with-svg-light-400w.webp b/docs/static/screenshots/Points/scatter-with-svg-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-with-svg-light-400w.webp
rename to docs/static/screenshots/Points/scatter-with-svg-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/scatter-with-svg-light-800w.webp b/docs/static/screenshots/Points/scatter-with-svg-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/scatter-with-svg-light-800w.webp
rename to docs/static/screenshots/Points/scatter-with-svg-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/solar-system-dark-240w.webp b/docs/static/screenshots/Points/solar-system-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/solar-system-dark-240w.webp
rename to docs/static/screenshots/Points/solar-system-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/solar-system-dark-400w.webp b/docs/static/screenshots/Points/solar-system-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/solar-system-dark-400w.webp
rename to docs/static/screenshots/Points/solar-system-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/solar-system-dark-800w.webp b/docs/static/screenshots/Points/solar-system-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/solar-system-dark-800w.webp
rename to docs/static/screenshots/Points/solar-system-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Points/solar-system-light-240w.webp b/docs/static/screenshots/Points/solar-system-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/solar-system-light-240w.webp
rename to docs/static/screenshots/Points/solar-system-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Points/solar-system-light-400w.webp b/docs/static/screenshots/Points/solar-system-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/solar-system-light-400w.webp
rename to docs/static/screenshots/Points/solar-system-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Points/solar-system-light-800w.webp b/docs/static/screenshots/Points/solar-system-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Points/solar-system-light-800w.webp
rename to docs/static/screenshots/Points/solar-system-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Polygon/tree-dark-240w.webp b/docs/static/screenshots/Polygon/tree-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Polygon/tree-dark-240w.webp
rename to docs/static/screenshots/Polygon/tree-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Polygon/tree-dark-400w.webp b/docs/static/screenshots/Polygon/tree-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Polygon/tree-dark-400w.webp
rename to docs/static/screenshots/Polygon/tree-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Polygon/tree-dark-800w.webp b/docs/static/screenshots/Polygon/tree-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Polygon/tree-dark-800w.webp
rename to docs/static/screenshots/Polygon/tree-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Polygon/tree-light-240w.webp b/docs/static/screenshots/Polygon/tree-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Polygon/tree-light-240w.webp
rename to docs/static/screenshots/Polygon/tree-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Polygon/tree-light-400w.webp b/docs/static/screenshots/Polygon/tree-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Polygon/tree-light-400w.webp
rename to docs/static/screenshots/Polygon/tree-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Polygon/tree-light-800w.webp b/docs/static/screenshots/Polygon/tree-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Polygon/tree-light-800w.webp
rename to docs/static/screenshots/Polygon/tree-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Raster/basic-dark-240w.webp b/docs/static/screenshots/Raster/basic-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Raster/basic-dark-240w.webp
rename to docs/static/screenshots/Raster/basic-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Raster/basic-dark-400w.webp b/docs/static/screenshots/Raster/basic-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Raster/basic-dark-400w.webp
rename to docs/static/screenshots/Raster/basic-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Raster/basic-dark-800w.webp b/docs/static/screenshots/Raster/basic-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Raster/basic-dark-800w.webp
rename to docs/static/screenshots/Raster/basic-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Raster/basic-light-240w.webp b/docs/static/screenshots/Raster/basic-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Raster/basic-light-240w.webp
rename to docs/static/screenshots/Raster/basic-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Raster/basic-light-400w.webp b/docs/static/screenshots/Raster/basic-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Raster/basic-light-400w.webp
rename to docs/static/screenshots/Raster/basic-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Raster/basic-light-800w.webp b/docs/static/screenshots/Raster/basic-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Raster/basic-light-800w.webp
rename to docs/static/screenshots/Raster/basic-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Rect/treemap-dark-240w.webp b/docs/static/screenshots/Rect/treemap-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rect/treemap-dark-240w.webp
rename to docs/static/screenshots/Rect/treemap-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Rect/treemap-dark-400w.webp b/docs/static/screenshots/Rect/treemap-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rect/treemap-dark-400w.webp
rename to docs/static/screenshots/Rect/treemap-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Rect/treemap-dark-800w.webp b/docs/static/screenshots/Rect/treemap-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rect/treemap-dark-800w.webp
rename to docs/static/screenshots/Rect/treemap-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Rect/treemap-light-240w.webp b/docs/static/screenshots/Rect/treemap-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rect/treemap-light-240w.webp
rename to docs/static/screenshots/Rect/treemap-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Rect/treemap-light-400w.webp b/docs/static/screenshots/Rect/treemap-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rect/treemap-light-400w.webp
rename to docs/static/screenshots/Rect/treemap-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Rect/treemap-light-800w.webp b/docs/static/screenshots/Rect/treemap-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rect/treemap-light-800w.webp
rename to docs/static/screenshots/Rect/treemap-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Rule/lollipop-dark-240w.webp b/docs/static/screenshots/Rule/lollipop-webgl-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rule/lollipop-dark-240w.webp
rename to docs/static/screenshots/Rule/lollipop-webgl-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Rule/lollipop-dark-400w.webp b/docs/static/screenshots/Rule/lollipop-webgl-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rule/lollipop-dark-400w.webp
rename to docs/static/screenshots/Rule/lollipop-webgl-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Rule/lollipop-dark-800w.webp b/docs/static/screenshots/Rule/lollipop-webgl-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rule/lollipop-dark-800w.webp
rename to docs/static/screenshots/Rule/lollipop-webgl-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Rule/lollipop-light-240w.webp b/docs/static/screenshots/Rule/lollipop-webgl-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rule/lollipop-light-240w.webp
rename to docs/static/screenshots/Rule/lollipop-webgl-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Rule/lollipop-light-400w.webp b/docs/static/screenshots/Rule/lollipop-webgl-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rule/lollipop-light-400w.webp
rename to docs/static/screenshots/Rule/lollipop-webgl-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Rule/lollipop-light-800w.webp b/docs/static/screenshots/Rule/lollipop-webgl-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Rule/lollipop-light-800w.webp
rename to docs/static/screenshots/Rule/lollipop-webgl-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Spline/line3d-dark-240w.webp b/docs/static/screenshots/Spline/line3d-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/line3d-dark-240w.webp
rename to docs/static/screenshots/Spline/line3d-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Spline/line3d-dark-400w.webp b/docs/static/screenshots/Spline/line3d-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/line3d-dark-400w.webp
rename to docs/static/screenshots/Spline/line3d-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Spline/line3d-dark-800w.webp b/docs/static/screenshots/Spline/line3d-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/line3d-dark-800w.webp
rename to docs/static/screenshots/Spline/line3d-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Spline/line3d-light-240w.webp b/docs/static/screenshots/Spline/line3d-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/line3d-light-240w.webp
rename to docs/static/screenshots/Spline/line3d-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Spline/line3d-light-400w.webp b/docs/static/screenshots/Spline/line3d-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/line3d-light-400w.webp
rename to docs/static/screenshots/Spline/line3d-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Spline/line3d-light-800w.webp b/docs/static/screenshots/Spline/line3d-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/line3d-light-800w.webp
rename to docs/static/screenshots/Spline/line3d-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Spline/series-dark-240w.webp b/docs/static/screenshots/Spline/series-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/series-dark-240w.webp
rename to docs/static/screenshots/Spline/series-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Spline/series-dark-400w.webp b/docs/static/screenshots/Spline/series-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/series-dark-400w.webp
rename to docs/static/screenshots/Spline/series-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Spline/series-dark-800w.webp b/docs/static/screenshots/Spline/series-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/series-dark-800w.webp
rename to docs/static/screenshots/Spline/series-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Spline/series-light-240w.webp b/docs/static/screenshots/Spline/series-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/series-light-240w.webp
rename to docs/static/screenshots/Spline/series-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Spline/series-light-400w.webp b/docs/static/screenshots/Spline/series-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/series-light-400w.webp
rename to docs/static/screenshots/Spline/series-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Spline/series-light-800w.webp b/docs/static/screenshots/Spline/series-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/series-light-800w.webp
rename to docs/static/screenshots/Spline/series-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Spline/temperatures-dark-240w.webp b/docs/static/screenshots/Spline/temperatures-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/temperatures-dark-240w.webp
rename to docs/static/screenshots/Spline/temperatures-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Spline/temperatures-dark-400w.webp b/docs/static/screenshots/Spline/temperatures-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/temperatures-dark-400w.webp
rename to docs/static/screenshots/Spline/temperatures-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Spline/temperatures-dark-800w.webp b/docs/static/screenshots/Spline/temperatures-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/temperatures-dark-800w.webp
rename to docs/static/screenshots/Spline/temperatures-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Spline/temperatures-light-240w.webp b/docs/static/screenshots/Spline/temperatures-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/temperatures-light-240w.webp
rename to docs/static/screenshots/Spline/temperatures-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Spline/temperatures-light-400w.webp b/docs/static/screenshots/Spline/temperatures-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/temperatures-light-400w.webp
rename to docs/static/screenshots/Spline/temperatures-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Spline/temperatures-light-800w.webp b/docs/static/screenshots/Spline/temperatures-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Spline/temperatures-light-800w.webp
rename to docs/static/screenshots/Spline/temperatures-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/basic-dark-240w.webp b/docs/static/screenshots/Surface/basic-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/basic-dark-240w.webp
rename to docs/static/screenshots/Surface/basic-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/basic-dark-400w.webp b/docs/static/screenshots/Surface/basic-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/basic-dark-400w.webp
rename to docs/static/screenshots/Surface/basic-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/basic-dark-800w.webp b/docs/static/screenshots/Surface/basic-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/basic-dark-800w.webp
rename to docs/static/screenshots/Surface/basic-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/basic-light-240w.webp b/docs/static/screenshots/Surface/basic-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/basic-light-240w.webp
rename to docs/static/screenshots/Surface/basic-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/basic-light-400w.webp b/docs/static/screenshots/Surface/basic-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/basic-light-400w.webp
rename to docs/static/screenshots/Surface/basic-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/basic-light-800w.webp b/docs/static/screenshots/Surface/basic-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/basic-light-800w.webp
rename to docs/static/screenshots/Surface/basic-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/math-functions-dark-240w.webp b/docs/static/screenshots/Surface/math-functions-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/math-functions-dark-240w.webp
rename to docs/static/screenshots/Surface/math-functions-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/math-functions-dark-400w.webp b/docs/static/screenshots/Surface/math-functions-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/math-functions-dark-400w.webp
rename to docs/static/screenshots/Surface/math-functions-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/math-functions-dark-800w.webp b/docs/static/screenshots/Surface/math-functions-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/math-functions-dark-800w.webp
rename to docs/static/screenshots/Surface/math-functions-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/math-functions-light-240w.webp b/docs/static/screenshots/Surface/math-functions-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/math-functions-light-240w.webp
rename to docs/static/screenshots/Surface/math-functions-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/math-functions-light-400w.webp b/docs/static/screenshots/Surface/math-functions-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/math-functions-light-400w.webp
rename to docs/static/screenshots/Surface/math-functions-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/math-functions-light-800w.webp b/docs/static/screenshots/Surface/math-functions-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/math-functions-light-800w.webp
rename to docs/static/screenshots/Surface/math-functions-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/terrain-dark-240w.webp b/docs/static/screenshots/Surface/terrain-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/terrain-dark-240w.webp
rename to docs/static/screenshots/Surface/terrain-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/terrain-dark-400w.webp b/docs/static/screenshots/Surface/terrain-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/terrain-dark-400w.webp
rename to docs/static/screenshots/Surface/terrain-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/terrain-dark-800w.webp b/docs/static/screenshots/Surface/terrain-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/terrain-dark-800w.webp
rename to docs/static/screenshots/Surface/terrain-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/terrain-light-240w.webp b/docs/static/screenshots/Surface/terrain-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/terrain-light-240w.webp
rename to docs/static/screenshots/Surface/terrain-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/terrain-light-400w.webp b/docs/static/screenshots/Surface/terrain-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/terrain-light-400w.webp
rename to docs/static/screenshots/Surface/terrain-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/terrain-light-800w.webp b/docs/static/screenshots/Surface/terrain-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/terrain-light-800w.webp
rename to docs/static/screenshots/Surface/terrain-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/us-elevation-dark-240w.webp b/docs/static/screenshots/Surface/us-elevation-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/us-elevation-dark-240w.webp
rename to docs/static/screenshots/Surface/us-elevation-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/us-elevation-dark-400w.webp b/docs/static/screenshots/Surface/us-elevation-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/us-elevation-dark-400w.webp
rename to docs/static/screenshots/Surface/us-elevation-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/us-elevation-dark-800w.webp b/docs/static/screenshots/Surface/us-elevation-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/us-elevation-dark-800w.webp
rename to docs/static/screenshots/Surface/us-elevation-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/us-elevation-light-240w.webp b/docs/static/screenshots/Surface/us-elevation-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/us-elevation-light-240w.webp
rename to docs/static/screenshots/Surface/us-elevation-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/us-elevation-light-400w.webp b/docs/static/screenshots/Surface/us-elevation-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/us-elevation-light-400w.webp
rename to docs/static/screenshots/Surface/us-elevation-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/us-elevation-light-800w.webp b/docs/static/screenshots/Surface/us-elevation-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/us-elevation-light-800w.webp
rename to docs/static/screenshots/Surface/us-elevation-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/volcano-dark-240w.webp b/docs/static/screenshots/Surface/volcano-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/volcano-dark-240w.webp
rename to docs/static/screenshots/Surface/volcano-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/volcano-dark-400w.webp b/docs/static/screenshots/Surface/volcano-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/volcano-dark-400w.webp
rename to docs/static/screenshots/Surface/volcano-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/volcano-dark-800w.webp b/docs/static/screenshots/Surface/volcano-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/volcano-dark-800w.webp
rename to docs/static/screenshots/Surface/volcano-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/volcano-light-240w.webp b/docs/static/screenshots/Surface/volcano-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/volcano-light-240w.webp
rename to docs/static/screenshots/Surface/volcano-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/volcano-light-400w.webp b/docs/static/screenshots/Surface/volcano-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/volcano-light-400w.webp
rename to docs/static/screenshots/Surface/volcano-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/volcano-light-800w.webp b/docs/static/screenshots/Surface/volcano-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/volcano-light-800w.webp
rename to docs/static/screenshots/Surface/volcano-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/world-elevation-dark-240w.webp b/docs/static/screenshots/Surface/world-elevation-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/world-elevation-dark-240w.webp
rename to docs/static/screenshots/Surface/world-elevation-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/world-elevation-dark-400w.webp b/docs/static/screenshots/Surface/world-elevation-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/world-elevation-dark-400w.webp
rename to docs/static/screenshots/Surface/world-elevation-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/world-elevation-dark-800w.webp b/docs/static/screenshots/Surface/world-elevation-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/world-elevation-dark-800w.webp
rename to docs/static/screenshots/Surface/world-elevation-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Surface/world-elevation-light-240w.webp b/docs/static/screenshots/Surface/world-elevation-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/world-elevation-light-240w.webp
rename to docs/static/screenshots/Surface/world-elevation-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Surface/world-elevation-light-400w.webp b/docs/static/screenshots/Surface/world-elevation-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/world-elevation-light-400w.webp
rename to docs/static/screenshots/Surface/world-elevation-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Surface/world-elevation-light-800w.webp b/docs/static/screenshots/Surface/world-elevation-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Surface/world-elevation-light-800w.webp
rename to docs/static/screenshots/Surface/world-elevation-light-800w.webp
diff --git a/docs/static/screenshots/webgl/Vector/field-dark-240w.webp b/docs/static/screenshots/Vector/field-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Vector/field-dark-240w.webp
rename to docs/static/screenshots/Vector/field-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/Vector/field-dark-400w.webp b/docs/static/screenshots/Vector/field-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Vector/field-dark-400w.webp
rename to docs/static/screenshots/Vector/field-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/Vector/field-dark-800w.webp b/docs/static/screenshots/Vector/field-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Vector/field-dark-800w.webp
rename to docs/static/screenshots/Vector/field-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/Vector/field-light-240w.webp b/docs/static/screenshots/Vector/field-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Vector/field-light-240w.webp
rename to docs/static/screenshots/Vector/field-light-240w.webp
diff --git a/docs/static/screenshots/webgl/Vector/field-light-400w.webp b/docs/static/screenshots/Vector/field-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Vector/field-light-400w.webp
rename to docs/static/screenshots/Vector/field-light-400w.webp
diff --git a/docs/static/screenshots/webgl/Vector/field-light-800w.webp b/docs/static/screenshots/Vector/field-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/Vector/field-light-800w.webp
rename to docs/static/screenshots/Vector/field-light-800w.webp
diff --git a/docs/static/screenshots/webgl/WebGL/playground-dark-240w.webp b/docs/static/screenshots/WebGL/playground-dark-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/WebGL/playground-dark-240w.webp
rename to docs/static/screenshots/WebGL/playground-dark-240w.webp
diff --git a/docs/static/screenshots/webgl/WebGL/playground-dark-400w.webp b/docs/static/screenshots/WebGL/playground-dark-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/WebGL/playground-dark-400w.webp
rename to docs/static/screenshots/WebGL/playground-dark-400w.webp
diff --git a/docs/static/screenshots/webgl/WebGL/playground-dark-800w.webp b/docs/static/screenshots/WebGL/playground-dark-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/WebGL/playground-dark-800w.webp
rename to docs/static/screenshots/WebGL/playground-dark-800w.webp
diff --git a/docs/static/screenshots/webgl/WebGL/playground-light-240w.webp b/docs/static/screenshots/WebGL/playground-light-240w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/WebGL/playground-light-240w.webp
rename to docs/static/screenshots/WebGL/playground-light-240w.webp
diff --git a/docs/static/screenshots/webgl/WebGL/playground-light-400w.webp b/docs/static/screenshots/WebGL/playground-light-400w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/WebGL/playground-light-400w.webp
rename to docs/static/screenshots/WebGL/playground-light-400w.webp
diff --git a/docs/static/screenshots/webgl/WebGL/playground-light-800w.webp b/docs/static/screenshots/WebGL/playground-light-800w.webp
similarity index 100%
rename from docs/static/screenshots/webgl/WebGL/playground-light-800w.webp
rename to docs/static/screenshots/WebGL/playground-light-800w.webp
diff --git a/docs/vite-plugin-webgl-examples.ts b/docs/vite-plugin-webgl-examples.ts
new file mode 100644
index 0000000000..fe618f49ee
--- /dev/null
+++ b/docs/vite-plugin-webgl-examples.ts
@@ -0,0 +1,182 @@
+import fs from 'node:fs';
+import path from 'node:path';
+import type { Plugin } from 'vite';
+
+/**
+ * LayerChart's examples drawn with WebGL, for the layer toggle's `WebGL`.
+ *
+ * An example in `include` can be when it draws in a `` with no `type` (so in the chart's
+ * `settings.layer`) and every component it imports from `layerchart` (or `layerchart/geo`, `layerchart/graph`) is
+ * one `@layerchart/webgl` exports too. Its WebGL version (`.svelte?webgl`) imports those
+ * from `@layerchart/webgl` instead, whose `Layer` draws a `` scene for `settings.layer`
+ * `webgl`, and whose marks draw their WebGL versions in it.
+ *
+ * `virtual:webgl-examples` lists them, as `/` (ex. `Points/basic`) to a loader
+ * of the version's component and source, and `nativeWebGLExamples` those written with
+ * `@layerchart/webgl` (ex. `Points/galaxy`), which draw with WebGL whatever the layer toggle.
+ */
+export function webglExamples({
+ examplesDir = 'src/examples/components',
+ webglIndex = '../packages/webgl/src/lib/index.ts',
+ include
+}: {
+ examplesDir?: string;
+ webglIndex?: string;
+ /**
+ * The examples checked to draw the same with WebGL (`/`). Many that qualify
+ * by their imports don't yet: `@layerchart/webgl`'s marks lack some of core's options. Every
+ * one that qualifies without it (to check them).
+ */
+ include?: string[];
+}): Plugin {
+ const VIRTUAL = 'virtual:webgl-examples';
+ const RESOLVED = '\0' + VIRTUAL;
+ let root = process.cwd();
+ let webglNames = new Set();
+
+ return {
+ name: 'webgl-examples',
+ enforce: 'pre',
+ configResolved(config) {
+ root = config.root;
+ webglNames = webglExports(fs.readFileSync(path.resolve(root, webglIndex), 'utf-8'));
+ },
+ resolveId(id) {
+ if (id === VIRTUAL) return RESOLVED;
+ },
+ load(id) {
+ if (id === RESOLVED) {
+ const dir = path.resolve(root, examplesDir);
+ const entries: string[] = [];
+ const native: string[] = [];
+ for (const component of fs.readdirSync(dir).sort()) {
+ const componentDir = path.join(dir, component);
+ if (!fs.statSync(componentDir).isDirectory()) continue;
+ for (const file of fs.readdirSync(componentDir).sort()) {
+ if (!file.endsWith('.svelte')) continue;
+ const key = `${component}/${file.slice(0, -'.svelte'.length)}`;
+ const source = fs.readFileSync(path.join(componentDir, file), 'utf-8');
+ if (isNativeWebGL(source)) {
+ native.push(key);
+ continue;
+ }
+ if (include && !include.includes(key)) continue;
+ if (!toWebGL(source, webglNames)) continue;
+ const url = `/${examplesDir}/${component}/${file}`;
+ entries.push(
+ `${JSON.stringify(key)}: () => Promise.all([import(${JSON.stringify(`${url}?webgl`)}), import(${JSON.stringify(`${url}?webgl&raw`)})]).then(([module, raw]) => ({ component: module.default, source: raw.default }))`
+ );
+ }
+ }
+ return (
+ `export const webglExamples = {\n${entries.join(',\n')}\n};\n` +
+ `export const nativeWebGLExamples = new Set(${JSON.stringify(native)});\n`
+ );
+ }
+
+ const [file, query] = id.split('?');
+ if (!query || !file.endsWith('.svelte')) return;
+ const params = new URLSearchParams(query);
+ if (!params.has('webgl')) return;
+ this.addWatchFile(file);
+ const source = toWebGL(fs.readFileSync(file, 'utf-8'), webglNames);
+ if (source == null) throw new Error(`${file} has no WebGL version`);
+ return params.has('raw') ? `export default ${JSON.stringify(source)};` : source;
+ },
+ // Whether an example qualifies can change with its source (or a new one)
+ configureServer(server) {
+ server.watcher.on('all', (_event, file) => {
+ if (!file.includes(examplesDir)) return;
+ for (const environment of Object.values(server.environments)) {
+ const module = environment.moduleGraph.getModuleById(RESOLVED);
+ if (module) environment.moduleGraph.invalidateModule(module);
+ }
+ });
+ }
+ };
+}
+
+/** The values `@layerchart/webgl` exports (its own, and those it re-exports from `layerchart`) */
+function webglExports(index: string) {
+ const names = new Set();
+ for (const [, list] of index.matchAll(/^export \{([^}]*)\}/gm)) {
+ for (const specifier of list.split(',')) {
+ const name = specifier
+ .trim()
+ .split(/\s+as\s+/)
+ .pop();
+ if (name) names.add(name);
+ }
+ }
+ return names;
+}
+
+/** Written with `@layerchart/webgl` (ex. a 3D chart in a `` layer) */
+export function isNativeWebGL(source: string) {
+ return /from '@layerchart\/webgl(\/webgl)?'/.test(source);
+}
+
+const IMPORT =
+ /^([ \t]*)import \{([^}]*)\} from '(layerchart|layerchart\/geo|layerchart\/graph|layerchart\/hierarchy|layerchart\/force)';?$/gm;
+
+/** Layers, which draw in their own way whatever the toggle (ex. an `Html` layer of labels) */
+const LAYERS = new Set(['Svg', 'Canvas', 'Html']);
+
+/**
+ * An example's source with its components imported from `@layerchart/webgl`, or `null` if it
+ * can't draw with WebGL
+ */
+export function toWebGL(source: string, webglNames: Set): string | null {
+ // Something drawn in the chart's layer (`settings.layer`): a `` with no `type`, a
+ // simplified chart, or a `Chart` drawing its `marks` in its own. Layers of a given type (ex.
+ // `` labels) draw as they do whatever the toggle, so they're kept.
+ const simplified = /<(ArcChart|AreaChart|BarChart|LineChart|PieChart|ScatterChart)[\s>/]/.test(
+ source
+ );
+ const layers = [...source.matchAll(/]*)>/g)].map((m) => m[1]);
+ const untyped = layers.some((attrs) => !/\btype\s*=|\{type\}/.test(attrs));
+ // A type decided as it runs (ex. `type={layer}`) can't be told apart
+ if (layers.some((attrs) => /\btype=\{|\{type\}/.test(attrs))) return null;
+ const explicit = /<(Svg|Canvas|Html)[\s>]/.test(source);
+ const chartOnly = /]/.test(source) && !layers.length && !explicit;
+ if (/]/.test(source)) return null;
+ if (!simplified && !untyped && !chartOnly) return null;
+ // Per-layer imports draw in their layer only
+ if (/from 'layerchart\/(svg|canvas|html)'/.test(source)) return null;
+ // Its own components could draw LayerChart's marks, which a WebGL scene doesn't
+ if (/from '\.{1,2}\/[^']*\.svelte'/.test(source)) return null;
+
+ let qualifies = true;
+ const rewritten = source.replace(IMPORT, (_whole, indent: string, list: string, from: string) => {
+ const kept: string[] = [];
+ const moved: string[] = [];
+ for (const raw of list.split(',')) {
+ const specifier = raw.trim();
+ if (!specifier) continue;
+ const name = specifier.replace(/^type\s+/, '').split(/\s+as\s+/)[0];
+ const isType = specifier.startsWith('type ');
+ if (!isType && webglNames.has(name)) {
+ moved.push(specifier);
+ } else {
+ // A component `@layerchart/webgl` doesn't have would draw nothing in its scene (other
+ // names, ex. `ChartState` as a type, are fine)
+ const alias = specifier.split(/\s+as\s+/).pop()!;
+ if (
+ !isType &&
+ !LAYERS.has(name) &&
+ /^[A-Z]/.test(name) &&
+ new RegExp(`<${alias}[\\s.>/]`).test(source)
+ )
+ qualifies = false;
+ kept.push(specifier);
+ }
+ }
+ return [
+ moved.length ? `${indent}import { ${moved.join(', ')} } from '@layerchart/webgl';` : null,
+ kept.length ? `${indent}import { ${kept.join(', ')} } from '${from}';` : null
+ ]
+ .filter(Boolean)
+ .join('\n');
+ });
+ return qualifies && rewritten !== source ? rewritten : null;
+}
diff --git a/docs/vite.config.ts b/docs/vite.config.ts
index 0106832f46..4c5a4210bf 100644
--- a/docs/vite.config.ts
+++ b/docs/vite.config.ts
@@ -6,6 +6,8 @@ import contentCollections from '@content-collections/vite';
import Icons from 'unplugin-icons/vite';
import { sandboxRegistry } from './src/lib/sandbox/registry-plugin';
import { workerWasm } from './vite-plugin-worker-wasm';
+import { webglExamples } from './vite-plugin-webgl-examples';
+import { checkedWebGLExamples } from './webgl-examples';
// import devtoolsJson from 'vite-plugin-devtools-json';
const isTest = process.env.VITEST === 'true';
@@ -43,6 +45,11 @@ export default defineConfig({
tailwindcss(),
sveltekit(),
sandboxRegistry(),
+ // LayerChart's examples drawn with WebGL, for the layer toggle (`WEBGL_EXAMPLES=all` for every
+ // one that qualifies, to check them)
+ webglExamples({
+ include: process.env.WEBGL_EXAMPLES === 'all' ? undefined : checkedWebGLExamples
+ }),
// The share cards' renderers (`routes/og`), which load WebAssembly
workerWasm({ packages: ['@cf-wasm/satori', '@cf-wasm/resvg', '@jsquash/webp'] }),
!isTest && contentCollections(),
diff --git a/docs/webgl-examples.ts b/docs/webgl-examples.ts
new file mode 100644
index 0000000000..3e003f9801
--- /dev/null
+++ b/docs/webgl-examples.ts
@@ -0,0 +1,961 @@
+/**
+ * LayerChart's examples checked to draw the same with WebGL, shown drawn with it when the layer
+ * toggle is on `WebGL` (see `vite-plugin-webgl-examples.ts`). Checked side by side with SVG
+ * (`WEBGL_EXAMPLES=all` serves every one that qualifies). The rest that qualify differ for now:
+ * ex. rounded `Bars` / `Rect` corners, `Axis` tick-label options, and radial marks.
+ */
+export const checkedWebGLExamples = [
+ 'AnnotationLine/bar-chart',
+ 'AnnotationLine/custom-label',
+ 'AnnotationLine/custom-line',
+ 'AnnotationLine/horizontal',
+ 'AnnotationLine/horizontal-placement',
+ 'AnnotationLine/horizontal-with-range',
+ 'AnnotationLine/playground',
+ 'AnnotationLine/sloped',
+ 'AnnotationLine/vertical',
+ 'AnnotationLine/vertical-placement',
+ 'AnnotationLine/vertical-with-rotation',
+ 'AnnotationPoint/band-scale-on-axis',
+ 'AnnotationPoint/band-scale-on-value',
+ 'AnnotationPoint/custom-marker',
+ 'AnnotationPoint/line-to-point',
+ 'AnnotationPoint/link-callouts',
+ 'AnnotationPoint/on-axis-with-tooltip',
+ 'AnnotationPoint/on-series-with-line-and-tooltip',
+ 'AnnotationPoint/on-series-with-tooltip',
+ 'AnnotationPoint/playground',
+ 'AnnotationPoint/series-annotation',
+ 'AnnotationPoint/us-cities',
+ 'AnnotationPoint/world-landmarks',
+ 'AnnotationRange/bar-chart-(multiple)',
+ 'AnnotationRange/bar-chart-(single)',
+ 'AnnotationRange/bar-chart-(value)',
+ 'AnnotationRange/custom-label',
+ 'AnnotationRange/hide-tooltip',
+ 'AnnotationRange/horizontal-with-fill-multiple',
+ 'AnnotationRange/horizontal-with-pattern-lower-bound',
+ 'AnnotationRange/horizontal-with-pattern-range',
+ 'AnnotationRange/horizontal-with-pattern-upper-bound',
+ 'AnnotationRange/label-placement',
+ 'AnnotationRange/vertical-with-gradient-range',
+ 'AnnotationRange/vertical-with-pattern-lower-bound',
+ 'AnnotationRange/vertical-with-pattern-range',
+ 'AnnotationRange/vertical-with-pattern-upper-bound',
+ 'Arc/clock',
+ 'Arc/color-wheel',
+ 'Arc/concentric',
+ 'Arc/draggable-arc',
+ 'Arc/gauge',
+ 'Arc/gauge-gradient',
+ 'Arc/partial-arc',
+ 'Arc/playground',
+ 'Arc/segmented-arc',
+ 'Arc/segmented-arc-clip-mask',
+ 'Arc/speedometer',
+ 'Arc/tween-value-on-mount',
+ 'ArcChart/basic',
+ 'ArcChart/color',
+ 'ArcChart/gradient-with-text',
+ 'ArcChart/radius-fixed',
+ 'ArcChart/radius-offset',
+ 'ArcChart/radius-percent',
+ 'ArcChart/series',
+ 'ArcChart/series-arc',
+ 'ArcChart/series-individual',
+ 'ArcChart/series-labels',
+ 'ArcChart/series-motion-spring',
+ 'ArcChart/series-motion-tween',
+ 'ArcChart/series-start-180',
+ 'ArcChart/series-start-90',
+ 'ArcChart/series-track-color',
+ 'ArcChart/track-size',
+ 'Area/basic',
+ 'Area/clip-tween-on-mount',
+ 'Area/clipped-area-on-tooltip',
+ 'Area/explicit-axis-ticks-min-max',
+ 'Area/gradient',
+ 'Area/gradient-separate-stroke',
+ 'Area/highlight-color-based-on-value-using-color-scale',
+ 'Area/highlight-color-based-on-value-using-tooltip-slot-prop',
+ 'Area/multiple-series',
+ 'Area/multiple-series-highlight-on-hover',
+ 'Area/multiple-series-tweened',
+ 'Area/multiple-series-using-overrides',
+ 'Area/multiple-series-with-labels',
+ 'Area/oscilloscope-ridgeline-isometric',
+ 'Area/playground',
+ 'Area/ridgeline',
+ 'Area/ridgeline-kde',
+ 'Area/stack',
+ 'Area/stack-with-gradient',
+ 'Area/threshold-with-lineargradient',
+ 'Area/threshold-with-lineargradient-over-under',
+ 'Area/threshold-with-rectclippath',
+ 'Area/threshold-with-rectclippath-over-under',
+ 'Area/tween-on-mount',
+ 'Area/with-labels',
+ 'Area/with-tooltip-and-highlight',
+ 'AreaChart/all-zero',
+ 'AreaChart/band-scale',
+ 'AreaChart/basic',
+ 'AreaChart/brush',
+ 'AreaChart/brush-sync',
+ 'AreaChart/curve',
+ 'AreaChart/custom',
+ 'AreaChart/custom-tooltip',
+ 'AreaChart/default-series-label',
+ 'AreaChart/gradient',
+ 'AreaChart/labels',
+ 'AreaChart/line-annotation',
+ 'AreaChart/markers',
+ 'AreaChart/motion-tween',
+ 'AreaChart/null-gaps',
+ 'AreaChart/point-annotations',
+ 'AreaChart/point-scale',
+ 'AreaChart/points',
+ 'AreaChart/radial',
+ 'AreaChart/range-annotation',
+ 'AreaChart/series',
+ 'AreaChart/series-individual-tooltip',
+ 'AreaChart/series-overlap',
+ 'AreaChart/series-point-annotations',
+ 'AreaChart/series-point-click',
+ 'AreaChart/series-separate-data',
+ 'AreaChart/series-stack',
+ 'AreaChart/series-stack-diverging',
+ 'AreaChart/series-stack-expand',
+ 'AreaChart/series-stack-gradient',
+ 'AreaChart/series-stack-legend',
+ 'AreaChart/series-stack-legend-labels',
+ 'AreaChart/series-stack-legend-placement',
+ 'AreaChart/series-stack-separate-data',
+ 'AreaChart/series-tooltip-click',
+ 'AreaChart/single-axis-x',
+ 'AreaChart/single-axis-y',
+ 'AreaChart/sparkline',
+ 'AreaChart/threshold-gradient',
+ 'AreaChart/tooltip-external',
+ 'AreaChart/tooltip-fixed-with-hide-delay',
+ 'AreaChart/tooltip-locking',
+ 'Axis/arrow-markers',
+ 'Axis/auto-padding',
+ 'Axis/axis-label-placement-left-right',
+ 'Axis/axis-label-placement-top-bottom',
+ 'Axis/barchart-tickspacing',
+ 'Axis/barchart-xinterval-xinset',
+ 'Axis/explicit-ticks',
+ 'Axis/extent-ticks-only',
+ 'Axis/grid',
+ 'Axis/grid-dashed',
+ 'Axis/hide-zero-filter',
+ 'Axis/hide-zero-format',
+ 'Axis/inject-ticks',
+ 'Axis/integer-only-filter',
+ 'Axis/integer-only-format',
+ 'Axis/labels-next-hash',
+ 'Axis/linechart-tickspacing',
+ 'Axis/log-scale',
+ 'Axis/multiline-tick-labels',
+ 'Axis/multiple-axis-grid-and-rules',
+ 'Axis/multiple-axis-grid-and-rules-separate-grid',
+ 'Axis/multiple-axis-grid-with-single-rule',
+ 'Axis/multiple-axis-same-placement-bottom',
+ 'Axis/multiple-axis-same-placement-right',
+ 'Axis/override-axis-ticks-scale',
+ 'Axis/placement-bottom-left',
+ 'Axis/placement-bottom-left-rule',
+ 'Axis/placement-top-right',
+ 'Axis/placement-top-right-rule',
+ 'Axis/radial-grid',
+ 'Axis/radial-rule',
+ 'Axis/remove-tick-marks',
+ 'Axis/rotate-labels',
+ 'Axis/tick-count',
+ 'Axis/tick-label-styling',
+ 'Axis/tick-occlusion',
+ 'Axis/tick-occlusion-explicit-ticks',
+ 'Axis/tick-occlusion-priority',
+ 'Axis/tick-occlusion-rotated',
+ 'Axis/tick-occlusion-vs-tick-spacing',
+ 'Axis/tick-spacing',
+ 'Axis/time-scale-auto',
+ 'Axis/time-scale-auto-format-filtering',
+ 'Axis/time-scale-auto-multiline',
+ 'Axis/time-scale-brush',
+ 'Axis/time-scale-brush-multiline',
+ 'Axis/time-scale-explicit',
+ 'Axis/time-scale-explicit-multiline',
+ 'Axis/utc-scale',
+ 'BarChart/axis-labels-inside-bars',
+ 'BarChart/axis-labels-inside-bars-using-labels',
+ 'BarChart/both-axis-grid',
+ 'BarChart/both-axis-grid-align-between',
+ 'BarChart/brush',
+ 'BarChart/brush-band',
+ 'BarChart/brush-pan-zoom',
+ 'BarChart/brush-pan-zoom-band',
+ 'BarChart/color-bars-class',
+ 'BarChart/color-per-value',
+ 'BarChart/color-threshold',
+ 'BarChart/color-using-scale',
+ 'BarChart/company-race',
+ 'BarChart/custom-chart',
+ 'BarChart/custom-tooltip',
+ 'BarChart/duration',
+ 'BarChart/duration-bars',
+ 'BarChart/duration-bars-color',
+ 'BarChart/duration-bars-dense',
+ 'BarChart/duration-bars-dense-lanes',
+ 'BarChart/duration-bars-lanes',
+ 'BarChart/duration-civilization-timeline',
+ 'BarChart/duration-civilization-timeline-dense',
+ 'BarChart/duration-labels',
+ 'BarChart/duration-points',
+ 'BarChart/duration-points-color',
+ 'BarChart/dynamic-height',
+ 'BarChart/facet-stack-long-data',
+ 'BarChart/gradient',
+ 'BarChart/group-long-data',
+ 'BarChart/group-series',
+ 'BarChart/group-series-bar-click',
+ 'BarChart/group-series-dual-axis',
+ 'BarChart/group-series-horizontal',
+ 'BarChart/group-series-labels',
+ 'BarChart/group-series-series-long-data',
+ 'BarChart/group-stack-long-data',
+ 'BarChart/group-stack-series',
+ 'BarChart/group-stack-series-horizontal',
+ 'BarChart/highlight-below-marks',
+ 'BarChart/histogram-date-time-count',
+ 'BarChart/histogram-date-time-interval',
+ 'BarChart/histogram-horizontal',
+ 'BarChart/histogram-random-distribution',
+ 'BarChart/histogram-vertical',
+ 'BarChart/horizontal',
+ 'BarChart/labels',
+ 'BarChart/labels-inside-placement',
+ 'BarChart/labels-placement',
+ 'BarChart/language-race',
+ 'BarChart/legend-custom-labels',
+ 'BarChart/legend-group-series',
+ 'BarChart/legend-placement',
+ 'BarChart/legend-stack-series',
+ 'BarChart/line-annotation',
+ 'BarChart/motion-tween',
+ 'BarChart/oscilloscope-frequency',
+ 'BarChart/override-axis-ticks-with-custom-scale',
+ 'BarChart/pan-zoom',
+ 'BarChart/pan-zoom-band',
+ 'BarChart/pan-zoom-domain-extent',
+ 'BarChart/pan-zoom-scale-extent',
+ 'BarChart/point-annotation',
+ 'BarChart/radial-horizontal',
+ 'BarChart/radial-horizontal-color-per-value',
+ 'BarChart/radial-horizontal-duration',
+ 'BarChart/radial-horizontal-grid-between',
+ 'BarChart/radial-vertical',
+ 'BarChart/radial-vertical-arcpadding',
+ 'BarChart/radial-vertical-yrange',
+ 'BarChart/radial-weather',
+ 'BarChart/range-annotation-multiple',
+ 'BarChart/range-annotation-single',
+ 'BarChart/range-annotation-value',
+ 'BarChart/remove-rounding',
+ 'BarChart/scale-override',
+ 'BarChart/series',
+ 'BarChart/series-data',
+ 'BarChart/series-diverging',
+ 'BarChart/series-horizontal',
+ 'BarChart/series-horizontal-diverging',
+ 'BarChart/series-horizontal-diverging-as-percent',
+ 'BarChart/series-horizontal-diverging-label-gap',
+ 'BarChart/series-horizontal-diverging-split-scale',
+ 'BarChart/series-horizontal-labels',
+ 'BarChart/series-stack-separate-data',
+ 'BarChart/single-axis-x',
+ 'BarChart/single-axis-y',
+ 'BarChart/single-dimension',
+ 'BarChart/single-stack-with-indicator',
+ 'BarChart/sparkbar',
+ 'BarChart/sparkbar-fixed-position-tooltip',
+ 'BarChart/sparkbar-negative-data',
+ 'BarChart/sparkbar-within-a-paragraph',
+ 'BarChart/sparkbar-within-a-paragraph-with-tooltip-and-highlight',
+ 'BarChart/stack-long-data',
+ 'BarChart/stack-series',
+ 'BarChart/stack-series-diverging',
+ 'BarChart/stack-series-expand',
+ 'BarChart/stack-series-horizontal',
+ 'BarChart/stack-series-padded',
+ 'BarChart/time-scale-interval',
+ 'BarChart/time-scale-interval-horizontal',
+ 'BarChart/time-scale-interval-with-inset',
+ 'BarChart/tooltip-click',
+ 'BarChart/vertical-default',
+ 'BarChart/vertical-fixed-width',
+ 'BarChart/waterfall',
+ 'Bars/horizontal-average-annotation-rule',
+ 'Bars/horizontal-basic',
+ 'Bars/horizontal-calculated-value-domain-negative',
+ 'Bars/horizontal-calculated-value-domain-positive',
+ 'Bars/horizontal-candlestick-bars',
+ 'Bars/horizontal-click-handler',
+ 'Bars/horizontal-customize-individual-styles',
+ 'Bars/horizontal-gradient',
+ 'Bars/horizontal-grouped',
+ 'Bars/horizontal-grouped-and-stacked',
+ 'Bars/horizontal-grouped-stacked-or-both-transition',
+ 'Bars/horizontal-highlight-individual-bar',
+ 'Bars/horizontal-highlight-individual-bar-line',
+ 'Bars/horizontal-inside-labels',
+ 'Bars/horizontal-limit-ticks-count',
+ 'Bars/horizontal-limit-ticks-second-scale',
+ 'Bars/horizontal-multiple-diverging',
+ 'Bars/horizontal-multiple-overlapping',
+ 'Bars/horizontal-outside-labels-default',
+ 'Bars/horizontal-rounded-right-only',
+ 'Bars/horizontal-stacked',
+ 'Bars/horizontal-stacked-percent',
+ 'Bars/horizontal-stagger-tween-on-mount',
+ 'Bars/horizontal-time-scale-with-inset',
+ 'Bars/horizontal-time-scale-with-interval',
+ 'Bars/horizontal-time-scale-with-missing-data',
+ 'Bars/horizontal-tooltip-and-bar-highlight',
+ 'Bars/horizontal-tooltip-and-click-handlers-for-individual-stack-grouped-bar',
+ 'Bars/horizontal-tooltip-and-clipped-highlight',
+ 'Bars/horizontal-tooltip-and-highlight',
+ 'Bars/horizontal-tween-on-mount',
+ 'Bars/horizontal-with-grid-on-top',
+ 'Bars/horizontal-with-grid-on-top-mix-blend',
+ 'Bars/vertical-average-annotation-rule',
+ 'Bars/vertical-basic',
+ 'Bars/vertical-calculated-value-domain-negative',
+ 'Bars/vertical-calculated-value-domain-positive',
+ 'Bars/vertical-click-handler',
+ 'Bars/vertical-customize-individual-styles',
+ 'Bars/vertical-fixed-width',
+ 'Bars/vertical-gradient',
+ 'Bars/vertical-grouped',
+ 'Bars/vertical-grouped-and-stacked',
+ 'Bars/vertical-grouped-stacked-or-both-transition',
+ 'Bars/vertical-highlight-individual-bar',
+ 'Bars/vertical-highlight-individual-bar-line',
+ 'Bars/vertical-inside-labels',
+ 'Bars/vertical-limit-ticks-count',
+ 'Bars/vertical-limit-ticks-second-scale',
+ 'Bars/vertical-multiple-diverging',
+ 'Bars/vertical-multiple-diverging-rounded-specific',
+ 'Bars/vertical-multiple-overlapping',
+ 'Bars/vertical-outside-labels-default',
+ 'Bars/vertical-rounded-top-only',
+ 'Bars/vertical-stacked',
+ 'Bars/vertical-stacked-percent',
+ 'Bars/vertical-stagger-tween-on-mount',
+ 'Bars/vertical-stagger-tween-on-mount-rounded-edge',
+ 'Bars/vertical-time-scale-with-inset',
+ 'Bars/vertical-time-scale-with-interval',
+ 'Bars/vertical-time-scale-with-interval-months',
+ 'Bars/vertical-time-scale-with-missing-data',
+ 'Bars/vertical-tooltip-and-bar-highlight',
+ 'Bars/vertical-tooltip-and-click-handlers-for-individual-stack-grouped-bar',
+ 'Bars/vertical-tooltip-and-clipped-highlight',
+ 'Bars/vertical-tooltip-and-highlight',
+ 'Bars/vertical-tween-on-mount',
+ 'Bars/vertical-tween-on-mount-rounded-edge',
+ 'Bars/vertical-with-grid-on-top',
+ 'Bars/vertical-with-grid-on-top-mix-blend',
+ 'Bin/basic',
+ 'Bin/categorical',
+ 'Bin/image-render',
+ 'Bin/images',
+ 'Bin/isometric',
+ 'Bin/labels',
+ 'Bin/shapes',
+ 'Bin/size-by-count',
+ 'Bin/tooltip',
+ 'Bin/walmart',
+ 'Bin/walmart-isometric',
+ 'BoxPlot/basic',
+ 'BoxPlot/horizontal',
+ 'BoxPlot/pre-computed',
+ 'BoxPlot/styled',
+ 'BoxPlot/with-tooltip',
+ 'BoxPlot/with-violin',
+ 'Brush/basic',
+ 'Brush/html',
+ 'Brush/programmatic',
+ 'Brush/region',
+ 'Brush/two-dimensional',
+ 'Brush/vertical',
+ 'BrushContext/basic',
+ 'BrushContext/constant-labels',
+ 'BrushContext/flame-chart',
+ 'BrushContext/handle-arrows',
+ 'BrushContext/handle-labels',
+ 'BrushContext/integrated-brush-(both-axis-area)',
+ 'BrushContext/integrated-brush-(x-axis)',
+ 'BrushContext/integrated-brush-(y-axis)',
+ 'BrushContext/max-window',
+ 'BrushContext/min-max-extent',
+ 'BrushContext/minimap',
+ 'BrushContext/programmatic-control',
+ 'BrushContext/selection',
+ 'BrushContext/separate-chart-(clip-data)',
+ 'BrushContext/separate-chart-(clip-data-y-axis)',
+ 'BrushContext/separate-chart-(filter-data)',
+ 'BrushContext/simple-styling',
+ 'BrushContext/snap-to-month',
+ 'BrushContext/striped-background',
+ 'BrushContext/synced-brushes',
+ 'BrushContext/tooltip-interop',
+ 'Calendar/90-days',
+ 'Calendar/basic',
+ 'Calendar/fixed-cell-size',
+ 'Calendar/isometric',
+ 'Calendar/last-month',
+ 'Calendar/multiple-years',
+ 'Calendar/responsive-cell-size-default',
+ 'Calendar/rounded-cells',
+ 'Cell/basic',
+ 'Cell/circle',
+ 'Cell/color-scale',
+ 'Cell/punchcard',
+ 'Cell/rounded-insets',
+ 'Chart/compound-common-scale-with-extra-marks',
+ 'Chart/compound-dual-axis-with-single-chart-using-remapped-scale',
+ 'Chart/compound-dual-axis-with-stacked-charts',
+ 'Chart/compound-separate-scales-with-stacked-charts-with-inverted-range-top-down',
+ 'Chart/data-chart-multi',
+ 'Chart/data-chart-single',
+ 'Chart/data-mark-data',
+ 'Chart/data-primitive-data',
+ 'Chart/data-series-chart-data',
+ 'Chart/data-series-separate-data',
+ 'Chart/facet-annotation',
+ 'Chart/facet-bars',
+ 'Chart/facet-brush',
+ 'Chart/facet-brush-band',
+ 'Chart/facet-brush-overview',
+ 'Chart/facet-brush-summary',
+ 'Chart/facet-brush-zoom',
+ 'Chart/facet-click',
+ 'Chart/facet-click-panel',
+ 'Chart/facet-color',
+ 'Chart/facet-grid',
+ 'Chart/facet-lines',
+ 'Chart/facet-non-faceted-marks',
+ 'Chart/facet-spacing',
+ 'Chart/facet-two-dimensional',
+ 'Chart/facet-wrap',
+ 'Chart/facet-x',
+ 'Chart/facet-y',
+ 'Chart/isometric-areas',
+ 'Chart/isometric-columns',
+ 'Chart/isometric-heatmap',
+ 'Chart/isometric-pin-map',
+ 'Chart/isometric-playground',
+ 'Chart/isometric-scatter',
+ 'Chart/isometric-scatter-3d',
+ 'Chart/isometric-stacked-columns',
+ 'Chart/isometric-treemap',
+ 'Chart/mixed-marks-with-stack',
+ 'Chart/mixed-marks-with-stack-long-data',
+ 'Chart/padding-auto',
+ 'ChartGroup/basic',
+ 'ChartGroup/coordinated-views',
+ 'ChartGroup/faceted-group',
+ 'ChartGroup/highlight-only',
+ 'ChartGroup/minimap',
+ 'ChartGroup/programmatic-control',
+ 'ChartGroup/synced-brushes',
+ 'ChartGroup/synced-legend',
+ 'ChartGroup/synced-zoom',
+ 'Chord/basic',
+ 'Chord/directed',
+ 'Chord/hover',
+ 'Circle/color-via-ordinal-scale',
+ 'Circle/color-via-threshold-scale',
+ 'Circle/data-mode',
+ 'Circle/styling-using-attributes',
+ 'Circle/styling-using-classes',
+ 'Circle/styling-using-css-variables',
+ 'ClipPath/basic',
+ 'ClipPath/clip-snippet',
+ 'ClipPath/inverted',
+ 'Contour/sampled',
+ 'Contour/sampled-interactive',
+ 'Contour/volcano-filled',
+ 'Contour/volcano-filled-interactive',
+ 'Contour/volcano-isometric',
+ 'Contour/volcano-lines',
+ 'Dagre/basic',
+ 'Dagre/playground',
+ 'Dagre/software-user-flow',
+ 'Dagre/tcp-state-diagram',
+ 'Density/bandwidth',
+ 'Density/basic',
+ 'Density/stroke-only',
+ 'Density/thresholds',
+ 'Density/walmart',
+ 'Density/weighted',
+ 'Dodge/anchor',
+ 'Dodge/bank-failures',
+ 'Dodge/beeswarm',
+ 'Dodge/duration-bars-dense-lanes',
+ 'Dodge/grouped-horizontal',
+ 'Dodge/grouped-vertical',
+ 'Dodge/image-beeswarm',
+ 'Dodge/penguins',
+ 'Dodge/tech-layoffs',
+ 'Dodge/text-beeswarm',
+ 'Dodge/timeline',
+ 'Dodge/timeline-bidirectional',
+ 'Dodge/variable-radius',
+ 'Ellipse/color-via-ordinal-scale',
+ 'Ellipse/color-via-threshold-scale',
+ 'Ellipse/data-mode',
+ 'Ellipse/styling-using-attributes',
+ 'Ellipse/styling-using-classes',
+ 'Ellipse/styling-using-css-variables',
+ 'ForceSimulation/beeswarm',
+ 'ForceSimulation/collision-detection',
+ 'ForceSimulation/disjoint-graph',
+ 'ForceSimulation/games-industry-layoffs',
+ 'ForceSimulation/graph-playground',
+ 'ForceSimulation/group',
+ 'ForceSimulation/text',
+ 'ForceSimulation/tree',
+ 'Frame/basic',
+ 'Frame/border',
+ 'Frame/full',
+ 'Frame/gradient',
+ 'GeoBin/columns',
+ 'GeoBin/dot-globe',
+ 'GeoBin/land',
+ 'GeoBin/us-population',
+ 'GeoBin/world-airports',
+ 'GeoBin/world-population',
+ 'GeoCircle/earthquake-globe',
+ 'GeoCircle/playground',
+ 'GeoClipPath/basic',
+ 'GeoPath/animated-globe',
+ 'GeoPath/choropleth',
+ 'GeoPath/eclipses-globe',
+ 'GeoPath/election-isometric',
+ 'GeoPath/geojson-drilldown',
+ 'GeoPath/interpolating-projections',
+ 'GeoPath/paint-brush-selection',
+ 'GeoPath/sketchy-globe',
+ 'GeoPath/spike-map',
+ 'GeoPath/submarine-cables-globe',
+ 'GeoPath/tooltip',
+ 'GeoPath/transform-canvas',
+ 'GeoPath/transform-canvas-scale-extent',
+ 'GeoPath/transform-globe-constrain',
+ 'GeoPath/transform-globe-inertia',
+ 'GeoPath/transform-projection',
+ 'GeoPath/transform-world-canvas',
+ 'GeoPath/transform-world-projection',
+ 'GeoPath/translucent-globe',
+ 'GeoPath/us-country-map',
+ 'GeoPath/us-state',
+ 'GeoPath/us-state-with-counties',
+ 'GeoPath/us-state-with-surrounding-states',
+ 'GeoPoint/icons',
+ 'GeoPoint/us-airports',
+ 'GeoPoint/us-state-capitals',
+ 'GeoPoint/world-airports',
+ 'GeoPoint/world-capitals',
+ 'GeoProjection/geojson-preview',
+ 'GeoProjection/projection-playground',
+ 'GeoProjection/satellite',
+ 'GeoProjection/true-size',
+ 'GeoSpline/draggable-globe',
+ 'GeoSpline/world-map',
+ 'GeoTile/basic',
+ 'GeoTile/clipped',
+ 'GeoTile/zoomable',
+ 'GeoTile/zoomable-seamless-layers',
+ 'GeoTile/zoomable-with-padding',
+ 'Graticule/basic',
+ 'Grid/band-scale-between',
+ 'Grid/band-scale-default',
+ 'Grid/basic',
+ 'Grid/dashed-lines',
+ 'Grid/explicit-ticks',
+ 'Grid/inject-tick-value',
+ 'Grid/integer-only',
+ 'Grid/padding',
+ 'Grid/radial',
+ 'Grid/radial-linear',
+ 'Grid/tick-count',
+ 'Grid/tick-count-null',
+ 'Grid/x-only',
+ 'Grid/y-only',
+ 'Group/basic',
+ 'Group/data-mode',
+ 'Group/series-state',
+ 'Hull/geo',
+ 'Hull/scatter',
+ 'Image/college-football-map',
+ 'Image/college-football-upsets',
+ 'Image/country-flags',
+ 'Image/pixel-mode',
+ 'Image/sports-logos',
+ 'Image/sports-territories',
+ 'Image/us-presidents',
+ 'Labels/shape-area',
+ 'Labels/shape-area-chart',
+ 'Labels/shape-geo',
+ 'Labels/voronoi',
+ 'Labels/voronoi-geo',
+ 'Line/color-via-ordinal-scale',
+ 'Line/color-via-threshold-scale',
+ 'Line/data-mode',
+ 'Line/styling-using-attributes',
+ 'Line/styling-using-classes',
+ 'Line/styling-using-css-variables',
+ 'LineChart/axis-labels-inside',
+ 'LineChart/basic',
+ 'LineChart/brush',
+ 'LineChart/brush-pan-zoom',
+ 'LineChart/bump-sports-rankings',
+ 'LineChart/curve',
+ 'LineChart/custom',
+ 'LineChart/custom-tooltip',
+ 'LineChart/default-series-label',
+ 'LineChart/draw',
+ 'LineChart/dynamic-data',
+ 'LineChart/facet-series-data',
+ 'LineChart/gradient-encoding',
+ 'LineChart/gradient-threshold',
+ 'LineChart/labels',
+ 'LineChart/labels-with-points',
+ 'LineChart/labels-within-points',
+ 'LineChart/large-radial-series',
+ 'LineChart/large-series',
+ 'LineChart/legend',
+ 'LineChart/line-annotation',
+ 'LineChart/long-data',
+ 'LineChart/motion-tween',
+ 'LineChart/null-dashed-gaps',
+ 'LineChart/null-gaps',
+ 'LineChart/override-color',
+ 'LineChart/pan-zoom',
+ 'LineChart/pan-zoom-custom-constrain',
+ 'LineChart/pan-zoom-domain-extent',
+ 'LineChart/pan-zoom-dynamic-data',
+ 'LineChart/pan-zoom-with-overview',
+ 'LineChart/perf-dimension-arrays',
+ 'LineChart/perf-dimension-arrays-processed',
+ 'LineChart/perf-series-arrays',
+ 'LineChart/perf-wide-data',
+ 'LineChart/perf-wide-data-processed',
+ 'LineChart/persist-brush-zoom',
+ 'LineChart/persist-series',
+ 'LineChart/point-annotations',
+ 'LineChart/points',
+ 'LineChart/radar',
+ 'LineChart/radar-rounded',
+ 'LineChart/radar-series',
+ 'LineChart/range-annotation',
+ 'LineChart/series',
+ 'LineChart/series-brush',
+ 'LineChart/series-custom-highlight-point',
+ 'LineChart/series-individual-tooltip',
+ 'LineChart/series-labels-hover',
+ 'LineChart/series-point-annotations',
+ 'LineChart/series-point-click',
+ 'LineChart/series-programmatic-control',
+ 'LineChart/series-separate-data',
+ 'LineChart/series-separate-data-diff-length',
+ 'LineChart/series-vertical',
+ 'LineChart/series-with-nulls',
+ 'LineChart/single-axis-x',
+ 'LineChart/single-axis-y',
+ 'LineChart/smart-labels-with-points',
+ 'LineChart/sparkline',
+ 'LineChart/sparkline-fixed-position-tooltip',
+ 'LineChart/sparkline-within-a-paragraph',
+ 'LineChart/sparkline-within-a-paragraph-with-tooltip-and-highlight',
+ 'LineChart/sparkline-zero-axis',
+ 'LineChart/svelte-milestones',
+ 'LineChart/tooltip-click',
+ 'LineChart/vertical',
+ 'LinearGradient/direction-with-custom-colors',
+ 'LinearGradient/explicit-offsets',
+ 'LinearGradient/tailwind-colors',
+ 'LinearGradient/units',
+ 'Link/bended-arrows',
+ 'Link/curves',
+ 'Link/playground',
+ 'Link/types',
+ 'Marker/line',
+ 'Marker/orientation',
+ 'Marker/spline',
+ 'Marker/spline-w-thicker-stroke',
+ 'Marker/styling',
+ 'Month/90-days',
+ 'Month/basic',
+ 'Month/custom-cell-size',
+ 'Month/multiple-years',
+ 'Month/without-day-numbers',
+ 'Month/without-month-labels',
+ 'Pack/basic',
+ 'Partition/filterable',
+ 'Partition/flame-graph',
+ 'Partition/horizontal',
+ 'Partition/sunburst',
+ 'Partition/vertical',
+ 'Path/basic',
+ 'Pattern/circles',
+ 'Pattern/lineargradient-as-pattern',
+ 'Pattern/lines',
+ 'Pattern/rects',
+ 'Pattern/with-fill-color',
+ 'Pattern/with-lineargradient',
+ 'Pie/basic',
+ 'Pie/default-slot-render-each-arc',
+ 'Pie/disable-sorting',
+ 'Pie/inner-radius-negative',
+ 'Pie/inner-radius-positive',
+ 'Pie/inner-radius-zero-one',
+ 'Pie/labels',
+ 'Pie/labels-centroid',
+ 'Pie/labels-centroid-multiple',
+ 'Pie/labels-outer',
+ 'Pie/labels-outer-radial',
+ 'Pie/labels-outer-with-padding',
+ 'Pie/multiple-data-prop',
+ 'Pie/offset',
+ 'Pie/outer-radius',
+ 'Pie/pad-angle',
+ 'Pie/pad-angle-with-inner-radius',
+ 'Pie/partial-range-chart-xrange',
+ 'Pie/partial-range-range-prop',
+ 'Pie/placement',
+ 'Pie/placement-center',
+ 'Pie/placement-left',
+ 'Pie/placement-right',
+ 'Pie/tooltip',
+ 'Pie/tooltip-with-arcs-slot',
+ 'Pie/tweened',
+ 'PieChart/arc',
+ 'PieChart/arc-props',
+ 'PieChart/basic',
+ 'PieChart/colors-data-prop',
+ 'PieChart/colors-interpolator',
+ 'PieChart/colors-scheme',
+ 'PieChart/colors-variables',
+ 'PieChart/donut',
+ 'PieChart/donut-with-text',
+ 'PieChart/labels',
+ 'PieChart/labels-callout',
+ 'PieChart/legend',
+ 'PieChart/legend-custom-label',
+ 'PieChart/legend-placement',
+ 'PieChart/legend-programmatic-control',
+ 'PieChart/legend-responsive',
+ 'PieChart/legend-with-padding',
+ 'PieChart/motion-spring',
+ 'PieChart/motion-tween',
+ 'PieChart/offset-slice',
+ 'PieChart/placement-custom',
+ 'PieChart/placement-left',
+ 'PieChart/placement-right',
+ 'PieChart/radius-fixed',
+ 'PieChart/radius-offset',
+ 'PieChart/radius-percent',
+ 'PieChart/segments',
+ 'PieChart/series',
+ 'PieChart/series-click',
+ 'PieChart/series-props',
+ 'PieChart/tooltip-click',
+ 'Point/basic',
+ 'Points/basic',
+ 'Points/color-via-class',
+ 'Points/color-via-fill',
+ 'Points/color-via-ordinal-scale',
+ 'Points/color-via-threshold-scale',
+ 'Points/with-labels',
+ 'Points/with-tooltip-and-highlight',
+ 'Polygon/10-point-star',
+ 'Polygon/12-point-star',
+ 'Polygon/14-point-star',
+ 'Polygon/16-point-star',
+ 'Polygon/18-point-star',
+ 'Polygon/20-point-star',
+ 'Polygon/6-point-star',
+ 'Polygon/8-point-star',
+ 'Polygon/arrow',
+ 'Polygon/color-via-ordinal-scale',
+ 'Polygon/color-via-threshold-scale',
+ 'Polygon/cross',
+ 'Polygon/data-mode',
+ 'Polygon/diamond',
+ 'Polygon/hexagon',
+ 'Polygon/octagon',
+ 'Polygon/parallelogram',
+ 'Polygon/pentagon',
+ 'Polygon/playground',
+ 'Polygon/rectangle',
+ 'Polygon/rhombus',
+ 'Polygon/square',
+ 'Polygon/trapezoid',
+ 'Polygon/triangle',
+ 'Raster/mandelbrot',
+ 'Raster/math-functions',
+ 'Raster/sampled',
+ 'Raster/us-water-vapor',
+ 'Raster/volcano',
+ 'Raster/with-contour-overlay',
+ 'Rect/color-via-ordinal-scale',
+ 'Rect/color-via-threshold-scale',
+ 'Rect/data-mode-edge',
+ 'Rect/playground',
+ 'Rect/styling-using-attributes',
+ 'Rect/styling-using-classes',
+ 'Rect/styling-using-css-variables',
+ 'Rule/annotation-x',
+ 'Rule/annotation-y',
+ 'Rule/baseline-top-right',
+ 'Rule/baseline-x-negative',
+ 'Rule/baseline-x-y',
+ 'Rule/baseline-y-negative',
+ 'Rule/candlestick',
+ 'Rule/candlestick-open-close-line-color',
+ 'Rule/candlestick-with-brushing',
+ 'Rule/data-x-band',
+ 'Rule/data-x-date',
+ 'Rule/data-x-range',
+ 'Rule/data-y-range',
+ 'Rule/lollipop',
+ 'Sankey/complex',
+ 'Sankey/node-select',
+ 'Sankey/simple',
+ 'Sankey/tooltip',
+ 'ScatterChart/basic',
+ 'ScatterChart/brush',
+ 'ScatterChart/custom',
+ 'ScatterChart/custom-tooltip',
+ 'ScatterChart/date-series-color-scale',
+ 'ScatterChart/domain-baseline',
+ 'ScatterChart/domain-nice',
+ 'ScatterChart/domain-padding',
+ 'ScatterChart/labels',
+ 'ScatterChart/line-annotation',
+ 'ScatterChart/point-annotations',
+ 'ScatterChart/punchcard',
+ 'ScatterChart/radius-scale',
+ 'ScatterChart/range-annotation-both',
+ 'ScatterChart/range-annotation-horizontal',
+ 'ScatterChart/range-annotation-vertical',
+ 'ScatterChart/series',
+ 'ScatterChart/series-custom-labels',
+ 'ScatterChart/series-legend',
+ 'ScatterChart/series-tween',
+ 'ScatterChart/series-with-radius',
+ 'ScatterChart/single-axis-x',
+ 'ScatterChart/single-axis-y',
+ 'ScatterChart/tooltip-click',
+ 'Spline/basic',
+ 'Spline/basic-start-and-end-snippets',
+ 'Spline/draw',
+ 'Spline/end-slot-with-draw-with-value',
+ 'Spline/end-snippet-with-draw',
+ 'Spline/geo-routes',
+ 'Spline/gradient-encoding',
+ 'Spline/gradient-threshold',
+ 'Spline/label-using-start-end-snippets',
+ 'Spline/markers-arrows',
+ 'Spline/math-formula',
+ 'Spline/missing-data-dashed',
+ 'Spline/missing-data-with-markers',
+ 'Spline/multiple-series',
+ 'Spline/multiple-series-highlight-on-hover',
+ 'Spline/multiple-series-tweened',
+ 'Spline/multiple-series-using-overrides',
+ 'Spline/multiple-series-with-labels',
+ 'Spline/parallel-coordinates',
+ 'Spline/parallel-coordinates-brush',
+ 'Spline/parallel-coordinates-faceted',
+ 'Spline/parallel-coordinates-mixed',
+ 'Spline/playground',
+ 'Spline/radial-line-with-areas',
+ 'Spline/radial-multi-year-lines',
+ 'Spline/radial-radar',
+ 'Spline/stroke-grouping',
+ 'Spline/stroke-grouping-with-legend',
+ 'Spline/tween-on-mount',
+ 'Spline/tweened',
+ 'Spline/vertical',
+ 'Spline/with-labels',
+ 'Spline/with-tooltip-and-highlight',
+ 'Text/color-via-ordinal-scale',
+ 'Text/color-via-threshold-scale',
+ 'Text/data-mode',
+ 'Text/segments',
+ 'Text/truncate-axis-labels',
+ 'Text/word-wrap-axis-labels',
+ 'Text/word-wrap-with-explicit-newline',
+ 'Tooltip/anchor-location',
+ 'Tooltip/area',
+ 'Tooltip/basic',
+ 'Tooltip/color-swatch',
+ 'Tooltip/color-swatch-using-theme',
+ 'Tooltip/custom-content',
+ 'Tooltip/data-snapping',
+ 'Tooltip/default-mouse-position-with-offset',
+ 'Tooltip/disable-motion',
+ 'Tooltip/duration',
+ 'Tooltip/externally-access-tooltip-data',
+ 'Tooltip/invert-variant',
+ 'Tooltip/multiple-overlapping-bars',
+ 'Tooltip/multiple-overlapping-durations',
+ 'Tooltip/multiple-tooltips-with-fixed-single-axis',
+ 'Tooltip/multiple-tooltips-with-fixed-single-axis-scaleband',
+ 'Tooltip/portal-overflow',
+ 'Tooltip/programmatic-control',
+ 'Tooltip/scatter-plot',
+ 'Tooltip/simple-bars',
+ 'Tooltip/single-date-time',
+ 'Tooltip/stacked-area',
+ 'Trail/basic',
+ 'Trail/curves',
+ 'Trail/playground',
+ 'Trail/tdf-stage',
+ 'TransformContext/playground',
+ 'Tree/basic',
+ 'Tree/html-nodes',
+ 'Tree/isometric',
+ 'Tree/playground',
+ 'Treemap/basic',
+ 'Treemap/complex',
+ 'Treemap/nested-filter',
+ 'Treemap/nested-zoom',
+ 'Treemap/playground',
+ 'Treemap/stacked-zoom',
+ 'Vector/anchor',
+ 'Vector/basic',
+ 'Vector/data-mode',
+ 'Vector/election-wind-map',
+ 'Vector/shapes',
+ 'Vector/wind-map',
+ 'Violin/bandwidth',
+ 'Violin/basic',
+ 'Violin/horizontal',
+ 'Violin/with-box-median',
+ 'Waffle/auto-multiple',
+ 'Waffle/band-padding',
+ 'Waffle/basic',
+ 'Waffle/circular-cells',
+ 'Waffle/horizontal',
+ 'Waffle/months',
+ 'Waffle/olympians-by-birth-year',
+ 'Waffle/olympians-by-sex',
+ 'Waffle/olympians-weight-by-sex',
+ 'Waffle/penguins',
+ 'Waffle/stacked',
+ 'Waffle/unit-multiple'
+];
diff --git a/packages/layerchart/package.json b/packages/layerchart/package.json
index 3c35c5c1ca..1e992bf2ae 100644
--- a/packages/layerchart/package.json
+++ b/packages/layerchart/package.json
@@ -130,6 +130,11 @@
"svelte": "./dist/graph.js",
"default": "./dist/graph.js"
},
+ "./base": {
+ "types": "./dist/base.d.ts",
+ "svelte": "./dist/base.js",
+ "default": "./dist/base.js"
+ },
"./svg": {
"types": "./dist/svg.d.ts",
"svelte": "./dist/svg.js",
diff --git a/packages/layerchart/src/lib/base.ts b/packages/layerchart/src/lib/base.ts
new file mode 100644
index 0000000000..29b0c2b669
--- /dev/null
+++ b/packages/layerchart/src/lib/base.ts
@@ -0,0 +1,267 @@
+// The layer-agnostic bases of LayerChart's marks and charts, with the primitives they draw with
+// left to their callers (ex. ` `): for a package drawing
+// LayerChart's components in a layer of its own, as `@layerchart/webgl` does. Each takes its
+// component's props, plus its primitives (`BaseLayerComponents`).
+
+export { default as AnnotationLineBase } from './components/AnnotationLine/AnnotationLine.base.svelte';
+export type {
+ AnnotationLineBaseLayerComponents,
+ AnnotationLineBaseProps,
+} from './components/AnnotationLine/AnnotationLine.base.svelte';
+export { default as AnnotationPointBase } from './components/AnnotationPoint/AnnotationPoint.base.svelte';
+export type {
+ AnnotationPointBaseLayerComponents,
+ AnnotationPointBaseProps,
+} from './components/AnnotationPoint/AnnotationPoint.base.svelte';
+export { default as AnnotationRangeBase } from './components/AnnotationRange/AnnotationRange.base.svelte';
+export type {
+ AnnotationRangeBaseLayerComponents,
+ AnnotationRangeBaseProps,
+} from './components/AnnotationRange/AnnotationRange.base.svelte';
+export { default as ArcBase } from './components/Arc/Arc.base.svelte';
+export type { ArcBaseLayerComponents, ArcBaseProps } from './components/Arc/Arc.base.svelte';
+export { default as ArcLabelBase } from './components/ArcLabel/ArcLabel.base.svelte';
+export type {
+ ArcLabelBaseLayerComponents,
+ ArcLabelBaseProps,
+} from './components/ArcLabel/ArcLabel.base.svelte';
+export { default as AreaBase } from './components/Area/Area.base.svelte';
+export type { AreaBaseLayerComponents, AreaBaseProps } from './components/Area/Area.base.svelte';
+export { default as AxisBase } from './components/Axis/Axis.base.svelte';
+export type { AxisBaseLayerComponents, AxisBaseProps } from './components/Axis/Axis.base.svelte';
+export { default as BarBase } from './components/Bar/Bar.base.svelte';
+export type { BarBaseLayerComponents, BarBaseProps } from './components/Bar/Bar.base.svelte';
+export { default as BarsBase } from './components/Bars/Bars.base.svelte';
+export type { BarsBaseLayerComponents, BarsBaseProps } from './components/Bars/Bars.base.svelte';
+export { default as BinBase } from './components/Bin/Bin.base.svelte';
+export type { BinBaseLayerComponents, BinBaseProps } from './components/Bin/Bin.base.svelte';
+export { default as BoxPlotBase } from './components/BoxPlot/BoxPlot.base.svelte';
+export type {
+ BoxPlotBaseLayerComponents,
+ BoxPlotBaseProps,
+} from './components/BoxPlot/BoxPlot.base.svelte';
+export { default as BrushBase } from './components/Brush/Brush.base.svelte';
+export type { BrushBaseProps } from './components/Brush/Brush.base.svelte';
+export { default as CalendarBase } from './components/Calendar/Calendar.base.svelte';
+export type {
+ CalendarBaseLayerComponents,
+ CalendarBaseProps,
+} from './components/Calendar/Calendar.base.svelte';
+export { default as CellBase } from './components/Cell/Cell.base.svelte';
+export type { CellBaseLayerComponents, CellBaseProps } from './components/Cell/Cell.base.svelte';
+export { default as ChartBase } from './components/Chart/Chart.base.svelte';
+export type { ChartBaseProps } from './components/Chart/Chart.base.svelte';
+export { default as ChartChildrenBase } from './components/ChartChildren/ChartChildren.base.svelte';
+export type {
+ ChartChildrenBaseLayerComponents,
+ ChartChildrenBaseProps,
+} from './components/ChartChildren/ChartChildren.base.svelte';
+export { default as ChartClipPathBase } from './components/ChartClipPath/ChartClipPath.base.svelte';
+export type {
+ ChartClipPathBaseLayerComponents,
+ ChartClipPathBaseProps,
+} from './components/ChartClipPath/ChartClipPath.base.svelte';
+export { default as CircleClipPathBase } from './components/CircleClipPath/CircleClipPath.base.svelte';
+export type {
+ CircleClipPathBaseLayerComponents,
+ CircleClipPathBaseProps,
+} from './components/CircleClipPath/CircleClipPath.base.svelte';
+export { default as ContourBase } from './components/Contour/Contour.base.svelte';
+export type {
+ ContourBaseLayerComponents,
+ ContourBaseProps,
+} from './components/Contour/Contour.base.svelte';
+export { default as DensityBase } from './components/Density/Density.base.svelte';
+export type {
+ DensityBaseLayerComponents,
+ DensityBaseProps,
+} from './components/Density/Density.base.svelte';
+export { default as FrameBase } from './components/Frame/Frame.base.svelte';
+export type {
+ FrameBaseLayerComponents,
+ FrameBaseProps,
+} from './components/Frame/Frame.base.svelte';
+export { default as GridBase } from './components/Grid/Grid.base.svelte';
+export type { GridBaseLayerComponents, GridBaseProps } from './components/Grid/Grid.base.svelte';
+export { default as HighlightBase } from './components/Highlight/Highlight.base.svelte';
+// What `Highlight` marks for the hovered row (its points, lines, area), for drawing them in a layer
+// of one's own
+export { HighlightState } from './components/Highlight/Highlight.shared.svelte.js';
+export type { HighlightPoint } from './components/Highlight/Highlight.shared.svelte.js';
+export type {
+ HighlightBaseLayerComponents,
+ HighlightBaseProps,
+} from './components/Highlight/Highlight.base.svelte';
+export { default as HullBase } from './components/Hull/Hull.base.svelte';
+export type { HullBaseLayerComponents, HullBaseProps } from './components/Hull/Hull.base.svelte';
+export { default as LabelsBase } from './components/Labels/Labels.base.svelte';
+export type {
+ LabelsBaseLayerComponents,
+ LabelsBaseProps,
+} from './components/Labels/Labels.base.svelte';
+export { default as LinkBase } from './components/Link/Link.base.svelte';
+export type { LinkBaseLayerComponents, LinkBaseProps } from './components/Link/Link.base.svelte';
+export { default as MonthBase } from './components/Month/Month.base.svelte';
+export type {
+ MonthBaseLayerComponents,
+ MonthBaseProps,
+} from './components/Month/Month.base.svelte';
+export { default as PieBase } from './components/Pie/Pie.base.svelte';
+export type { PieBaseLayerComponents, PieBaseProps } from './components/Pie/Pie.base.svelte';
+export { default as PointsBase } from './components/Points/Points.base.svelte';
+export type {
+ PointsBaseLayerComponents,
+ PointsBaseProps,
+} from './components/Points/Points.base.svelte';
+export { default as RasterBase } from './components/Raster/Raster.base.svelte';
+export type {
+ RasterBaseLayerComponents,
+ RasterBaseProps,
+} from './components/Raster/Raster.base.svelte';
+export { default as RectClipPathBase } from './components/RectClipPath/RectClipPath.base.svelte';
+export type {
+ RectClipPathBaseLayerComponents,
+ RectClipPathBaseProps,
+} from './components/RectClipPath/RectClipPath.base.svelte';
+export { default as RuleBase } from './components/Rule/Rule.base.svelte';
+export type { RuleBaseLayerComponents, RuleBaseProps } from './components/Rule/Rule.base.svelte';
+export { default as SplineBase } from './components/Spline/Spline.base.svelte';
+export type {
+ SplineBaseLayerComponents,
+ SplineBaseProps,
+} from './components/Spline/Spline.base.svelte';
+export { default as ThresholdBase } from './components/Threshold/Threshold.base.svelte';
+export type {
+ ThresholdBaseLayerComponents,
+ ThresholdBaseProps,
+} from './components/Threshold/Threshold.base.svelte';
+export { default as TrailBase } from './components/Trail/Trail.base.svelte';
+export type {
+ TrailBaseLayerComponents,
+ TrailBaseProps,
+} from './components/Trail/Trail.base.svelte';
+export { default as VectorBase } from './components/Vector/Vector.base.svelte';
+export type {
+ VectorBaseLayerComponents,
+ VectorBaseProps,
+} from './components/Vector/Vector.base.svelte';
+export { default as ViolinBase } from './components/Violin/Violin.base.svelte';
+export type {
+ ViolinBaseLayerComponents,
+ ViolinBaseProps,
+} from './components/Violin/Violin.base.svelte';
+export { default as VoronoiBase } from './components/Voronoi/Voronoi.base.svelte';
+export type {
+ VoronoiBaseLayerComponents,
+ VoronoiBaseProps,
+} from './components/Voronoi/Voronoi.base.svelte';
+export { default as ArcChartBase } from './components/charts/ArcChart/ArcChart.base.svelte';
+export type {
+ ArcChartBaseLayerComponents,
+ ArcChartBaseProps,
+} from './components/charts/ArcChart/ArcChart.base.svelte';
+export { default as AreaChartBase } from './components/charts/AreaChart/AreaChart.base.svelte';
+export type {
+ AreaChartBaseLayerComponents,
+ AreaChartBaseProps,
+} from './components/charts/AreaChart/AreaChart.base.svelte';
+export { default as BarChartBase } from './components/charts/BarChart/BarChart.base.svelte';
+export type {
+ BarChartBaseLayerComponents,
+ BarChartBaseProps,
+} from './components/charts/BarChart/BarChart.base.svelte';
+export { default as LineChartBase } from './components/charts/LineChart/LineChart.base.svelte';
+export type {
+ LineChartBaseLayerComponents,
+ LineChartBaseProps,
+} from './components/charts/LineChart/LineChart.base.svelte';
+export { default as PieChartBase } from './components/charts/PieChart/PieChart.base.svelte';
+export type {
+ PieChartBaseLayerComponents,
+ PieChartBaseProps,
+} from './components/charts/PieChart/PieChart.base.svelte';
+export { default as ScatterChartBase } from './components/charts/ScatterChart/ScatterChart.base.svelte';
+export type {
+ ScatterChartBaseLayerComponents,
+ ScatterChartBaseProps,
+} from './components/charts/ScatterChart/ScatterChart.base.svelte';
+export { default as GeoCircleBase } from './components/geo/GeoCircle/GeoCircle.base.svelte';
+export type {
+ GeoCircleBaseLayerComponents,
+ GeoCircleBaseProps,
+} from './components/geo/GeoCircle/GeoCircle.base.svelte';
+export { default as GeoClipPathBase } from './components/geo/GeoClipPath/GeoClipPath.base.svelte';
+export type {
+ GeoClipPathBaseLayerComponents,
+ GeoClipPathBaseProps,
+} from './components/geo/GeoClipPath/GeoClipPath.base.svelte';
+export { default as GeoEdgeFadeBase } from './components/geo/GeoEdgeFade/GeoEdgeFade.base.svelte';
+export type {
+ GeoEdgeFadeBaseLayerComponents,
+ GeoEdgeFadeBaseProps,
+} from './components/geo/GeoEdgeFade/GeoEdgeFade.base.svelte';
+export { default as GeoPathBase } from './components/geo/GeoPath/GeoPath.base.svelte';
+export type {
+ GeoPathBaseLayerComponents,
+ GeoPathBaseProps,
+} from './components/geo/GeoPath/GeoPath.base.svelte';
+export { default as GeoPointBase } from './components/geo/GeoPoint/GeoPoint.base.svelte';
+export type {
+ GeoPointBaseLayerComponents,
+ GeoPointBaseProps,
+} from './components/geo/GeoPoint/GeoPoint.base.svelte';
+export { default as GeoSplineBase } from './components/geo/GeoSpline/GeoSpline.base.svelte';
+export type {
+ GeoSplineBaseLayerComponents,
+ GeoSplineBaseProps,
+} from './components/geo/GeoSpline/GeoSpline.base.svelte';
+export { default as GeoTileBase } from './components/geo/GeoTile/GeoTile.base.svelte';
+export type {
+ GeoTileBaseLayerComponents,
+ GeoTileBaseProps,
+} from './components/geo/GeoTile/GeoTile.base.svelte';
+export { default as GraticuleBase } from './components/geo/Graticule/Graticule.base.svelte';
+export type {
+ GraticuleBaseLayerComponents,
+ GraticuleBaseProps,
+} from './components/geo/Graticule/Graticule.base.svelte';
+export { default as TileImageBase } from './components/geo/TileImage/TileImage.base.svelte';
+export type {
+ TileImageBaseLayerComponents,
+ TileImageBaseProps,
+} from './components/geo/TileImage/TileImage.base.svelte';
+export { default as RibbonBase } from './components/graph/Ribbon/Ribbon.base.svelte';
+export type {
+ RibbonBaseLayerComponents,
+ RibbonBaseProps,
+} from './components/graph/Ribbon/Ribbon.base.svelte';
+
+// A `Group`'s placement (pixel or data mode, `center`, motion, a series' visibility), for a
+// layer's own `Group`
+export { GroupState } from './components/Group/Group.shared.svelte.js';
+export { PointsState, type Point } from './components/Points/Points.shared.svelte.js';
+export { ArcState } from './components/Arc/Arc.shared.svelte.js';
+// A `Waffle`'s layout (each row's outline, cell size, and color), for a layer's own `Waffle`
+export { WaffleState, type WaffleItem } from './components/Waffle/Waffle.shared.svelte.js';
+// Where an `Image` or `Ellipse` is placed (pixel or data mode, motion), for a layer's own
+export { ImageState } from './components/Image/Image.shared.svelte.js';
+export { EllipseState } from './components/Ellipse/Ellipse.shared.svelte.js';
+// `GeoBin`'s cells over the sphere, for ` `
+export { sphereBinning } from './components/geo/GeoBin/GeoBin.sphere.js';
+export { default as FacetAxisBase } from './components/FacetAxis.base.svelte';
+export type { FacetAxisBaseProps } from './components/FacetAxis.base.svelte';
+export { default as FacetPanelBase } from './components/FacetPanel.base.svelte';
+export type { FacetPanelBaseProps } from './components/FacetPanel.base.svelte';
+// A `Pattern`'s lines, circles, and rects, as its tile draws them
+export { buildPatternShapes } from './components/Pattern/Pattern.shared.svelte.js';
+
+// The rows a mark draws: its own `data`, else its series' or the chart's, narrowed to the facet
+// panel it's drawn in
+export { getFacetPanel, getMarkData } from './contexts/facet.js';
+
+// What a data-mode mark tells the chart (its data and channels), so the chart's domains include it
+export { circleMarkInfo } from './components/Circle/Circle.shared.svelte.js';
+export { lineMarkInfo } from './components/Line/Line.shared.svelte.js';
+export { polygonMarkInfo } from './components/Polygon/Polygon.shared.svelte.js';
+export { rectMarkInfo } from './components/Rect/Rect.shared.svelte.js';
+export { textMarkInfo } from './components/Text/Text.shared.svelte.js';
diff --git a/packages/layerchart/src/lib/components/Calendar/Calendar.base.svelte b/packages/layerchart/src/lib/components/Calendar/Calendar.base.svelte
index 2e49f33ece..91b2f6541b 100644
--- a/packages/layerchart/src/lib/components/Calendar/Calendar.base.svelte
+++ b/packages/layerchart/src/lib/components/Calendar/Calendar.base.svelte
@@ -5,6 +5,8 @@
export type CalendarBaseLayerComponents = {
Rect: Component;
Text: Component;
+ /** Outlines each month for `monthPath` (LayerChart's `MonthPath` by default) */
+ MonthPath?: Component;
};
export type CalendarBaseProps = CalendarPropsWithoutHTML & CalendarBaseLayerComponents;
@@ -15,8 +17,8 @@
import { index } from 'd3-array';
import { endOfInterval, format } from '@layerstack/utils';
- // MonthPath isn't split — only used here when `monthPath` is set.
- import MonthPath from '../MonthPath.svelte';
+ // MonthPath isn't split — only used here when `monthPath` is set (unless a layer brings its own).
+ import CoreMonthPath from '../MonthPath.svelte';
import {} from '$lib/utils/common.js';
import { getChartContext } from '$lib/contexts/chart.js';
import { getMarkData } from '$lib/contexts/facet.js';
@@ -26,6 +28,7 @@
let {
Rect,
Text,
+ MonthPath = CoreMonthPath,
end,
start,
cellSize: cellSizeProp,
diff --git a/packages/layerchart/src/lib/components/ChartChildren/ChartChildren.base.svelte b/packages/layerchart/src/lib/components/ChartChildren/ChartChildren.base.svelte
index 0eb9b92bb0..e05da9251e 100644
--- a/packages/layerchart/src/lib/components/ChartChildren/ChartChildren.base.svelte
+++ b/packages/layerchart/src/lib/components/ChartChildren/ChartChildren.base.svelte
@@ -18,6 +18,14 @@
Rule: Component;
Highlight: Component;
ChartClipPath: Component;
+ /** The `points` drawn per series; LayerChart's own (loaded when first used) without it */
+ Points?: Component;
+ /** The `labels` drawn per series; LayerChart's own (loaded when first used) without it */
+ Labels?: Component;
+ /** The `annotations` drawn; LayerChart's own (loaded when first used) without it */
+ ChartAnnotations?: Component;
+ /** The facet grid's headers; LayerChart's own without it */
+ FacetAxis?: Component;
};
export type ChartChildrenBaseProps<
@@ -34,7 +42,7 @@
import { getChartContext } from '$lib/contexts/chart.js';
import { getSettings } from '$lib/contexts/settings.js';
import type { Facet } from '$lib/states/facet.svelte.js';
- import FacetAxis from '../FacetAxis.svelte';
+ import FacetAxisCore from '../FacetAxis.svelte';
import { asAny } from '$lib/utils/types.js';
import { getObjectOrNull } from '$lib/utils/common.js';
@@ -48,6 +56,10 @@
Rule,
Highlight,
ChartClipPath,
+ Points: PointsProp,
+ Labels: LabelsProp,
+ ChartAnnotations: ChartAnnotationsProp,
+ FacetAxis = FacetAxisCore,
props = {},
children: childrenProp,
belowContext,
@@ -69,6 +81,8 @@
let snippetProps = $derived({ context });
let layer = $derived(settings.layer);
+ // `Layer` draws `webgl` as `canvas` (`@layerchart/webgl`'s draws it with WebGL)
+ let layerTypeProps = $derived(layer === 'canvas' || layer === 'webgl' ? props.canvas : props.svg);
{#if childrenProp}
@@ -76,12 +90,7 @@
{:else}
{@render belowContext?.(snippetProps)}
-
+
+{#if ctx.facet.enabled && axis !== false && isFirstPanel}
+ {#if ctx.facet.xScale && ctx.facet.xDomain.length > 1}
+
+ {/if}
+
+ {#if ctx.facet.yScale && ctx.facet.yDomain.length > 1}
+
+
+
+
+ {/if}
+{/if}
diff --git a/packages/layerchart/src/lib/components/FacetAxis.svelte b/packages/layerchart/src/lib/components/FacetAxis.svelte
index 785384848f..2a0878c015 100644
--- a/packages/layerchart/src/lib/components/FacetAxis.svelte
+++ b/packages/layerchart/src/lib/components/FacetAxis.svelte
@@ -1,63 +1,8 @@
-
-{#if ctx.facet.enabled && axis !== false && isFirstPanel}
- {#if ctx.facet.xScale && ctx.facet.xDomain.length > 1}
-
- {/if}
-
- {#if ctx.facet.yScale && ctx.facet.yDomain.length > 1}
-
-
-
-
- {/if}
-{/if}
+
+
diff --git a/packages/layerchart/src/lib/components/FacetPanel.base.svelte b/packages/layerchart/src/lib/components/FacetPanel.base.svelte
new file mode 100644
index 0000000000..8c001f4b04
--- /dev/null
+++ b/packages/layerchart/src/lib/components/FacetPanel.base.svelte
@@ -0,0 +1,26 @@
+
+
+
+
+
+ {@render children?.({ facet })}
+
diff --git a/packages/layerchart/src/lib/components/FacetPanel.svelte b/packages/layerchart/src/lib/components/FacetPanel.svelte
index 13a0c571ea..80ff70aa81 100644
--- a/packages/layerchart/src/lib/components/FacetPanel.svelte
+++ b/packages/layerchart/src/lib/components/FacetPanel.svelte
@@ -9,17 +9,10 @@
-
- {@render children?.({ facet })}
-
+
diff --git a/packages/layerchart/src/lib/components/Hull/Hull.base.svelte b/packages/layerchart/src/lib/components/Hull/Hull.base.svelte
index ee170c69c4..2f59bdb2b1 100644
--- a/packages/layerchart/src/lib/components/Hull/Hull.base.svelte
+++ b/packages/layerchart/src/lib/components/Hull/Hull.base.svelte
@@ -5,6 +5,8 @@
export type HullBaseLayerComponents = {
Group: Component;
Spline: Component;
+ /** Its outline on a map (by default LayerChart's own, drawn in the chart's layer) */
+ GeoPath?: Component;
};
export type HullBaseProps = HullProps & HullBaseLayerComponents;
@@ -19,7 +21,7 @@
import { clsx } from 'clsx';
// GeoPath agnostic; only loaded when used inside a geo chart.
- import GeoPath from '../geo/GeoPath/GeoPath.svelte';
+ import CoreGeoPath from '../geo/GeoPath/GeoPath.svelte';
import { getChartContext } from '$lib/contexts/chart.js';
import { getFacetPanel } from '$lib/contexts/facet.js';
import { getGeoContext } from '$lib/contexts/geo.js';
@@ -34,6 +36,7 @@
let {
Group,
Spline,
+ GeoPath = CoreGeoPath,
data,
curve = curveLinearClosed,
classes = {},
diff --git a/packages/layerchart/src/lib/components/geo/GeoPoint/GeoPoint.base.svelte b/packages/layerchart/src/lib/components/geo/GeoPoint/GeoPoint.base.svelte
index f7a6ea03ca..5d44ca2a1b 100644
--- a/packages/layerchart/src/lib/components/geo/GeoPoint/GeoPoint.base.svelte
+++ b/packages/layerchart/src/lib/components/geo/GeoPoint/GeoPoint.base.svelte
@@ -65,9 +65,8 @@
{...extractLayerProps(restProps, 'lc-geo-point')}
/>
{/if}
-{/if}
-
-{#if layerCtx === 'canvas'}
+{:else}
+
{#if children}
{@render children({ x, y })}
{:else}
diff --git a/packages/layerchart/src/lib/components/graph/Chord.svelte b/packages/layerchart/src/lib/components/graph/Chord.svelte
index 3ee2c0ae15..ac2da53e6f 100644
--- a/packages/layerchart/src/lib/components/graph/Chord.svelte
+++ b/packages/layerchart/src/lib/components/graph/Chord.svelte
@@ -1,6 +1,6 @@
{#if layer === 'canvas'}
diff --git a/packages/layerchart/src/lib/components/layers/Layer.webgl.svelte.test.ts b/packages/layerchart/src/lib/components/layers/Layer.webgl.svelte.test.ts
new file mode 100644
index 0000000000..158df893c8
--- /dev/null
+++ b/packages/layerchart/src/lib/components/layers/Layer.webgl.svelte.test.ts
@@ -0,0 +1,26 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+
+import WebGLSetting from './__fixtures__/WebGLSetting.svelte';
+
+describe('Layer with `settings.layer="webgl"`', () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ afterEach(() => warn.mockClear());
+
+ it('draws a `` with no `type` as `canvas`, and warns once', async () => {
+ const { container } = render(WebGLSetting, { mode: 'children' });
+ await expect.poll(() => container.querySelector('canvas')).not.toBeNull();
+ expect(container.querySelector('svg')).toBeNull();
+
+ render(WebGLSetting, { mode: 'children' });
+ const fallbackWarnings = () =>
+ warn.mock.calls.filter(([message]) => String(message).includes('draws `webgl` as `canvas`'));
+ await expect.poll(() => fallbackWarnings().length).toBe(1);
+ });
+
+ it('draws a chart from its props as `canvas`', async () => {
+ const { container } = render(WebGLSetting, { mode: 'props' });
+ await expect.poll(() => container.querySelector('canvas')).not.toBeNull();
+ expect(container.querySelector('svg circle')).toBeNull();
+ });
+});
diff --git a/packages/layerchart/src/lib/components/layers/__fixtures__/WebGLSetting.svelte b/packages/layerchart/src/lib/components/layers/__fixtures__/WebGLSetting.svelte
new file mode 100644
index 0000000000..8f24c52972
--- /dev/null
+++ b/packages/layerchart/src/lib/components/layers/__fixtures__/WebGLSetting.svelte
@@ -0,0 +1,28 @@
+
+
+
+ {#if mode === 'children'}
+
+
+
+
+
+ {:else}
+
+ {/if}
+
diff --git a/packages/layerchart/src/lib/contexts/layer.ts b/packages/layerchart/src/lib/contexts/layer.ts
index fe127e610d..84b47f9ec2 100644
--- a/packages/layerchart/src/lib/contexts/layer.ts
+++ b/packages/layerchart/src/lib/contexts/layer.ts
@@ -2,10 +2,14 @@ import { createContext } from 'svelte';
export type LayerContext = 'svg' | 'canvas' | 'html';
-const [_getLayer, _setLayer] = createContext();
+const [_getLayer, _setLayer, _hasLayer] = createContext();
-export function getLayerContext(): LayerContext {
- return _getLayer();
+/**
+ * The layer marks here draw in, or `undefined` outside `Svg`, `Canvas`, and `Html` (ex. in a
+ * layer of another package's, where a mark of LayerChart's then draws nothing rather than throw)
+ */
+export function getLayerContext(): LayerContext | undefined {
+ return _hasLayer() ? _getLayer() : undefined;
}
export function setLayerContext(context: LayerContext): LayerContext {
diff --git a/packages/layerchart/src/lib/states/settings.svelte.ts b/packages/layerchart/src/lib/states/settings.svelte.ts
index 490c99e4ad..d08660a497 100644
--- a/packages/layerchart/src/lib/states/settings.svelte.ts
+++ b/packages/layerchart/src/lib/states/settings.svelte.ts
@@ -1,8 +1,14 @@
import type { LayerContext } from '$lib/contexts/layer.js';
import type { ChartViewProp } from '$lib/views/view.js';
+/**
+ * The layer a `Layer` with no `type` draws in. `webgl` is drawn by `@layerchart/webgl`'s
+ * `Layer`; LayerChart's draws it as `svg`.
+ */
+export type SettingsLayer = LayerContext | 'webgl';
+
export type SettingsOptions = {
- layer?: LayerContext;
+ layer?: SettingsLayer;
debug?: boolean;
/** The `view` of every chart that doesn't set its own (ex. `isometric`) */
view?: ChartViewProp | null;
@@ -10,7 +16,7 @@ export type SettingsOptions = {
/** Global settings context for charts */
export class Settings {
- layer: LayerContext;
+ layer: SettingsLayer;
debug: boolean;
view: ChartViewProp | null;
diff --git a/packages/layerchart/src/lib/utils/dataProp.test.ts b/packages/layerchart/src/lib/utils/dataProp.test.ts
index 812f264604..0ac34fea6e 100644
--- a/packages/layerchart/src/lib/utils/dataProp.test.ts
+++ b/packages/layerchart/src/lib/utils/dataProp.test.ts
@@ -110,6 +110,11 @@ describe('resolveDataProp', () => {
});
describe('resolveColorProp', () => {
+ it('passes a paint a Canvas layer resolved (a CanvasGradient or CanvasPattern) through', () => {
+ const gradient = { addColorStop() {} };
+ expect(resolveColorProp(gradient as any, { value: 1 }, null)).toBe(gradient);
+ });
+
const data = { category: 'A', value: 42, color: '#ff0000' };
const mockCScale = vi.fn((v: any) => (v === 'A' ? 'steelblue' : v === 'B' ? 'coral' : 'gray'));
diff --git a/packages/layerchart/src/lib/utils/dataProp.ts b/packages/layerchart/src/lib/utils/dataProp.ts
index 3adf4c518e..3aba8dd353 100644
--- a/packages/layerchart/src/lib/utils/dataProp.ts
+++ b/packages/layerchart/src/lib/utils/dataProp.ts
@@ -248,6 +248,10 @@ export function resolveColorProp(
return value;
}
+ // A paint a Canvas layer resolved itself (a `LinearGradient`'s `CanvasGradient`, a `Pattern`'s
+ // `CanvasPattern`), passed to the canvas as it is
+ if (typeof value === 'object') return value as unknown as string;
+
return undefined;
}
diff --git a/packages/webgl/package.json b/packages/webgl/package.json
index 07253bb7c1..256de53154 100644
--- a/packages/webgl/package.json
+++ b/packages/webgl/package.json
@@ -62,6 +62,11 @@
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js",
"default": "./dist/index.js"
+ },
+ "./webgl": {
+ "types": "./dist/webgl.d.ts",
+ "svelte": "./dist/webgl.js",
+ "default": "./dist/webgl.js"
}
},
"files": [
diff --git a/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.shared.svelte.ts b/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.shared.svelte.ts
new file mode 100644
index 0000000000..d705b6650c
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.shared.svelte.ts
@@ -0,0 +1 @@
+export type { AnnotationLineProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.svelte b/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.svelte
new file mode 100644
index 0000000000..c60903c672
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.webgl.svelte b/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.webgl.svelte
new file mode 100644
index 0000000000..3ce8c7314b
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationLine/AnnotationLine.webgl.svelte
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.shared.svelte.ts b/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.shared.svelte.ts
new file mode 100644
index 0000000000..78aca27b69
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.shared.svelte.ts
@@ -0,0 +1 @@
+export type { AnnotationPointProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.svelte b/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.svelte
new file mode 100644
index 0000000000..5f88dc13c5
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.webgl.svelte b/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.webgl.svelte
new file mode 100644
index 0000000000..4c8407ec5b
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationPoint/AnnotationPoint.webgl.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/AnnotationRange/AnnotationRange.svelte b/packages/webgl/src/lib/components/AnnotationRange/AnnotationRange.svelte
new file mode 100644
index 0000000000..e641bb8066
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationRange/AnnotationRange.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/AnnotationRange/AnnotationRange.webgl.svelte b/packages/webgl/src/lib/components/AnnotationRange/AnnotationRange.webgl.svelte
new file mode 100644
index 0000000000..d90299bf07
--- /dev/null
+++ b/packages/webgl/src/lib/components/AnnotationRange/AnnotationRange.webgl.svelte
@@ -0,0 +1,13 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Arc/Arc.shared.svelte.ts b/packages/webgl/src/lib/components/Arc/Arc.shared.svelte.ts
new file mode 100644
index 0000000000..4c00aca85d
--- /dev/null
+++ b/packages/webgl/src/lib/components/Arc/Arc.shared.svelte.ts
@@ -0,0 +1,125 @@
+import type { ArcProps as CoreArcProps, ColorProp, DataProp } from 'layerchart';
+import type { MotionOptions } from 'layerchart/utils/motion.svelte';
+
+/** How the track behind an arc is drawn */
+export type ArcTrackProps = {
+ /** CSS classes to style it by, as core marks take them (ex. `fill-red-500/10`) */
+ class?: string;
+ /** @default 'color-mix(in oklab, var(--color-surface-content) 10%, transparent)' */
+ fill?: string;
+ /** The outline's CSS color. No outline without one. */
+ stroke?: string;
+ /** @default 1 */
+ opacity?: number;
+ /** The fill's opacity (0 to 1). @default 1 */
+ fillOpacity?: number;
+ /** The outline's opacity (0 to 1). @default 1 */
+ strokeOpacity?: number;
+};
+
+/**
+ * The core `Arc`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`x`, `y`, `class`)
+ */
+export type ArcProps = {
+ /**
+ * On an `isometric` chart, stand the arc up `z` pixels, or between `[start, end]`, like a
+ * `Path` (or a key / function of `data` through the chart's `z` scale). Flat on the floor
+ * without one.
+ */
+ z?: DataProp | [start: number, end: number];
+ /** The value the arc runs to, through `domain` into `range` (as a gauge) */
+ value?: number;
+ /** The value to ease from with `motion`. @default 0 */
+ initialValue?: number;
+ /** Domain [min,max] of `value`. @default [0, 100] */
+ domain?: [number, number];
+ /** Range [min,max] in degrees. See also startAngle/endAngle. @default [0, 360] */
+ range?: [number, number];
+ /**
+ * Start angle in radians, clockwise from the top of the plot (its far edge before the view
+ * turns)
+ */
+ startAngle?: number;
+ /** End angle in radians */
+ endAngle?: number;
+ /**
+ * Define innerRadius. Defaults to yRange min
+ * • value >= 1: discrete value
+ * • value < 1: percent of `outerRadius`
+ * • value < 0: offset of `outerRadius`
+ */
+ innerRadius?: number;
+ /**
+ * Define outerRadius. Defaults to smallest width (xRange) or height (yRange) dimension (/2)
+ */
+ outerRadius?: number;
+ /** @default 0 */
+ cornerRadius?: number;
+ /** @default 0 */
+ padAngle?: number;
+ trackStartAngle?: number;
+ trackEndAngle?: number;
+ trackInnerRadius?: number;
+ trackOuterRadius?: number;
+ /** @default cornerRadius */
+ trackCornerRadius?: number;
+ /** @default padAngle */
+ trackPadAngle?: number;
+ /**
+ * Pixels to move it out from the center, along its middle angle (ex. to pull a slice out)
+ *
+ * @default 0
+ */
+ offset?: number;
+ /**
+ * Show the tooltip for `data` when the pointer is over it (with the chart's
+ * `tooltipContext`). **Must set `data` prop as well**
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+ /** Data to set when showing tooltip, and its `fill` / `stroke` read */
+ data?: any;
+ /**
+ * Draw the whole range behind the arc (as a gauge's track): `true` for the default look, or
+ * how to draw it
+ */
+ track?: boolean | ArcTrackProps;
+ /**
+ * Drawn with the arc, given what the core `Arc` gives its children (ex. `getArcTextProps` to
+ * place a `Text` at its centroid)
+ */
+ children?: CoreArcProps['children'];
+ /** Ease `value` changes */
+ motion?: MotionOptions;
+ /**
+ * Fill color: a CSS color, or a key / function of `data` run through the chart's color scale.
+ *
+ * @default 'var(--color-primary)'
+ */
+ fill?: ColorProp;
+ /** Fill opacity (0-1) @default 1 */
+ fillOpacity?: number;
+ /** Stroke color: a CSS color, or a key / function of `data` run through the color scale */
+ stroke?: ColorProp;
+ /** Stroke width in pixels @default 1 */
+ strokeWidth?: number;
+ /** Stroke opacity (0-1) @default 1 */
+ strokeOpacity?: number;
+ /** Overall opacity (0-1) @default 1 */
+ opacity?: number;
+
+ /**
+ * The center across, in pixels. Defaults to the plot's center, or inside a `Group` (or a
+ * centered layer) to its origin, as the core `Arc`.
+ */
+ x?: number;
+ /** The center down, in pixels. Defaults as `x`. */
+ y?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+};
diff --git a/packages/webgl/src/lib/components/Arc/Arc.svelte b/packages/webgl/src/lib/components/Arc/Arc.svelte
index aa49eb055d..601fc1405d 100644
--- a/packages/webgl/src/lib/components/Arc/Arc.svelte
+++ b/packages/webgl/src/lib/components/Arc/Arc.svelte
@@ -1,283 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Arc/Arc.webgl.svelte b/packages/webgl/src/lib/components/Arc/Arc.webgl.svelte
new file mode 100644
index 0000000000..cd0438fb40
--- /dev/null
+++ b/packages/webgl/src/lib/components/Arc/Arc.webgl.svelte
@@ -0,0 +1,256 @@
+
+
+
+
+{#if children && state}
+ {@render children({
+ centroid: state.trackArcCentroid,
+ boundingBox: state.boundingBox,
+ value: state.motionEndAngleValue,
+ startAngle: state.startAngle,
+ endAngle: state.arcEndAngle,
+ innerRadius: state.innerRadius,
+ outerRadius: state.outerRadius,
+ getTrackTextProps: state.getTrackTextProps,
+ getArcTextProps: state.getArcTextProps,
+ })}
+{/if}
diff --git a/packages/webgl/src/lib/components/ArcLabel/ArcLabel.svelte b/packages/webgl/src/lib/components/ArcLabel/ArcLabel.svelte
new file mode 100644
index 0000000000..1184014538
--- /dev/null
+++ b/packages/webgl/src/lib/components/ArcLabel/ArcLabel.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Area/Area.outline.svelte b/packages/webgl/src/lib/components/Area/Area.outline.svelte
new file mode 100644
index 0000000000..d653ba5e70
--- /dev/null
+++ b/packages/webgl/src/lib/components/Area/Area.outline.svelte
@@ -0,0 +1,112 @@
+
+
+
+
+
+{#if marker || markerStart || markerMid || markerEnd}
+
+ outlines()
+ .filter((outline) => outline.color)
+ .map((outline) => ({
+ points: outline.subpaths.flat(),
+ color: outline.color!,
+ // Each vertex between its ends (its pieces' too, as an SVG path's subpaths')
+ get mids() {
+ return outline.vertices().slice(1, -1);
+ },
+ }))}
+ {strokeWidth}
+ {opacity}
+ />
+{/if}
+
+{#if startContent || endContent}
+ {#each outlines() as outline, i (i)}
+ {@const ends = pathEnds(outline.subpaths, progress[i])}
+ {#if ends}
+
+ {/if}
+ {/each}
+{/if}
diff --git a/packages/webgl/src/lib/components/Area/Area.shared.svelte.ts b/packages/webgl/src/lib/components/Area/Area.shared.svelte.ts
new file mode 100644
index 0000000000..6085e82ae9
--- /dev/null
+++ b/packages/webgl/src/lib/components/Area/Area.shared.svelte.ts
@@ -0,0 +1,134 @@
+import type { Snippet } from 'svelte';
+import type { draw as drawTransition } from 'svelte/transition';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+import type { Accessor, ColorProp, DataProp } from 'layerchart';
+import type { CurveFactory } from 'd3-shape';
+import type { MarkerOptions } from '../Line/markers.js';
+
+/**
+ * The core `Area`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`y`, `z0`, `tooltip`)
+ */
+export type AreaProps = {
+ /** Override data instead of using context */
+ data?: any[];
+ /**
+ * Stand the area up as a curtain off the floor at each row's `y`, rising to this height: a
+ * key or function of the row (through the chart's `z` scale), or a number of pixels. Defaults
+ * to the chart's `z`; without one (or with `y0` / `y1`), the area lies on the floor, between
+ * `y0` and `y1`, as the core `Area` fills the plot.
+ */
+ z?: DataProp;
+ /**
+ * Pass ` ` explicitly instead of calculating from data / context: SVG path data
+ * in the plot's pixels, filled on the floor as the core `Path` draws it
+ */
+ pathData?: string | null;
+ /** Override the chart's `x` accessor */
+ x?: Accessor;
+ /**
+ * The area's base down the plot, as the core `Area`: an accessor of the row. Defaults to
+ * a stacked row's base, else the bottom of the plot.
+ */
+ y0?: Accessor;
+ /** The area's top down the plot, likewise. Defaults to a stacked row's top, else `y`. */
+ y1?: Accessor;
+ /**
+ * Draw one area per distinct value, in data order. Defaults to the chart's `g`, else the
+ * categorical data key `fill` / `stroke` names, else the chart's `c` (as `Spline`).
+ */
+ g?: Accessor;
+ /** Series key to use for accessor. */
+ seriesKey?: string;
+ /**
+ * Tween each area to where it's asked to be, as the core `Area` (ex. `'tween'`, or `{ type:
+ * 'tween', duration: 300 }`), a new one up from the baseline. A spring leaves it, as core's.
+ */
+ motion?: MotionProp;
+ /** The d3 curve the area's edges take through its rows (ex. `curveMonotoneX`) */
+ curve?: CurveFactory;
+ /** Whether a row is drawn: the area breaks at rows it isn't, as the core `Area` does */
+ defined?: (d: any, index: number, data: any[]) => boolean;
+ /**
+ * Draw a line along the top: in the fill's color, or as the core `Area`'s `line` takes it, with
+ * its own `stroke` (a CSS color, or a key / function of the area's first row run through the
+ * color scale), `strokeWidth`, and `class` (ex. `{ class: 'stroke-2 stroke-primary' }`).
+ *
+ * @default false
+ */
+ line?: boolean | { stroke?: ColorProp; strokeWidth?: number; class?: string };
+ /**
+ * Fill color, the name of a data property (resolved via the chart's `c` scale), or a function
+ * (read from each area's first row). Defaults to the chart's `c`, else its series' color,
+ * else `var(--color-primary)`.
+ */
+ fill?: ColorProp;
+ /**
+ * Stroke color, the name of a data property, or a function (read from each area's first row):
+ * an outline around each area, as the core `Area`'s path takes it. None without one (here or
+ * in `class`).
+ */
+ stroke?: ColorProp;
+ /**
+ * Opacity of the area and its outline (its line stays solid).
+ *
+ * @default 1
+ */
+ opacity?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+
+ /**
+ * Whether to animate the drawing of its outline over time (with a `stroke`), as the core
+ * `Area`'s path draws it. Pass either `true` or an object with transition options
+ * (`duration`, `delay`, `speed`, `easing`) to enable the transition.
+ *
+ * Works best with `tweened` disabled.
+ */
+ draw?: boolean | Parameters[1];
+ /**
+ * Marker to attach to both start and end points of its outline (with a `stroke`): drawn flat
+ * on the floor, turned along it, in its stroke color
+ */
+ marker?: MarkerOptions;
+ /** Marker to attach to the middle point of the outline (each vertex between its ends) */
+ markerMid?: MarkerOptions;
+ /** Marker to attach to the start point of the outline */
+ markerStart?: MarkerOptions;
+ /** Marker to attach to the end point of the outline (where it closes, at its start) */
+ markerEnd?: MarkerOptions;
+ /**
+ * Add additional content at the start of the area's path (its top's first point).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ startContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Add additional content at the end of the area's path (following it as `draw` draws it).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ endContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /** Opacity of its fill, with `opacity` @default 1 */
+ fillOpacity?: number;
+ /** Opacity of its outline (not its `line`), with `opacity` @default 1 */
+ strokeOpacity?: number;
+ /** The width of the line and the outline, in pixels. @default 1 */
+ strokeWidth?: number;
+
+ /** Override the chart's `y` accessor */
+ y?: Accessor;
+ /**
+ * A curtain's base, likewise.
+ *
+ * @default 0 (the floor)
+ */
+ z0?: DataProp;
+ /**
+ * Show the tooltip for the row the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/Area/Area.svelte b/packages/webgl/src/lib/components/Area/Area.svelte
index d386c94d93..e51a8fba9b 100644
--- a/packages/webgl/src/lib/components/Area/Area.svelte
+++ b/packages/webgl/src/lib/components/Area/Area.svelte
@@ -1,258 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Area/Area.webgl.svelte b/packages/webgl/src/lib/components/Area/Area.webgl.svelte
new file mode 100644
index 0000000000..19f41e874e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Area/Area.webgl.svelte
@@ -0,0 +1,512 @@
+
+
+
+
+
+{#if pathData}
+
+{:else if startContent || endContent || runs.some((run) => run.outline)}
+
+
+ areas.map((members): Outline => {
+ const pieces = members.map((i) => runs[i]);
+ return {
+ subpaths: pieces.map((run) => outlineOf(columnsNow(run))),
+ color: pieces[0].outline,
+ vertices: () => {
+ let offset = 0;
+ return pieces.flatMap((run) => {
+ const own = outlineVertices(run).map((k) => offset + k);
+ offset += 2 * run.columns.length + 1;
+ return own;
+ });
+ },
+ };
+ })}
+ lengths={() =>
+ areas.map((members) =>
+ members.reduce((sum, i) => sum + lengthOf(outlineOf(runs[i].columns)), 0)
+ )}
+ {draw}
+ {marker}
+ {markerMid}
+ {markerStart}
+ {markerEnd}
+ {startContent}
+ {endContent}
+ {strokeWidth}
+ opacity={opacity * strokeOpacity * seriesOpacity * (look?.opacity ?? 1)}
+ />
+{/if}
diff --git a/packages/webgl/src/lib/components/Axis/Axis.base.svelte b/packages/webgl/src/lib/components/Axis/Axis.base.svelte
new file mode 100644
index 0000000000..9f8a5e5082
--- /dev/null
+++ b/packages/webgl/src/lib/components/Axis/Axis.base.svelte
@@ -0,0 +1,824 @@
+
+
+
+
+
+{#if grid && along !== 'z'}
+
+{/if}
+
+{#if ruleMarkers}
+ {#await import('../Line/Line.markers.svelte') then { default: LineMarkers }}
+ ruleMarked} />
+ {/await}
+{/if}
+
+{#if placement !== 'back'}
+ {#each floorLabels as l (l.key)}
+
+ {/each}
+{/if}
+
+{#each snippetLabels as l, i (l.key)}
+ {#if isTitle(l)}
+ {#if typeof label === 'function'}{@render label({ props: textProps(l) })}{/if}
+ {:else}
+ {@render tickLabel?.({ props: textProps(l), index: i })}
+ {/if}
+{/each}
diff --git a/packages/webgl/src/lib/components/Axis/Axis.shared.svelte.ts b/packages/webgl/src/lib/components/Axis/Axis.shared.svelte.ts
new file mode 100644
index 0000000000..7fdfa2af44
--- /dev/null
+++ b/packages/webgl/src/lib/components/Axis/Axis.shared.svelte.ts
@@ -0,0 +1,238 @@
+import type { Snippet } from 'svelte';
+import type { autoTickFormat, DataProp, TicksConfig } from 'layerchart';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+import type { MarkerOptions } from '../Line/markers.js';
+
+/** How an axis draws its labels, as `Text` draws them */
+export type AxisLabelProps = {
+ /**
+ * Face the viewer, drawn over the scene upright and crisp, rather than on the plot box: the
+ * floor's labels (`bottom`, `left`) lie on it, as an `isometric` chart's do, and the height
+ * axis' (`back`) stand on the back wall beside its edge, turning with it.
+ *
+ * @default false
+ */
+ viewport?: boolean;
+ /** Class added to each `viewport` label, and the fill (and opacity) it sets, for the others */
+ class?: string;
+ /**
+ * Font size in pixels of the plot, for labels on the plot box. Defaults to read about as
+ * large as `viewport` labels as the view is fitted.
+ */
+ fontSize?: number;
+ /** Font weight, for labels on the plot box */
+ fontWeight?: number | string;
+ /** CSS color, for labels on the plot box */
+ fill?: string;
+ /** Degrees to turn tick labels on the plot box, as the core `Axis`' (ex. `315` up and across) */
+ rotate?: number;
+ /** Tick labels' horizontal anchor, as the core `Axis`' (ex. `'end'` with `rotate`) */
+ textAnchor?: 'start' | 'middle' | 'end';
+ /** Tick labels' vertical anchor, as the core `Axis`' */
+ verticalAnchor?: 'start' | 'middle' | 'end';
+ /**
+ * Pixels across from where it's placed, for labels on the plot box (in place of the core
+ * `Axis`' default offset from its tick, as there)
+ */
+ dx?: number;
+ /**
+ * Pixels down from where it's placed, for labels on the plot box (in place of the core `Axis`'
+ * default offset from its tick, as there)
+ */
+ dy?: number;
+};
+
+/** How an axis' rule or grid lines are drawn */
+export type AxisLineProps = {
+ /** CSS classes to style them by (their stroke, width, and opacity) */
+ class?: string;
+ stroke?: string;
+ /** Width in pixels, the same at any depth. @default 1 */
+ strokeWidth?: number;
+ opacity?: number;
+ /** Dashed-line pattern (grid lines): a dash length, `[dash, gap]`, or an SVG `stroke-dasharray` */
+ dashArray?: number | number[] | string;
+};
+
+/** How an axis' rule is drawn: as its other lines, with markers at its ends, as a `Rule`'s */
+export type AxisRuleProps = AxisLineProps & {
+ /** A marker at its start and end: a type (ex. `'arrow'`) or the core `Marker`'s props */
+ marker?: MarkerOptions;
+ /** A marker at its start (where the core `Rule` starts it: its left, or a side's bottom) */
+ markerStart?: MarkerOptions;
+ markerMid?: MarkerOptions;
+ /** A marker at its end (its right, or a side's top) */
+ markerEnd?: MarkerOptions;
+};
+
+/** What a `label` or `tickLabel` snippet is given to spread on a `Text` */
+export type AxisTextProps = {
+ x: number;
+ y: number;
+ z: number;
+ value: string;
+ textAnchor: 'start' | 'middle' | 'end';
+ verticalAnchor: 'start' | 'middle' | 'end';
+ dx: number;
+ dy: number;
+ rotate: number;
+ fontSize: number;
+ fontWeight: number | string;
+ /** Pixels from a line's top to its baseline, as the core `Axis`' labels */
+ capHeight: number;
+ /** Between lines, in multiples of `fontSize` */
+ lineHeight: number;
+ fill: string;
+ class?: string;
+ viewport?: boolean;
+};
+
+/**
+ * The core `Axis`' props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`tickLabelOffset`)
+ */
+export type AxisProps = {
+ /**
+ * Which axis: `bottom` labels `x` along the floor's front edge (`top` along its back), `left`
+ * labels `y` along its side (`right` along the other), and `back` labels `z` up a corner. Same
+ * as an `isometric` chart's. The edges turn to stay in front as the camera orbits. In a
+ * `radial` chart, `angle` labels `x` around its rim and `radius` labels `y` out from its center.
+ */
+ placement: 'bottom' | 'top' | 'left' | 'right' | 'back' | 'angle' | 'radius';
+ /**
+ * Draw in every panel of a faceted chart, rather than only on the grid's outer edge.
+ * @default false
+ */
+ facetAll?: boolean;
+ /**
+ * The label for the axis, drawn beyond the tick labels.
+ *
+ * Can either be a string or a snippet to render custom content. The snippet receives
+ * spreadable props to apply to a `Text`.
+ */
+ label?: string | Snippet<[{ props: AxisTextProps }]>;
+ /**
+ * Location of axis label along the axis
+ * @default 'middle'
+ */
+ labelPlacement?: 'start' | 'middle' | 'end';
+ /** Props applied to label Text */
+ labelProps?: AxisLabelProps;
+ /**
+ * Draw a rule line along the axis' edge of the plot box, and how
+ * @default false
+ */
+ rule?: boolean | AxisRuleProps;
+ /**
+ * Draw grid lines across the plot at its ticks, as the core `Axis` draws them. Pass props
+ * (class, stroke, strokeWidth, opacity, dashArray) to forward onto the grid lines.
+ * @default false
+ */
+ grid?: boolean | AxisLineProps;
+ /** Control the number of ticks: a count, values, or an interval */
+ ticks?: TicksConfig;
+ /**
+ * Width or height of each tick in pixels (enabling responsive count). `null` leaves the count
+ * to the scale.
+ *
+ * @default 50 in a 3D view (80 across a flat one)
+ */
+ tickSpacing?: number | null;
+ /**
+ * Drop ticks whose labels would overlap one already kept, measuring each label at the size
+ * it actually renders. Across a flat chart; a 3D view keeps every tick (its labels turn with
+ * the view, so what overlaps changes as it does).
+ *
+ * `tickSpacing` only picks a tick *count* — it cannot know how wide a formatted label turns
+ * out to be, so a long format (`'Wednesday'`, `'$1,234,567'`) still collides at any count
+ * that fits the axis. This measures instead.
+ *
+ * - `priority`: which ticks win when labels compete. `'end'` (default) keeps the last tick and
+ * walks backwards (the newest value on a time axis); `'start'` keeps the first; `'start-end'`
+ * anchors both ends of the axis and thins what is between them.
+ * - `padding`: minimum gap, in pixels, required between two kept labels.
+ *
+ * @default false
+ */
+ tickOcclusion?: boolean | { padding?: number; priority?: 'start' | 'end' | 'start-end' };
+ /**
+ * Whether to render tick labels on multiple lines for additional context
+ *
+ * @default false
+ */
+ tickMultiline?: boolean;
+ /**
+ * Length of the tick line
+ * @default 4
+ */
+ tickLength?: number;
+ /**
+ * Whether to render tick marks.
+ *
+ * @default true
+ */
+ tickMarks?: boolean;
+ /** Format tick labels */
+ format?: Parameters[0]['formatType'];
+ /** Props to apply to each tick label */
+ tickLabelProps?: AxisLabelProps;
+ /** A snippet to render your own custom tick label, given props to spread on a `Text` */
+ tickLabel?: Snippet<[{ props: AxisTextProps; index: number }]>;
+ /** Override scale for the axis */
+ scale?: any;
+ /**
+ * Domain for the axis, on a copy of `scale` (or the chart's scale for this placement) that keeps
+ * its range and type. Useful for a secondary axis, e.g. `domain={[0, 100]}` on the right.
+ */
+ domain?: any[];
+ /** Stroke color for axis rule, grid lines, and tick marks. */
+ stroke?: string;
+ /** Fill color for tick labels and axis label. */
+ fill?: string;
+ /**
+ * Classes for styling various parts of the axis (the stroke, width, and opacity they set on
+ * its lines, and the fill on its labels)
+ * @default {}
+ */
+ classes?: {
+ root?: string;
+ label?: string;
+ rule?: string;
+ tick?: string;
+ tickLabel?: string;
+ };
+ /** Ease each tick (its mark, label, and grid line) to where it moves, ex. `'tween'` */
+ motion?: MotionProp;
+ /**
+ * Translate x position of the axis, in pixels (or per row, through the `x` scale, as `Group`)
+ */
+ x?: DataProp;
+ /** Initial translate x (pixel mode only). @default x */
+ initialX?: number;
+ /**
+ * Translate y position of the axis, in pixels (or per row, through the `y` scale, as `Group`)
+ */
+ y?: DataProp;
+ /** Initial translate y (pixel mode only). @default y */
+ initialY?: number;
+ /** Data array to iterate over in data mode (an axis per row, as `Group`) */
+ data?: any[];
+ /** Key function for each row's axis in data mode. @default (d, i) => i */
+ key?: (d: any, index: number) => any;
+ /**
+ * Series key to follow, fading the axis while another series is highlighted and removing it
+ * while the series is hidden. Only applicable if `` uses `series`.
+ */
+ seriesKey?: string;
+ /** Center within chart. @default false */
+ center?: boolean | 'x' | 'y';
+ /** The opacity of the element. (0 to 1) */
+ opacity?: number;
+
+ /**
+ * Pixels between the plot box's edge and the tick labels, as the core `Axis` spaces them.
+ *
+ * @default tickLength beside the plot (`left` / `right`), tickLength + 2 above or below it
+ */
+ tickLabelOffset?: number;
+};
diff --git a/packages/webgl/src/lib/components/Axis/Axis.svelte b/packages/webgl/src/lib/components/Axis/Axis.svelte
index 57ad22c9b9..325438014d 100644
--- a/packages/webgl/src/lib/components/Axis/Axis.svelte
+++ b/packages/webgl/src/lib/components/Axis/Axis.svelte
@@ -1,350 +1,24 @@
-{#if placement !== 'back'}
- {#each floorLabels as l (l.key)}
-
- {/each}
+{#if inScene}
+
+{:else}
+
{/if}
diff --git a/packages/webgl/src/lib/components/Axis/Axis.webgl.svelte b/packages/webgl/src/lib/components/Axis/Axis.webgl.svelte
new file mode 100644
index 0000000000..717bbdf4cf
--- /dev/null
+++ b/packages/webgl/src/lib/components/Axis/Axis.webgl.svelte
@@ -0,0 +1,61 @@
+
+
+
+
+{#if !visible}
+
+{:else if grouped}
+
+
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Bar/Bar.shared.svelte.ts b/packages/webgl/src/lib/components/Bar/Bar.shared.svelte.ts
new file mode 100644
index 0000000000..7c7c3e2552
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bar/Bar.shared.svelte.ts
@@ -0,0 +1,132 @@
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+import type { Accessor, ColorProp, DataProp } from 'layerchart';
+import type { Insets } from 'layerchart/utils/rect.svelte';
+import type { MarkEvents } from '../../contexts/scene.svelte.js';
+import type { Rounded } from '../../utils/rounded.js';
+
+/**
+ * The core `Bar`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`z`, `class`, `size`). One row's bar, as `Bars` draws each, without registering it with
+ * the chart.
+ */
+export type BarProps = {
+ /** Data to render the bar from */
+ data: any;
+ /** Override `x` from context. @default ctx.x */
+ x?: Accessor;
+ /** Override `y` from context. @default ctx.y */
+ y?: Accessor;
+ /** Override `x1` from context. @default ctx.x1 */
+ x1?: Accessor;
+ /** Override `y1` from context. @default ctx.y1 */
+ y1?: Accessor;
+ /** Series key to use for accessor. */
+ seriesKey?: string;
+ /** Padding between stacked bars. */
+ stackPadding?: number;
+ /**
+ * Corner radius in pixels, rounding flat bars.
+ *
+ * @default 0
+ */
+ radius?: number;
+ /**
+ * Pixels to leave between a bar and the edges of its band: on every side, or per side (ex.
+ * `{ x: 4 }`). A 3D bar takes the same on every side (`all`).
+ */
+ insets?: number | Insets;
+ /** Where a new bar starts across `x` as it eases in with `motion`, in pixels */
+ initialX?: number;
+ /** Where a new bar starts down `y` as it eases in with `motion`, in pixels */
+ initialY?: number;
+ /** How tall (down `y`) a new bar starts as it eases in with `motion`, in pixels */
+ initialHeight?: number;
+ /** How wide a new bar starts as it eases in with `motion`, in pixels */
+ initialWidth?: number;
+ /** Fixed width in pixels. */
+ width?: number;
+ /** Fixed height in pixels (down `y`, its depth in a 3D view). */
+ height?: number;
+ /**
+ * Which corners to round. Takes an accessor as well as a value — which corner is the stack's
+ * edge depends on the row, not just on the series.
+ *
+ * @default 'all'
+ */
+ rounded?: Rounded | ((d: any) => Rounded);
+ /**
+ * Ease each bar to where it's asked to be: one config for all (ex. `'spring'`, `{ type:
+ * 'tween', duration: 300 }`), or one per prop (ex. `{ y: { type: 'tween', delay: 300 } }`, of
+ * `x`, `y`, `z`, `width`, `depth`, and `height`). A new bar grows from the baseline.
+ */
+ motion?: MotionProp<'x' | 'y' | 'z' | 'width' | 'depth' | 'height'>;
+ /**
+ * Setup pointer events to show tooltip for related data.
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+ /**
+ * The fill color: a CSS color, or a data key / function run through the chart's color scale.
+ * Defaults to the series', else the chart's `c`, else `var(--color-surface-content)`.
+ */
+ fill?: ColorProp;
+ /** The fill opacity (0 to 1). @default 1 */
+ fillOpacity?: number;
+ /**
+ * The stroke color, as the core isometric bars draw theirs: around each bar's top and up its
+ * corners. A CSS color, or a data key / function run through the chart's color scale. None
+ * without one (here or in `class`) or a `strokeWidth`, which outlines in black.
+ */
+ stroke?: ColorProp;
+ /** The stroke width in pixels, the same at any depth. @default 1 */
+ strokeWidth?: number;
+ /** The stroke opacity (0 to 1). @default 1 */
+ strokeOpacity?: number;
+ /** The opacity (0 to 1), or a bar's by its row (ex. fading other series). @default 1 */
+ opacity?: number | ((d: any) => number);
+ /** Click event handler, called with the bar's row (`{ data }`) */
+ onclick?: MarkEvents['onclick'];
+ /** Double click event handler, called with the bar's row (`{ data }`) */
+ ondblclick?: MarkEvents['ondblclick'];
+ /** Pointer enter event handler, called with the bar's row (`{ data }`) */
+ onpointerenter?: MarkEvents['onpointerenter'];
+ /** Pointer move event handler, called with the bar's row (`{ data }`) */
+ onpointermove?: MarkEvents['onpointermove'];
+ /** Pointer leave event handler, called with the bar's row (`{ data }`) */
+ onpointerleave?: MarkEvents['onpointerleave'];
+ /** Pointer over event handler, called with the bar's row (`{ data }`) */
+ onpointerover?: MarkEvents['onpointerover'];
+ /** Pointer out event handler, called with the bar's row (`{ data }`) */
+ onpointerout?: MarkEvents['onpointerout'];
+
+ /**
+ * The bar's height: a data key or function (through the chart's `z` scale), or a number of
+ * pixels. Defaults to the chart's `z`, stacked when the chart stacks along `z`. With neither,
+ * the bars are LayerChart's 2D ones, flat on the floor.
+ */
+ z?: DataProp;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+ /**
+ * A bar's width and depth in pixels along an axis without bands (and on a `globe`).
+ *
+ * @default 10
+ */
+ size?: number;
+};
+
+/** The pointer handlers a bar takes */
+export type BarEvents = Pick<
+ BarProps,
+ | 'onclick'
+ | 'ondblclick'
+ | 'onpointerenter'
+ | 'onpointermove'
+ | 'onpointerleave'
+ | 'onpointerover'
+ | 'onpointerout'
+>;
diff --git a/packages/webgl/src/lib/components/Bar/Bar.svelte b/packages/webgl/src/lib/components/Bar/Bar.svelte
new file mode 100644
index 0000000000..ebd921eb69
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bar/Bar.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Bar/Bar.webgl.svelte b/packages/webgl/src/lib/components/Bar/Bar.webgl.svelte
new file mode 100644
index 0000000000..9577aaf685
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bar/Bar.webgl.svelte
@@ -0,0 +1,11 @@
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Bars/Bar.radial.svelte b/packages/webgl/src/lib/components/Bars/Bar.radial.svelte
new file mode 100644
index 0000000000..50e391ccf1
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bars/Bar.radial.svelte
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Bars/Bars.base.svelte b/packages/webgl/src/lib/components/Bars/Bars.base.svelte
new file mode 100644
index 0000000000..3c15e2b691
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bars/Bars.base.svelte
@@ -0,0 +1,405 @@
+
+
+
+
+
+
+{#if roundedBars}
+ (outlined ? outlineOf(d) : null)}
+ {strokeWidth}
+ opacity={fillAlpha}
+ lineOpacity={strokeAlpha}
+ {tooltip}
+ {events}
+ />
+{/if}
diff --git a/packages/webgl/src/lib/components/Bars/Bars.radial.svelte b/packages/webgl/src/lib/components/Bars/Bars.radial.svelte
new file mode 100644
index 0000000000..fcb4daa650
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bars/Bars.radial.svelte
@@ -0,0 +1,13 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Bars/Bars.rounded.svelte b/packages/webgl/src/lib/components/Bars/Bars.rounded.svelte
new file mode 100644
index 0000000000..4cff1cddb8
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bars/Bars.rounded.svelte
@@ -0,0 +1,70 @@
+
+
diff --git a/packages/webgl/src/lib/components/Bars/Bars.shared.svelte.ts b/packages/webgl/src/lib/components/Bars/Bars.shared.svelte.ts
new file mode 100644
index 0000000000..b391319421
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bars/Bars.shared.svelte.ts
@@ -0,0 +1,21 @@
+import type { Snippet } from 'svelte';
+import type { BarEvents, BarProps } from '../Bar/Bar.shared.svelte.js';
+
+/**
+ * The core `Bars`' props (in its order, as it describes them), then a bar's (as `Bar` takes
+ * them, with a `WebGL` layer's own last)
+ */
+export type BarsProps = {
+ /** Override the data from the context. */
+ data?: any[];
+ /** Which bar each row is as rows change, for `motion`. @default (d, index) => index */
+ key?: (d: any, index: number) => unknown;
+ /** Event dispatched when an individual bar is clicked. */
+ onBarClick?: (e: MouseEvent, detail: { data: any }) => void;
+ /** Series key to use for accessor. */
+ seriesKey?: string;
+ /** Padding between stacked bars. */
+ stackPadding?: number;
+ /** Drawn in place of its bars (ex. a `Bar` per row, styled each its own way) */
+ children?: Snippet;
+} & Omit;
diff --git a/packages/webgl/src/lib/components/Bars/Bars.svelte b/packages/webgl/src/lib/components/Bars/Bars.svelte
index 7ecdad556b..53bfb27636 100644
--- a/packages/webgl/src/lib/components/Bars/Bars.svelte
+++ b/packages/webgl/src/lib/components/Bars/Bars.svelte
@@ -1,188 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Bars/Bars.webgl.svelte b/packages/webgl/src/lib/components/Bars/Bars.webgl.svelte
new file mode 100644
index 0000000000..dd514202d6
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bars/Bars.webgl.svelte
@@ -0,0 +1,33 @@
+
+
+
+
+{#if children}
+ {@render children()}
+{:else if ctx.radial}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Bin/Bin.grid.svelte b/packages/webgl/src/lib/components/Bin/Bin.grid.svelte
new file mode 100644
index 0000000000..4927ef1a6e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bin/Bin.grid.svelte
@@ -0,0 +1,122 @@
+
+
diff --git a/packages/webgl/src/lib/components/Bin/Bin.shared.svelte.ts b/packages/webgl/src/lib/components/Bin/Bin.shared.svelte.ts
new file mode 100644
index 0000000000..5ac32218e8
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bin/Bin.shared.svelte.ts
@@ -0,0 +1,118 @@
+import type { Snippet } from 'svelte';
+import type { Accessor, BinCell, BinShape, ColorProp, DataProp } from 'layerchart';
+
+/** How `Bin`'s `grid` is drawn: `true`, or its stroke, width, opacity, and classes */
+export type BinGridProps =
+ | boolean
+ | {
+ class?: string;
+ style?: string;
+ stroke?: string;
+ strokeWidth?: number;
+ strokeOpacity?: number;
+ opacity?: number;
+ };
+
+/**
+ * The core `Bin`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`gap`, `tooltip`)
+ */
+export type BinProps = {
+ /** Rows to bin. Falls back to the chart's data. */
+ data?: T[];
+ /** Horizontal position accessor, or longitude on a geo chart. Defaults to the chart's `x`. */
+ x?: Accessor;
+ /** Vertical position accessor, or latitude on a geo chart. Defaults to the chart's `y`. */
+ y?: Accessor;
+ /**
+ * How much each row counts toward its cell's `count`, ex. the people in a cell of gridded
+ * population data. Without it, each row counts once.
+ */
+ weight?: Accessor;
+ /**
+ * Shape of the cells tiling the plot (as projected, on a map).
+ *
+ * @default 'hexagon'
+ */
+ shape?: BinShape;
+ /**
+ * Width of a cell in pixels — the distance between neighboring hexagon centers, a square's side,
+ * or a triangle's base.
+ *
+ * @default 20
+ */
+ size?: number;
+ /**
+ * Outline every cell of the grid beneath the bins, clipped to the plot, to show how it is divided.
+ * Pass props (class, style, stroke, strokeWidth, strokeOpacity, opacity) to style its lines.
+ *
+ * @default false
+ */
+ grid?: BinGridProps;
+ /**
+ * Fill color of each cell.
+ * - `undefined`: the cell's `count`, through a color ramp
+ * - `string`: a cell property such as `'count'` through a color ramp, else a literal CSS color
+ * - `function(cell)`: any value derived from the cell, ex. `(cell) => mean(cell.data, (d) => d.price)`
+ *
+ * Numbers are colored by the chart's `cScale` when it is continuous (re-domained to the cells'
+ * extent unless `cDomain` is given), else a `YlGnBu` ramp. Categories use the chart's `cScale`.
+ */
+ fill?: ColorProp>;
+ /**
+ * Stroke color of each cell, resolved like `fill`: around each cell's top, and up its corners
+ * when it stands any height. None without one (here or in `class`).
+ */
+ stroke?: ColorProp>;
+ /** The fill opacity (0 to 1). @default 1 */
+ fillOpacity?: number;
+ /** The stroke opacity (0 to 1). @default 1 */
+ strokeOpacity?: number;
+ /** The stroke width in pixels, the same at any depth. @default 1 */
+ strokeWidth?: number;
+ /** The opacity (0 to 1). @default 1 */
+ opacity?: number;
+ /**
+ * Size each cell by a value rather than filling the grid, ex. `r="count"`.
+ * - `string` / `function(cell)`: area proportional to the value, the largest filling its cell
+ * - `number`: circumradius in pixels
+ */
+ r?: DataProp>;
+ /**
+ * Stand each cell up as a prism, ex. `z="count"`. Flat on the floor without one.
+ * - `string` / `function(cell)`: resolved through `zScale`
+ * - `number`: pixel height for every cell
+ */
+ z?: DataProp>;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+ /**
+ * Render the cells yourself (ex. as `Points` or `Text` labels, at each cell's `x` / `y`)
+ * instead of as prisms
+ */
+ children?: Snippet<[{ cells: BinCell[] }]>;
+ /** Called with the cell clicked */
+ onclick?: (e: MouseEvent, cell: BinCell) => void;
+ /** Called with the cell the pointer enters */
+ onpointerenter?: (e: PointerEvent, cell: BinCell) => void;
+ /** Called with the cell the pointer moves over */
+ onpointermove?: (e: PointerEvent, cell: BinCell) => void;
+ /** Called with the cell the pointer leaves */
+ onpointerleave?: (e: PointerEvent, cell: BinCell) => void;
+
+ /**
+ * Pixels between neighboring cells, so each stands apart.
+ *
+ * @default 0
+ */
+ gap?: number;
+ /**
+ * Show the tooltip for the cell the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/Bin/Bin.svelte b/packages/webgl/src/lib/components/Bin/Bin.svelte
index 1610930c65..5d372b0364 100644
--- a/packages/webgl/src/lib/components/Bin/Bin.svelte
+++ b/packages/webgl/src/lib/components/Bin/Bin.svelte
@@ -1,212 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Bin/Bin.webgl.svelte b/packages/webgl/src/lib/components/Bin/Bin.webgl.svelte
new file mode 100644
index 0000000000..a2b4c58f79
--- /dev/null
+++ b/packages/webgl/src/lib/components/Bin/Bin.webgl.svelte
@@ -0,0 +1,222 @@
+
+
+
+
+{#if grid}
+
+{/if}
+{#if children}
+ {@render children({ cells })}
+{/if}
diff --git a/packages/webgl/src/lib/components/BoxPlot/BoxPlot.shared.svelte.ts b/packages/webgl/src/lib/components/BoxPlot/BoxPlot.shared.svelte.ts
new file mode 100644
index 0000000000..57e82623ba
--- /dev/null
+++ b/packages/webgl/src/lib/components/BoxPlot/BoxPlot.shared.svelte.ts
@@ -0,0 +1 @@
+export type { BoxPlotProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/BoxPlot/BoxPlot.svelte b/packages/webgl/src/lib/components/BoxPlot/BoxPlot.svelte
new file mode 100644
index 0000000000..57af96be92
--- /dev/null
+++ b/packages/webgl/src/lib/components/BoxPlot/BoxPlot.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/BoxPlot/BoxPlot.webgl.svelte b/packages/webgl/src/lib/components/BoxPlot/BoxPlot.webgl.svelte
new file mode 100644
index 0000000000..357a2306d6
--- /dev/null
+++ b/packages/webgl/src/lib/components/BoxPlot/BoxPlot.webgl.svelte
@@ -0,0 +1,16 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Brush/Brush.parts.ts b/packages/webgl/src/lib/components/Brush/Brush.parts.ts
new file mode 100644
index 0000000000..a502c8894e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Brush/Brush.parts.ts
@@ -0,0 +1,34 @@
+import { getContext, setContext } from 'svelte';
+
+/** One drawn part of a brush (its region, selection, or a handle), and the drag it takes */
+export type BrushPart = {
+ readonly x: number;
+ readonly y: number;
+ readonly width: number;
+ readonly height: number;
+ readonly class: string | undefined;
+ readonly position: string | undefined;
+ readonly onpointerdown: ((e: PointerEvent, target?: Element) => void) | undefined;
+ readonly ondblclick: ((e: MouseEvent) => void) | undefined;
+};
+
+const KEY = Symbol('LayerChartWebGLBrushParts');
+
+/** The parts a brush draws, in the order they're drawn (the last on top) */
+export function setBrushParts(parts: BrushPart[]) {
+ setContext(KEY, parts);
+}
+
+export function getBrushParts(): BrushPart[] | undefined {
+ return getContext(KEY);
+}
+
+/** The cursor a part shows, as the core `Brush`'s styles set it */
+export function cursorOf(part: BrushPart) {
+ const classes = part.class ?? '';
+ if (classes.includes('lc-brush-handle')) {
+ return part.position === 'top' || part.position === 'bottom' ? 'ns-resize' : 'ew-resize';
+ }
+ if (classes.includes('lc-brush-selection')) return 'move';
+ return 'crosshair';
+}
diff --git a/packages/webgl/src/lib/components/Brush/Brush.rect.svelte b/packages/webgl/src/lib/components/Brush/Brush.rect.svelte
new file mode 100644
index 0000000000..db23517901
--- /dev/null
+++ b/packages/webgl/src/lib/components/Brush/Brush.rect.svelte
@@ -0,0 +1,62 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Brush/Brush.svelte b/packages/webgl/src/lib/components/Brush/Brush.svelte
new file mode 100644
index 0000000000..f41927dcad
--- /dev/null
+++ b/packages/webgl/src/lib/components/Brush/Brush.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Brush/Brush.webgl.svelte b/packages/webgl/src/lib/components/Brush/Brush.webgl.svelte
new file mode 100644
index 0000000000..074a42898b
--- /dev/null
+++ b/packages/webgl/src/lib/components/Brush/Brush.webgl.svelte
@@ -0,0 +1,62 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Calendar/Calendar.shared.svelte.ts b/packages/webgl/src/lib/components/Calendar/Calendar.shared.svelte.ts
new file mode 100644
index 0000000000..755081e5b6
--- /dev/null
+++ b/packages/webgl/src/lib/components/Calendar/Calendar.shared.svelte.ts
@@ -0,0 +1 @@
+export type { CalendarProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Calendar/Calendar.svelte b/packages/webgl/src/lib/components/Calendar/Calendar.svelte
new file mode 100644
index 0000000000..ed40df74eb
--- /dev/null
+++ b/packages/webgl/src/lib/components/Calendar/Calendar.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Calendar/Calendar.webgl.svelte b/packages/webgl/src/lib/components/Calendar/Calendar.webgl.svelte
new file mode 100644
index 0000000000..f302e35027
--- /dev/null
+++ b/packages/webgl/src/lib/components/Calendar/Calendar.webgl.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Calendar/MonthPath.webgl.svelte b/packages/webgl/src/lib/components/Calendar/MonthPath.webgl.svelte
new file mode 100644
index 0000000000..0c81b4b171
--- /dev/null
+++ b/packages/webgl/src/lib/components/Calendar/MonthPath.webgl.svelte
@@ -0,0 +1,55 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Cell/Cell.shared.svelte.ts b/packages/webgl/src/lib/components/Cell/Cell.shared.svelte.ts
new file mode 100644
index 0000000000..73c9aff57b
--- /dev/null
+++ b/packages/webgl/src/lib/components/Cell/Cell.shared.svelte.ts
@@ -0,0 +1 @@
+export type { CellProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Cell/Cell.svelte b/packages/webgl/src/lib/components/Cell/Cell.svelte
new file mode 100644
index 0000000000..358144e4be
--- /dev/null
+++ b/packages/webgl/src/lib/components/Cell/Cell.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Cell/Cell.webgl.svelte b/packages/webgl/src/lib/components/Cell/Cell.webgl.svelte
new file mode 100644
index 0000000000..d907a6d871
--- /dev/null
+++ b/packages/webgl/src/lib/components/Cell/Cell.webgl.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Chart/Chart.svelte b/packages/webgl/src/lib/components/Chart/Chart.svelte
new file mode 100644
index 0000000000..af34e8ad6a
--- /dev/null
+++ b/packages/webgl/src/lib/components/Chart/Chart.svelte
@@ -0,0 +1,17 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/ChartChildren/ChartAnnotations.svelte b/packages/webgl/src/lib/components/ChartChildren/ChartAnnotations.svelte
new file mode 100644
index 0000000000..273944052a
--- /dev/null
+++ b/packages/webgl/src/lib/components/ChartChildren/ChartAnnotations.svelte
@@ -0,0 +1,32 @@
+
+
+{#each visibleAnnotations as annotation}
+ {#if annotation.type === 'point'}
+
+ {:else if annotation.type === 'line'}
+
+ {:else if annotation.type === 'range'}
+
+ {/if}
+{/each}
diff --git a/packages/webgl/src/lib/components/ChartChildren/ChartChildren.svelte b/packages/webgl/src/lib/components/ChartChildren/ChartChildren.svelte
new file mode 100644
index 0000000000..33cabd0276
--- /dev/null
+++ b/packages/webgl/src/lib/components/ChartChildren/ChartChildren.svelte
@@ -0,0 +1,45 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/ChartClipPath/ChartClipPath.svelte b/packages/webgl/src/lib/components/ChartClipPath/ChartClipPath.svelte
new file mode 100644
index 0000000000..70b7b31103
--- /dev/null
+++ b/packages/webgl/src/lib/components/ChartClipPath/ChartClipPath.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/ChartClipPath/ChartClipPath.webgl.svelte b/packages/webgl/src/lib/components/ChartClipPath/ChartClipPath.webgl.svelte
new file mode 100644
index 0000000000..1a7098cc08
--- /dev/null
+++ b/packages/webgl/src/lib/components/ChartClipPath/ChartClipPath.webgl.svelte
@@ -0,0 +1,16 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Circle/Circle.shared.svelte.ts b/packages/webgl/src/lib/components/Circle/Circle.shared.svelte.ts
new file mode 100644
index 0000000000..19c84c0097
--- /dev/null
+++ b/packages/webgl/src/lib/components/Circle/Circle.shared.svelte.ts
@@ -0,0 +1,126 @@
+import type { ColorProp, DataProp } from 'layerchart';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+
+/**
+ * The core `Circle`'s props (in its order, as it describes them), then its style props, then
+ * those of a `WebGL` layer's own (`tooltip`, `style`)
+ */
+export type CircleProps = {
+ /**
+ * The center x position of the circle.
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via xScale
+ * - `function(d)`: accessor called per data item, result passed through xScale
+ *
+ * @default 0
+ */
+ cx?: DataProp;
+ /**
+ * The initial center x position of the circle (pixel mode only), to ease from with `motion`.
+ *
+ * @default cx
+ */
+ initialCx?: number;
+ /**
+ * The center y position of the circle.
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via yScale
+ * - `function(d)`: accessor called per data item, result passed through yScale
+ *
+ * @default 0
+ */
+ cy?: DataProp;
+ /**
+ * The initial center y position of the circle (pixel mode only), to ease from with `motion`.
+ *
+ * @default cy
+ */
+ initialCy?: number;
+ /**
+ * The radius of the circle.
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via rScale
+ * - `function(d)`: accessor called per data item, result passed through rScale
+ *
+ * @default 1
+ */
+ r?: DataProp;
+ /**
+ * Its height off the floor: a number of pixels, or a data key / function through the chart's
+ * `z` scale. Without one, the chart's `z` in data mode, else flat on the floor.
+ */
+ z?: DataProp;
+ /**
+ * Keep the circle facing the viewer (round), as the core `Circle` on an `isometric` chart.
+ * Always so here: a flat chart's circles are discs seen from above, and a 3D view's are
+ * spheres, round from any side.
+ *
+ * @default false
+ */
+ viewport?: boolean;
+ /**
+ * The initial radius of the circle (pixel mode only), to ease from with `motion` (ex. `0` to
+ * grow in).
+ *
+ * @default r
+ */
+ initialR?: number;
+ /**
+ * Data array to iterate over in data mode.
+ * Falls back to chart context data when not provided.
+ */
+ data?: any[];
+ /**
+ * Which circle each row is as rows change, for `motion`.
+ *
+ * @default (d, i) => i
+ */
+ key?: (d: any, index: number) => unknown;
+ /**
+ * Ease each circle to where it's asked to be, as the core `Circle` (ex. `'spring'`, or
+ * `{ type: 'tween', duration: 300 }`), or each of `cx`, `cy`, and `r` by its own (ex.
+ * `{ r: 'spring' }`)
+ */
+ motion?: MotionProp<'cx' | 'cy' | 'r'>;
+ /**
+ * Dashed-border pattern. Accepts a number (single dash length), a
+ * `[dash, gap, ...]` array, or a string (same syntax as SVG
+ * `stroke-dasharray`), in pixels: its ring's (drawn flat), its first dash and gap repeating.
+ */
+ dashArray?: number | number[] | string;
+
+ /**
+ * A CSS color, or a data key / function run through the chart's color scale (`none` or `null`
+ * for only its ring).
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ fill?: ColorProp | null;
+ /** The fill opacity (0 to 1), as the core `Circle`'s. @default 1 */
+ fillOpacity?: number;
+ /** A ring around it, in a CSS color or a data key / function run through the color scale */
+ stroke?: ColorProp;
+ /** The ring's width, in pixels. @default 1 */
+ strokeWidth?: number;
+ /** The ring's opacity (0 to 1), as the core `Circle`'s `strokeOpacity`. @default 1 */
+ strokeOpacity?: number;
+ /** @default 1 */
+ opacity?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+
+ /**
+ * Show the tooltip for the row the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+ /**
+ * Inline CSS, as on the core marks' elements (ex. `--fill-color: var(--color-primary)`): the
+ * colors it sets, as LayerChart's styles read them
+ */
+ style?: string;
+};
diff --git a/packages/webgl/src/lib/components/Circle/Circle.svelte b/packages/webgl/src/lib/components/Circle/Circle.svelte
new file mode 100644
index 0000000000..d64c8ff89e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Circle/Circle.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Circle/Circle.webgl.svelte b/packages/webgl/src/lib/components/Circle/Circle.webgl.svelte
new file mode 100644
index 0000000000..efb9a18e2a
--- /dev/null
+++ b/packages/webgl/src/lib/components/Circle/Circle.webgl.svelte
@@ -0,0 +1,179 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/CircleClipPath/CircleClipPath.svelte b/packages/webgl/src/lib/components/CircleClipPath/CircleClipPath.svelte
new file mode 100644
index 0000000000..bb30ca1190
--- /dev/null
+++ b/packages/webgl/src/lib/components/CircleClipPath/CircleClipPath.svelte
@@ -0,0 +1,23 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/CircleClipPath/CircleClipPath.webgl.svelte b/packages/webgl/src/lib/components/CircleClipPath/CircleClipPath.webgl.svelte
new file mode 100644
index 0000000000..f2de0a168e
--- /dev/null
+++ b/packages/webgl/src/lib/components/CircleClipPath/CircleClipPath.webgl.svelte
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/ClipPath/ClipPath.svelte b/packages/webgl/src/lib/components/ClipPath/ClipPath.svelte
new file mode 100644
index 0000000000..325a95ad6f
--- /dev/null
+++ b/packages/webgl/src/lib/components/ClipPath/ClipPath.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/ClipPath/ClipPath.webgl.svelte b/packages/webgl/src/lib/components/ClipPath/ClipPath.webgl.svelte
new file mode 100644
index 0000000000..81497bf0ae
--- /dev/null
+++ b/packages/webgl/src/lib/components/ClipPath/ClipPath.webgl.svelte
@@ -0,0 +1,145 @@
+
+
+
+
+{#if clipShapes && !path}
+
+{/if}
+{@render children?.({ id, url, useId })}
diff --git a/packages/webgl/src/lib/components/ClipPath/ClipShapes.svelte b/packages/webgl/src/lib/components/ClipPath/ClipShapes.svelte
new file mode 100644
index 0000000000..38c63139cd
--- /dev/null
+++ b/packages/webgl/src/lib/components/ClipPath/ClipShapes.svelte
@@ -0,0 +1,42 @@
+
+
+
+
+ {@render clip({ id })}
+
diff --git a/packages/webgl/src/lib/components/Contour/Contour.lines.svelte b/packages/webgl/src/lib/components/Contour/Contour.lines.svelte
new file mode 100644
index 0000000000..d2b1c2a4cc
--- /dev/null
+++ b/packages/webgl/src/lib/components/Contour/Contour.lines.svelte
@@ -0,0 +1,116 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Contour/Contour.shared.svelte.ts b/packages/webgl/src/lib/components/Contour/Contour.shared.svelte.ts
new file mode 100644
index 0000000000..a25a572fa1
--- /dev/null
+++ b/packages/webgl/src/lib/components/Contour/Contour.shared.svelte.ts
@@ -0,0 +1,95 @@
+import type { DataProp } from 'layerchart';
+import type { GridDataProps } from '../../utils/grid.js';
+
+/**
+ * The core `Contour`'s props (in its order, as it describes them), then those of a `WebGL`
+ * layer's own (`pixelSize`, `class`). Flat (on a flat chart, at `z={0}`) it's LayerChart's own
+ * `Contour`, drawn with WebGL marks; raised, or in a 3D view, lines of its own at each threshold.
+ */
+export type ContourProps = {
+ /**
+ * Row-major grid values (with `width` and `height`), or rows of scattered samples (with `x`,
+ * `y`, and `value`) to interpolate onto a grid.
+ */
+ data?: GridDataProps['data'];
+ /** Columns in a `data` grid */
+ width?: number;
+ /** Rows in a `data` grid */
+ height?: number;
+ /** Where a `data` grid's first column starts, in data coordinates (longitude on a map) */
+ x1?: number;
+ /** Where a `data` grid's first row starts, in data coordinates (latitude on a map) */
+ y1?: number;
+ /** Where a `data` grid's last column ends, in data coordinates */
+ x2?: number;
+ /** Where a `data` grid's last row ends, in data coordinates */
+ y2?: number;
+ /**
+ * A scattered row's value (a key or accessor), or a function `(x, y) => value` sampled across
+ * the plot in data coordinates (longitude and latitude on a map).
+ *
+ * @default 'value'
+ */
+ value?: GridDataProps['value'];
+ /** A scattered row's `x`. Defaults to the chart's. */
+ x?: GridDataProps['x'];
+ /** A scattered row's `y`. Defaults to the chart's. */
+ y?: GridDataProps['y'];
+ /** @default 'barycentric' */
+ interpolate?: GridDataProps['interpolate'];
+ /**
+ * A count of evenly spaced thresholds, or the values.
+ *
+ * @default 10
+ */
+ thresholds?: number | number[];
+ /**
+ * Blur the grid's values over this many cells before tracing the contours, smoothing out
+ * noise.
+ *
+ * @default 0
+ */
+ blur?: number;
+ /**
+ * Interpolate where each contour crosses between cells, rather than following the cells' edges.
+ *
+ * @default true
+ */
+ smooth?: boolean;
+ /**
+ * Height off the floor: a band property (ex. `'value'`, each line at its threshold's height) or
+ * function of the band, through the chart's `z` scale, or a number of pixels laying them all
+ * flat at that height. At `0` on a flat chart, it's LayerChart's own `Contour`: bands filled
+ * through the color scale, outlined only with a `stroke`. Raised, they're lines.
+ *
+ * @default 0
+ */
+ z?: DataProp;
+ /**
+ * The bands' fill color, flat. Defaults to each band's color through the chart's color scale.
+ * `'none'` (without a `stroke`) draws only their outlines, in those colors.
+ */
+ fill?: string;
+ /** The fill opacity of the bands, flat. (0 to 1) */
+ fillOpacity?: number;
+ /**
+ * The lines' color. Flat, none without one; raised, `var(--color-surface-content)`.
+ */
+ stroke?: string;
+ /** The stroke opacity of the raised lines. (0 to 1) */
+ strokeOpacity?: number;
+ /** The lines' width in pixels, the same at any depth. @default 1 */
+ strokeWidth?: number;
+ /** The opacity of the element. (0 to 1) */
+ opacity?: number;
+
+ /**
+ * Pixels between samples of a function, scattered rows, or a grid on a map. Raised lines
+ * only: flat, the core `Contour` samples its own grid.
+ *
+ * @default 4
+ */
+ pixelSize?: number;
+ /** CSS classes for the flat bands, as the core `Contour` takes them */
+ class?: string;
+};
diff --git a/packages/webgl/src/lib/components/Contour/Contour.svelte b/packages/webgl/src/lib/components/Contour/Contour.svelte
index 4d146e07e5..bc572401b5 100644
--- a/packages/webgl/src/lib/components/Contour/Contour.svelte
+++ b/packages/webgl/src/lib/components/Contour/Contour.svelte
@@ -1,93 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Contour/Contour.webgl.svelte b/packages/webgl/src/lib/components/Contour/Contour.webgl.svelte
new file mode 100644
index 0000000000..7da6d82f0a
--- /dev/null
+++ b/packages/webgl/src/lib/components/Contour/Contour.webgl.svelte
@@ -0,0 +1,31 @@
+
+
+
+
+{#if raised}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Density/Density.shared.svelte.ts b/packages/webgl/src/lib/components/Density/Density.shared.svelte.ts
new file mode 100644
index 0000000000..0795fc16b2
--- /dev/null
+++ b/packages/webgl/src/lib/components/Density/Density.shared.svelte.ts
@@ -0,0 +1 @@
+export type { DensityProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Density/Density.svelte b/packages/webgl/src/lib/components/Density/Density.svelte
new file mode 100644
index 0000000000..791b8b2de3
--- /dev/null
+++ b/packages/webgl/src/lib/components/Density/Density.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Density/Density.webgl.svelte b/packages/webgl/src/lib/components/Density/Density.webgl.svelte
new file mode 100644
index 0000000000..167799c3c6
--- /dev/null
+++ b/packages/webgl/src/lib/components/Density/Density.webgl.svelte
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Ellipse/Ellipse.svelte b/packages/webgl/src/lib/components/Ellipse/Ellipse.svelte
new file mode 100644
index 0000000000..cef1775753
--- /dev/null
+++ b/packages/webgl/src/lib/components/Ellipse/Ellipse.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Ellipse/Ellipse.webgl.svelte b/packages/webgl/src/lib/components/Ellipse/Ellipse.webgl.svelte
new file mode 100644
index 0000000000..45b8d62f1d
--- /dev/null
+++ b/packages/webgl/src/lib/components/Ellipse/Ellipse.webgl.svelte
@@ -0,0 +1,109 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/FacetAxis/FacetAxis.svelte b/packages/webgl/src/lib/components/FacetAxis/FacetAxis.svelte
new file mode 100644
index 0000000000..ac65ab27c5
--- /dev/null
+++ b/packages/webgl/src/lib/components/FacetAxis/FacetAxis.svelte
@@ -0,0 +1,8 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Frame/Frame.shared.svelte.ts b/packages/webgl/src/lib/components/Frame/Frame.shared.svelte.ts
new file mode 100644
index 0000000000..9e31e9ddd9
--- /dev/null
+++ b/packages/webgl/src/lib/components/Frame/Frame.shared.svelte.ts
@@ -0,0 +1 @@
+export type { FrameProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Frame/Frame.svelte b/packages/webgl/src/lib/components/Frame/Frame.svelte
new file mode 100644
index 0000000000..5d216405f2
--- /dev/null
+++ b/packages/webgl/src/lib/components/Frame/Frame.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Frame/Frame.webgl.svelte b/packages/webgl/src/lib/components/Frame/Frame.webgl.svelte
new file mode 100644
index 0000000000..c4130f9da9
--- /dev/null
+++ b/packages/webgl/src/lib/components/Frame/Frame.webgl.svelte
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoBin/GeoBin.cells.ts b/packages/webgl/src/lib/components/GeoBin/GeoBin.cells.ts
new file mode 100644
index 0000000000..6901f281c7
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoBin/GeoBin.cells.ts
@@ -0,0 +1,31 @@
+import { getContext, setContext } from 'svelte';
+
+/** One of a `GeoBin`'s paths (a cell, a column's side, its grid), with how it's painted */
+export type BinPath = {
+ readonly pathData: string | undefined;
+ readonly z: number;
+ readonly fill: string | undefined;
+ readonly fillOpacity: number;
+ readonly stroke: string | undefined;
+ readonly strokeOpacity: number;
+ readonly strokeWidth: number | undefined;
+ readonly opacity: number;
+ readonly class: string | undefined;
+ readonly onclick: ((e: MouseEvent) => void) | undefined;
+ readonly onpointerenter: ((e: PointerEvent) => void) | undefined;
+ readonly onpointermove: ((e: PointerEvent) => void) | undefined;
+ readonly onpointerleave: ((e: PointerEvent) => void) | undefined;
+};
+
+/** The paths a `GeoBin` draws, in order, and a count bumped (`bump`) as they come and go */
+export type BinPaths = { list: BinPath[]; readonly version: number; bump: () => void };
+
+const KEY = Symbol('LayerChartWebGLBinPaths');
+
+export function setBinPaths(paths: BinPaths) {
+ setContext(KEY, paths);
+}
+
+export function getBinPaths(): BinPaths {
+ return getContext(KEY);
+}
diff --git a/packages/webgl/src/lib/components/GeoBin/GeoBin.path.svelte b/packages/webgl/src/lib/components/GeoBin/GeoBin.path.svelte
new file mode 100644
index 0000000000..eae1c88b75
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoBin/GeoBin.path.svelte
@@ -0,0 +1,85 @@
+
diff --git a/packages/webgl/src/lib/components/GeoBin/GeoBin.svelte b/packages/webgl/src/lib/components/GeoBin/GeoBin.svelte
new file mode 100644
index 0000000000..cd981d2b1e
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoBin/GeoBin.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoBin/GeoBin.webgl.svelte b/packages/webgl/src/lib/components/GeoBin/GeoBin.webgl.svelte
new file mode 100644
index 0000000000..f96d6af874
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoBin/GeoBin.webgl.svelte
@@ -0,0 +1,132 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoCircle/GeoCircle.svelte b/packages/webgl/src/lib/components/GeoCircle/GeoCircle.svelte
new file mode 100644
index 0000000000..148c6e8b9d
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoCircle/GeoCircle.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoCircle/GeoCircle.webgl.svelte b/packages/webgl/src/lib/components/GeoCircle/GeoCircle.webgl.svelte
new file mode 100644
index 0000000000..37a0913095
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoCircle/GeoCircle.webgl.svelte
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoClipPath/GeoClipPath.svelte b/packages/webgl/src/lib/components/GeoClipPath/GeoClipPath.svelte
new file mode 100644
index 0000000000..ebba2c5016
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoClipPath/GeoClipPath.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoClipPath/GeoClipPath.webgl.svelte b/packages/webgl/src/lib/components/GeoClipPath/GeoClipPath.webgl.svelte
new file mode 100644
index 0000000000..6b59954ee3
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoClipPath/GeoClipPath.webgl.svelte
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.group.svelte b/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.group.svelte
new file mode 100644
index 0000000000..de23a7e765
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.group.svelte
@@ -0,0 +1,9 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.svelte b/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.svelte
new file mode 100644
index 0000000000..e21322c870
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.webgl.svelte b/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.webgl.svelte
new file mode 100644
index 0000000000..684d0c5292
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoEdgeFade/GeoEdgeFade.webgl.svelte
@@ -0,0 +1,11 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoPath/GeoPath.shared.svelte.ts b/packages/webgl/src/lib/components/GeoPath/GeoPath.shared.svelte.ts
new file mode 100644
index 0000000000..59e1f1cf66
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoPath/GeoPath.shared.svelte.ts
@@ -0,0 +1,124 @@
+import type { Snippet } from 'svelte';
+import type { draw as drawTransition } from 'svelte/transition';
+import type { ColorProp, DataProp } from 'layerchart';
+import type { Feature, FeatureCollection, Geometry, GeometryCollection } from 'geojson';
+import type {
+ GeoIdentityTransform,
+ GeoPath,
+ GeoProjection,
+ GeoSphere,
+ GeoTransformPrototype,
+} from 'd3-geo';
+import type { CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
+import type { MotionOptions } from 'layerchart/utils/motion.svelte';
+import type { MarkerOptions } from '../Line/markers.js';
+
+/**
+ * The core `GeoPath`'s props (in its order, as it describes them), then those of a `WebGL`
+ * layer's own (`class`)
+ */
+export type GeoPathProps = {
+ /**
+ * How tall each feature stands: a property key or function of the feature (through the chart's
+ * `z` scale), or a number of pixels. Flat on the floor without one.
+ */
+ z?: DataProp;
+ /**
+ * A feature, a collection of them (drawn as one mark), or a geometry. On a `globe`, their
+ * lines and outlines draw over it (filled shapes on a globe aren't drawn yet), and
+ * `{ type: 'Sphere' }` fills the globe itself (ex. the ocean beneath an image still loading).
+ */
+ geojson?:
+ | Feature
+ | FeatureCollection
+ | Geometry
+ | GeometryCollection
+ | GeoSphere
+ | null
+ | undefined;
+ /**
+ * Show the tooltip for the feature the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+ /**
+ * Click event handler, called with the path generator (as the core `GeoPath`'s), and the
+ * feature clicked
+ */
+ onclick?: ((e: MouseEvent, geoPath: GeoPath | undefined, feature: Feature) => void) | undefined;
+ /**
+ * The curve the projected outlines are drawn through, as the core `GeoPath`'s.
+ *
+ * @default curveLinearClosed
+ */
+ curve?: CurveFactory | CurveFactoryLineOnly;
+ /** Transform the projection's output, ex. to offset or scale every point (a `geoTransform`) */
+ geoTransform?: (projection: GeoProjection | GeoIdentityTransform) => GeoTransformPrototype;
+ /** Draw in place of the path, given the path generator (as the core `GeoPath`) */
+ children?: Snippet<[{ geoPath: GeoPath | undefined }]>;
+ /**
+ * A CSS color, or a function of the feature returning one (or a value for the chart's color
+ * scale). Lines have no fill. None by default, as the core `GeoPath` (`null` for none where
+ * a `class` sets one).
+ */
+ fill?: ColorProp | null;
+ /** The fill opacity of the element. (0 to 1) */
+ fillOpacity?: number;
+ /**
+ * The outlines' color: a CSS color, or a data key / function of the feature run through the
+ * chart's color scale (`null` for none).
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ stroke?: ColorProp | null;
+ /**
+ * Outline width in pixels, the same at any depth.
+ *
+ * @default 1
+ */
+ strokeWidth?: number;
+ /** The stroke opacity of the element. (0 to 1) */
+ strokeOpacity?: number;
+ /** The opacity of the element. (0 to 1) @default 1 */
+ opacity?: number;
+ /**
+ * Whether to animate the drawing of its outlines over time, as one path through its features.
+ * Pass either `true` or an object with transition options (`duration`, `delay`, `speed`,
+ * `easing`) to enable the transition. Drawn again as its shapes change.
+ */
+ draw?: boolean | Parameters[1];
+ /**
+ * Marker to attach to both start and end points of the line (one path through its features'
+ * outlines): drawn flat on the floor (over a globe, along it), turned along the line, in the
+ * first feature's stroke color
+ */
+ marker?: MarkerOptions;
+ /** Marker to attach to the middle point of the line (each point between its ends) */
+ markerMid?: MarkerOptions;
+ /** Marker to attach to the start point of the line */
+ markerStart?: MarkerOptions;
+ /** Marker to attach to the end point of the line */
+ markerEnd?: MarkerOptions;
+ /**
+ * Add additional content at the start of the line (its first feature's first point).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ startContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Add additional content at the end of the line (following it as `draw` draws it).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ endContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Ease each feature's height and fill to new values rather than jumping, ex. `'tween'` or
+ * `{ type: 'tween', duration: 800 }`.
+ */
+ motion?: MotionOptions;
+
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+};
diff --git a/packages/webgl/src/lib/components/GeoPath/GeoPath.svelte b/packages/webgl/src/lib/components/GeoPath/GeoPath.svelte
index 93672cce84..3ff8df784f 100644
--- a/packages/webgl/src/lib/components/GeoPath/GeoPath.svelte
+++ b/packages/webgl/src/lib/components/GeoPath/GeoPath.svelte
@@ -1,239 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoPath/GeoPath.webgl.svelte b/packages/webgl/src/lib/components/GeoPath/GeoPath.webgl.svelte
new file mode 100644
index 0000000000..b8cff14554
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoPath/GeoPath.webgl.svelte
@@ -0,0 +1,376 @@
+
+
+
+
+{#if children}
+ {@render children({ geoPath: pathGenerator })}
+{:else}
+ {#if marker || markerStart || markerMid || markerEnd}
+
+ {
+ const color = features.length ? strokeOf(features[0]) : null;
+ const points = outlines.flat(2);
+ return color
+ ? [
+ {
+ points,
+ color,
+ // Each vertex between its ends: its rings' and lines' every point
+ get mids() {
+ return Array.from(
+ { length: Math.max(0, points.length / 3 - 2) },
+ (_, k) => k + 1
+ );
+ },
+ },
+ ]
+ : [];
+ }}
+ {strokeWidth}
+ opacity={opacity * (look?.opacity ?? 1)}
+ />
+ {/if}
+ {#if startContent || endContent}
+ {@const ends = pathEnds(outlines.flat(), drawn.progress)}
+ {#if ends}
+
+ {/if}
+ {/if}
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoPoint/GeoPoint.shared.svelte.ts b/packages/webgl/src/lib/components/GeoPoint/GeoPoint.shared.svelte.ts
new file mode 100644
index 0000000000..30fe317538
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoPoint/GeoPoint.shared.svelte.ts
@@ -0,0 +1 @@
+export type { GeoPointProps } from 'layerchart/geo';
diff --git a/packages/webgl/src/lib/components/GeoPoint/GeoPoint.svelte b/packages/webgl/src/lib/components/GeoPoint/GeoPoint.svelte
new file mode 100644
index 0000000000..e2a8a4b44a
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoPoint/GeoPoint.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoPoint/GeoPoint.webgl.svelte b/packages/webgl/src/lib/components/GeoPoint/GeoPoint.webgl.svelte
new file mode 100644
index 0000000000..1841ee21ab
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoPoint/GeoPoint.webgl.svelte
@@ -0,0 +1,30 @@
+
+
+
+
+
+{#if children}
+
+
+ {@render children({ x, y })}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoRaster/GeoRaster.shared.svelte.ts b/packages/webgl/src/lib/components/GeoRaster/GeoRaster.shared.svelte.ts
new file mode 100644
index 0000000000..b7f72e10ac
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoRaster/GeoRaster.shared.svelte.ts
@@ -0,0 +1,75 @@
+import type { GeoProjection } from 'd3-geo';
+import type { ImageSource } from '../../utils/texture.js';
+
+/**
+ * The core `GeoRaster`'s props (in its order, as it describes them), then those of a `WebGL`
+ * layer's own (`elevation`, `pixelSize`, `opacity`, `tooltip`)
+ */
+export type GeoRasterProps = {
+ /**
+ * The image to lay over the map through the chart's projection (ex. NASA's Blue Marble), or
+ * wrap around its `globe`, as the core `GeoRaster` reprojects it: a URL, or an image,
+ * canvas, or bitmap already drawn. Equirectangular unless `sourceProjection` says otherwise:
+ * longitude across it from -180° to 180°, latitude down it from 90° to -90°.
+ */
+ image: ImageSource;
+ /**
+ * Projection used by the source image. Pass as an uncalled function, e.g.
+ * `sourceProjection={geoEquirectangular}`.
+ *
+ * When omitted, the source is assumed to be an equirectangular (plate carrée) image covering
+ * the full globe. Not on a `globe`, which wraps an equirectangular image.
+ */
+ sourceProjection?: () => GeoProjection;
+ /**
+ * How the image is sampled between its pixels: `'nearest'` for crisp, blocky pixels, or
+ * `'bilinear'` to blend them. The core `GeoRaster` defaults to `'nearest'`, as blending
+ * costs it ~4x the work; here the GPU blends for free.
+ *
+ * @default 'bilinear'
+ */
+ interpolate?: 'nearest' | 'bilinear';
+ /**
+ * `crossOrigin` attribute applied to the underlying `Image` element when loading from a URL.
+ * Set to `null` to disable.
+ *
+ * @default 'anonymous'
+ */
+ crossOrigin?: string | null;
+ /**
+ * Resolution multiplier for the reprojected output, relative to chart CSS pixels: the image is
+ * laid over points `pixelSize / resolution` pixels apart, so a value greater than 1 follows the
+ * projection's curves (and terrain) more closely, at the cost of more of them.
+ *
+ * @default 1
+ */
+ resolution?: number;
+ /**
+ * Draw the image's pixels as crisp blocks (as `interpolate: 'nearest'`), for a pixel-art look.
+ *
+ * @default false
+ */
+ pixelated?: boolean;
+
+ /**
+ * Raise the image into terrain: a function of longitude and latitude returning a value for
+ * the chart's `z` scale (ex. elevation in meters). `NaN` leaves a place out (ex. beyond the
+ * elevation loaded), as `Surface` does.
+ */
+ elevation?: (longitude: number, latitude: number) => number;
+ /**
+ * Pixels between the points the image is laid over.
+ *
+ * @default 4
+ */
+ pixelSize?: number;
+ /** The opacity of the element. (0 to 1) @default 1 */
+ opacity?: number;
+ /**
+ * Show the tooltip for the longitude / latitude the pointer is over (with the chart's
+ * `tooltipContext`), and its `elevation`.
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/GeoRaster/GeoRaster.svelte b/packages/webgl/src/lib/components/GeoRaster/GeoRaster.svelte
index f36ac50bdd..18abea0f98 100644
--- a/packages/webgl/src/lib/components/GeoRaster/GeoRaster.svelte
+++ b/packages/webgl/src/lib/components/GeoRaster/GeoRaster.svelte
@@ -1,287 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoRaster/GeoRaster.webgl.svelte b/packages/webgl/src/lib/components/GeoRaster/GeoRaster.webgl.svelte
new file mode 100644
index 0000000000..459d04cd27
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoRaster/GeoRaster.webgl.svelte
@@ -0,0 +1,237 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoSpline/GeoSpline.svelte b/packages/webgl/src/lib/components/GeoSpline/GeoSpline.svelte
new file mode 100644
index 0000000000..993c2a0d32
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoSpline/GeoSpline.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoSpline/GeoSpline.webgl.svelte b/packages/webgl/src/lib/components/GeoSpline/GeoSpline.webgl.svelte
new file mode 100644
index 0000000000..6915a7f674
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoSpline/GeoSpline.webgl.svelte
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/GeoTile/GeoTile.shared.svelte.ts b/packages/webgl/src/lib/components/GeoTile/GeoTile.shared.svelte.ts
new file mode 100644
index 0000000000..736df70aaa
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoTile/GeoTile.shared.svelte.ts
@@ -0,0 +1,93 @@
+import type { Snippet } from 'svelte';
+import type { GroupProps } from 'layerchart';
+import type { ElevationEncoding, Tile } from '../../utils/tiles.js';
+
+/**
+ * Elevation tiles to raise a `GeoTile` into terrain: a second tile service beside its imagery,
+ * with its own encoding and zoom limit
+ */
+export type GeoTileElevation = {
+ /** An elevation tile's URL from its column, row, and zoom (ex. AWS's open terrain tiles) */
+ url: (x: number, y: number, z: number) => string;
+ /**
+ * How the tiles pack meters into their colors: `'terrarium'` (ex. AWS, Mapterhorn) or
+ * `'mapbox'` (Terrain-RGB).
+ *
+ * @default 'terrarium'
+ */
+ encoding?: ElevationEncoding;
+ /** The deepest zoom the tiles go to: deeper ones use part of an ancestor's (as `maxZoom`) */
+ maxZoom?: number;
+};
+
+/**
+ * The core `GeoTile`'s props (in its order, as it describes them), then those of a `WebGL`
+ * layer's own (`maxZoom`, `elevation`, `segments`, ...)
+ */
+export type GeoTileProps = {
+ /** A tile's image URL, from its column, row, and zoom (an XYZ tile service, as the core `GeoTile` takes) */
+ url: (x: number, y: number, z: number) => string;
+ /**
+ * Zoom levels to add to (or take from) the one picked for the view, for sharper (or fewer)
+ * tiles.
+ *
+ * @default 0
+ */
+ zoomDelta?: number;
+ /**
+ * Pixels across a tile, for picking the zoom.
+ *
+ * @default 256
+ */
+ tileSize?: number;
+ /**
+ * Load each image anew rather than from those loaded before.
+ *
+ * @default false
+ */
+ disableCache?: boolean;
+ /**
+ * Props for the `Group` the tiles are drawn in (ex. `{ opacity: 0.5 }`, or `x` / `y` to move
+ * them)
+ */
+ group?: Partial;
+ /**
+ * Outline each tile, labeled with its zoom / column / row.
+ *
+ * @default false
+ */
+ debug?: boolean;
+ /**
+ * Draw in place of the tiles, given those covering the view (each `[x, y, z]`): none of their
+ * images load
+ */
+ children?: Snippet<[{ tiles: Tile[] }]>;
+
+ /**
+ * The deepest zoom the image tiles go to: deeper tiles show part of their ancestor's image,
+ * enlarged (ex. imagery that stops at zoom 12 under terrain that doesn't)
+ */
+ maxZoom?: number;
+ /**
+ * Raise the tiles into terrain from elevation tiles: their `url`, `encoding`, and `maxZoom`,
+ * their meters run through the chart's `z` scale
+ */
+ elevation?: GeoTileElevation;
+ /**
+ * Points across each tile's mesh: more follow terrain (or a projection's curves) more closely.
+ *
+ * @default 64 with `elevation`, else 16
+ */
+ segments?: number;
+ /** The opacity of the tiles. (0 to 1) @default 1 */
+ opacity?: number;
+ /**
+ * Show the tooltip for the longitude / latitude the pointer is over (with the chart's
+ * `tooltipContext`), and its elevation.
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+ /** The tiles drawn, as `[x, y, z]`, when they change */
+ onTilesChange?: (tiles: Tile[]) => void;
+};
diff --git a/packages/webgl/src/lib/components/GeoTile/GeoTile.svelte b/packages/webgl/src/lib/components/GeoTile/GeoTile.svelte
index 9ac88cbbea..fddb01a4c7 100644
--- a/packages/webgl/src/lib/components/GeoTile/GeoTile.svelte
+++ b/packages/webgl/src/lib/components/GeoTile/GeoTile.svelte
@@ -1,1075 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoTile/GeoTile.tiles.svelte b/packages/webgl/src/lib/components/GeoTile/GeoTile.tiles.svelte
new file mode 100644
index 0000000000..2206dfd423
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoTile/GeoTile.tiles.svelte
@@ -0,0 +1,1011 @@
+
+
+
+
+{#if children}
+ {@render children({ tiles })}
+{/if}
diff --git a/packages/webgl/src/lib/components/GeoTile/GeoTile.webgl.svelte b/packages/webgl/src/lib/components/GeoTile/GeoTile.webgl.svelte
new file mode 100644
index 0000000000..5a00cd6a49
--- /dev/null
+++ b/packages/webgl/src/lib/components/GeoTile/GeoTile.webgl.svelte
@@ -0,0 +1,19 @@
+
+
+
+
+
+{#if group}
+
+
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Graticule/Graticule.shared.svelte.ts b/packages/webgl/src/lib/components/Graticule/Graticule.shared.svelte.ts
new file mode 100644
index 0000000000..b494645370
--- /dev/null
+++ b/packages/webgl/src/lib/components/Graticule/Graticule.shared.svelte.ts
@@ -0,0 +1,16 @@
+import type { GeoPathProps } from '../GeoPath/GeoPath.shared.svelte.js';
+
+/**
+ * The core `Graticule`'s props (in its order), then the `GeoPath` props it draws its lines with,
+ * as the core `Graticule` takes them
+ */
+export type GraticuleProps = {
+ /** Each meridian and parallel as its own line, styled by these (or the graticule's) props */
+ lines?: Partial> | boolean;
+ /** The graticule's outline, styled by these (or the graticule's) props */
+ outline?: Partial> | boolean;
+ /** Degrees between meridians. @default 10 */
+ stepX?: number;
+ /** Degrees between parallels. @default 10 */
+ stepY?: number;
+} & Partial;
diff --git a/packages/webgl/src/lib/components/Graticule/Graticule.svelte b/packages/webgl/src/lib/components/Graticule/Graticule.svelte
new file mode 100644
index 0000000000..5fb9fef5f5
--- /dev/null
+++ b/packages/webgl/src/lib/components/Graticule/Graticule.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Graticule/Graticule.webgl.svelte b/packages/webgl/src/lib/components/Graticule/Graticule.webgl.svelte
new file mode 100644
index 0000000000..5004908cc4
--- /dev/null
+++ b/packages/webgl/src/lib/components/Graticule/Graticule.webgl.svelte
@@ -0,0 +1,29 @@
+
+
+
+
+
+{#if !lines && !outline}
+
+
+{/if}
+
+{#if lines}
+ {#each graticule.lines() as line}
+
+ {/each}
+{/if}
+
+{#if outline}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Grid/Grid.shared.svelte.ts b/packages/webgl/src/lib/components/Grid/Grid.shared.svelte.ts
new file mode 100644
index 0000000000..6d622adc97
--- /dev/null
+++ b/packages/webgl/src/lib/components/Grid/Grid.shared.svelte.ts
@@ -0,0 +1,89 @@
+import type { TicksConfig } from 'layerchart';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+
+/** How one axis' grid lines are drawn, as the core `Grid` forwards them onto its lines */
+export type GridLineProps = {
+ /** CSS classes to style them by (their stroke, width, and opacity) */
+ class?: string;
+ stroke?: string;
+ /** Width in pixels, the same at any depth. @default 1 */
+ strokeWidth?: number;
+ opacity?: number;
+ /** Dashed-line pattern: a dash length, `[dash, gap]`, or an SVG `stroke-dasharray`, in pixels */
+ dashArray?: number | number[] | string;
+};
+
+/**
+ * The core `Grid`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`walls`, `fill`)
+ */
+export type GridProps = {
+ /**
+ * Draw a x-axis lines, across the floor and up the wall behind (spokes at its ticks in a
+ * `radial` chart). Pass props (class, stroke, strokeWidth, opacity, dashArray) to style them.
+ *
+ * @default false, as the core `Grid`, unless none of `x`, `y`, and `z` is turned on (then true)
+ */
+ x?: boolean | GridLineProps;
+ /**
+ * Draw a y-axis lines, across the floor and up the wall behind (circles at its ticks in a
+ * `radial` chart). Pass props (class, stroke, strokeWidth, opacity, dashArray) to style them.
+ *
+ * @default false, as the core `Grid`, unless none of `x`, `y`, and `z` is turned on (then true)
+ */
+ y?: boolean | GridLineProps;
+ /**
+ * Draw lines at the `z` scale's ticks, around both walls, and pass props to style them.
+ *
+ * @default false, unless none of `x`, `y`, and `z` is turned on (then true)
+ */
+ z?: boolean | GridLineProps;
+ /** Control the number of x-axis ticks: a count, values, or an interval, as for `Axis` */
+ xTicks?: TicksConfig;
+ /** Control the number of y-axis ticks: a count, values, or an interval, as for `Axis` */
+ yTicks?: TicksConfig;
+ /** Control the number of `z` gridlines: a count, values, or an interval, as for `Axis` */
+ zTicks?: TicksConfig;
+ /**
+ * Line alignment when band scale is used (x or y axis): through each band's middle, or between
+ * the bands (and past the last).
+ *
+ * @default 'center'
+ */
+ bandAlign?: 'center' | 'between';
+ /**
+ * Render `y` lines with circles or linear splines
+ *
+ * @default 'circle'
+ */
+ radialY?: 'circle' | 'linear';
+ /**
+ * Stroke color for grid lines.
+ *
+ * @default 'color-mix(in oklab, var(--color-surface-content) 10%, transparent)'
+ */
+ stroke?: string;
+ /**
+ * Classes to style the lines by (their stroke, width, and opacity): `root` for all of it,
+ * `line` for every line.
+ *
+ * @default {}
+ */
+ classes?: {
+ root?: string;
+ line?: string;
+ };
+ /** Ease each line to where its tick moves, ex. `'tween'` or `{ type: 'spring' }` */
+ motion?: MotionProp;
+
+ /**
+ * Shade the floor and the two walls away from the camera. The walls turn to stay behind
+ * the plot as the camera orbits, and only stand when the chart has height (`z`). Flat
+ * (without a `view`), the floor is left clear, as the core `Grid` leaves it.
+ *
+ * @default true with a `view`, else false
+ */
+ walls?: boolean;
+ /** The floor and walls' CSS color */
+ fill?: string;
+};
diff --git a/packages/webgl/src/lib/components/Grid/Grid.svelte b/packages/webgl/src/lib/components/Grid/Grid.svelte
index 182904c701..a6e9b897a2 100644
--- a/packages/webgl/src/lib/components/Grid/Grid.svelte
+++ b/packages/webgl/src/lib/components/Grid/Grid.svelte
@@ -1,172 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Grid/Grid.webgl.svelte b/packages/webgl/src/lib/components/Grid/Grid.webgl.svelte
new file mode 100644
index 0000000000..e32e9e1100
--- /dev/null
+++ b/packages/webgl/src/lib/components/Grid/Grid.webgl.svelte
@@ -0,0 +1,255 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Group/Group.base.svelte b/packages/webgl/src/lib/components/Group/Group.base.svelte
new file mode 100644
index 0000000000..04ee1d8c68
--- /dev/null
+++ b/packages/webgl/src/lib/components/Group/Group.base.svelte
@@ -0,0 +1,51 @@
+
+
+{@render children?.()}
diff --git a/packages/webgl/src/lib/components/Group/Group.shared.svelte.ts b/packages/webgl/src/lib/components/Group/Group.shared.svelte.ts
new file mode 100644
index 0000000000..5ed2a194b2
--- /dev/null
+++ b/packages/webgl/src/lib/components/Group/Group.shared.svelte.ts
@@ -0,0 +1 @@
+export type { GroupProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Group/Group.svelte b/packages/webgl/src/lib/components/Group/Group.svelte
new file mode 100644
index 0000000000..aac12e8489
--- /dev/null
+++ b/packages/webgl/src/lib/components/Group/Group.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Group/Group.webgl.svelte b/packages/webgl/src/lib/components/Group/Group.webgl.svelte
new file mode 100644
index 0000000000..d1229e7e33
--- /dev/null
+++ b/packages/webgl/src/lib/components/Group/Group.webgl.svelte
@@ -0,0 +1,28 @@
+
+
+
+
+{#if c.hidden}
+
+{:else if c.dataMode}
+ {#each c.resolvedItems as item (item.key)}
+
+ {@render props.children?.()}
+
+ {/each}
+{:else}
+
+ {@render props.children?.()}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Highlight/Highlight.shared.svelte.ts b/packages/webgl/src/lib/components/Highlight/Highlight.shared.svelte.ts
new file mode 100644
index 0000000000..e6641c64f2
--- /dev/null
+++ b/packages/webgl/src/lib/components/Highlight/Highlight.shared.svelte.ts
@@ -0,0 +1,119 @@
+import type { Snippet } from 'svelte';
+import type { Accessor, HighlightPoint } from 'layerchart';
+import type { BarProps } from '../Bar/Bar.shared.svelte.js';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+
+/** The band (or slice) under the highlighted row, in pixels, as an `area` snippet is given it */
+export type HighlightArea = { x: number; y: number; width: number; height: number };
+
+/** How a `Highlight`'s point is drawn, as the core `Circle` props */
+export type HighlightPointProps = {
+ /** Radius in pixels on screen. @default 4 */
+ r?: number;
+ /** Defaults to the row's color (the chart's `c`), else the primary color */
+ fill?: string;
+ /** @default 'white' */
+ stroke?: string;
+ /** Defaults to `2` with an `r`, else `6` */
+ strokeWidth?: number;
+ opacity?: number;
+ class?: string;
+};
+
+/** How a `Highlight`'s lines are drawn, as the core `Line` props */
+export type HighlightLineProps = {
+ /** @default 'color-mix(in oklab, var(--color-surface-content) 20%, transparent)' */
+ stroke?: string;
+ /** Width in pixels, the same at any depth. @default 2 */
+ strokeWidth?: number;
+ opacity?: number;
+ /** CSS classes to style them by (their stroke, width, and opacity) */
+ class?: string;
+};
+
+/** How a `Highlight`'s shadows are drawn */
+export type HighlightShadowProps = {
+ /** Radius in pixels, as the view is fitted. @default 6 */
+ r?: number;
+ /** @default 'color-mix(in oklab, var(--color-surface-content) 20%, transparent)' */
+ fill?: string;
+ opacity?: number;
+ /** CSS classes to style them by (their fill and opacity) */
+ class?: string;
+};
+
+/**
+ * The core `Highlight`'s props (in its order, as it describes them). Its points are drawn over
+ * the scene facing the viewer, and its lines and shadows in it.
+ */
+export type HighlightProps = {
+ /** Highlight specific data (annotate). Defaults to the tooltip's row. */
+ data?: any;
+ /** Override `x` from context */
+ x?: Accessor;
+ /** Override `y` from context */
+ y?: Accessor;
+ /**
+ * Override `z` from context: the point floats at the row's height. `z={() => 0}` puts it on
+ * the floor beneath instead.
+ */
+ z?: Accessor;
+ /**
+ * Use the chart's radius scale for the point's size: `true` for the chart's `r`, or an accessor
+ * for the value to scale
+ */
+ r?: boolean | Accessor;
+ /**
+ * Which of the row's positions the lines trace: across the floor at its `x`, `y`, or both, and
+ * up the back wall along that axis
+ */
+ axis?: 'x' | 'y' | 'both' | 'none';
+ /**
+ * Mark the row with a point facing the viewer, and how it's drawn.
+ * @default false
+ */
+ points?: boolean | HighlightPointProps;
+ /**
+ * Trace the row's position on the floor and, with a `z`, each back wall: across it at the row's
+ * height, and up it at the row's `x` or `y` (with `axis`).
+ * @default false
+ */
+ lines?: boolean | HighlightLineProps;
+ /**
+ * With a `z`, a spot beneath the row on the floor and level with it on each back wall.
+ * @default false
+ */
+ shadows?: boolean | HighlightShadowProps;
+ /**
+ * Show area and pass props to Rect: the band (or slice) under the highlighted row (ex.
+ * `{ class: 'fill-primary/10' }`), or a snippet drawing it from the `area`
+ *
+ * @default false
+ */
+ area?: boolean | Record | Snippet<[{ area: HighlightArea }]>;
+ /**
+ * Show bar and pass props to Bar: the highlighted row's bar, over its own (ex. `{ class:
+ * 'fill-primary' }`), or a snippet drawing it
+ *
+ * @default false
+ */
+ bar?: boolean | Partial | Snippet;
+ /**
+ * `'spring'` to glide from one highlighted row to the next (as the core `Highlight`), or
+ * `'none'`. It follows each step of a pan or zoom at once, rather than chasing it.
+ * @default 'spring'
+ */
+ motion?: MotionProp;
+ /** The opacity of the element. (0 to 1) */
+ opacity?: number;
+ /** Called with the highlighted row as its `area` is clicked */
+ onAreaClick?: (e: MouseEvent, detail: { data: any }) => void;
+ /** Called with the highlighted row as its `bar` is clicked */
+ onBarClick?: (e: MouseEvent, detail: { data: any }) => void;
+ /** Called with its point (in the chart's pixels) and the highlighted row as the point is clicked */
+ onPointClick?: (e: MouseEvent, detail: { point: HighlightPoint; data: any }) => void;
+ /** Called with its point and the highlighted row as the pointer moves onto the point */
+ onPointEnter?: (e: MouseEvent, detail: { point: HighlightPoint; data: any }) => void;
+ /** Called with its point and the highlighted row as the pointer moves off the point */
+ onPointLeave?: (e: MouseEvent, detail: { point: HighlightPoint; data: any }) => void;
+};
diff --git a/packages/webgl/src/lib/components/Highlight/Highlight.svelte b/packages/webgl/src/lib/components/Highlight/Highlight.svelte
index d722cbead9..9bff46701b 100644
--- a/packages/webgl/src/lib/components/Highlight/Highlight.svelte
+++ b/packages/webgl/src/lib/components/Highlight/Highlight.svelte
@@ -1,323 +1,29 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Highlight/Highlight.webgl.svelte b/packages/webgl/src/lib/components/Highlight/Highlight.webgl.svelte
new file mode 100644
index 0000000000..c7590e1cd7
--- /dev/null
+++ b/packages/webgl/src/lib/components/Highlight/Highlight.webgl.svelte
@@ -0,0 +1,327 @@
+
+
+
+
+
+{#if area}
+
+{/if}
+
+
+{#if bar && row != null}
+ {#if typeof bar === 'function'}
+ {@render bar()}
+ {:else}
+ {@const own = typeof bar === 'object' ? bar : {}}
+ onBarClick(e, { data: row }))}
+ />
+ {/if}
+{/if}
diff --git a/packages/webgl/src/lib/components/Hull/Hull.shared.svelte.ts b/packages/webgl/src/lib/components/Hull/Hull.shared.svelte.ts
new file mode 100644
index 0000000000..c43b96c7e1
--- /dev/null
+++ b/packages/webgl/src/lib/components/Hull/Hull.shared.svelte.ts
@@ -0,0 +1 @@
+export type { HullProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Hull/Hull.svelte b/packages/webgl/src/lib/components/Hull/Hull.svelte
new file mode 100644
index 0000000000..850247d1c9
--- /dev/null
+++ b/packages/webgl/src/lib/components/Hull/Hull.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Hull/Hull.webgl.svelte b/packages/webgl/src/lib/components/Hull/Hull.webgl.svelte
new file mode 100644
index 0000000000..da3785d678
--- /dev/null
+++ b/packages/webgl/src/lib/components/Hull/Hull.webgl.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Image/Image.svelte b/packages/webgl/src/lib/components/Image/Image.svelte
new file mode 100644
index 0000000000..aa638a7c3e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Image/Image.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Image/Image.webgl.svelte b/packages/webgl/src/lib/components/Image/Image.webgl.svelte
new file mode 100644
index 0000000000..9bf356bb95
--- /dev/null
+++ b/packages/webgl/src/lib/components/Image/Image.webgl.svelte
@@ -0,0 +1,347 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Labels/Labels.shared.svelte.ts b/packages/webgl/src/lib/components/Labels/Labels.shared.svelte.ts
new file mode 100644
index 0000000000..71e5c13189
--- /dev/null
+++ b/packages/webgl/src/lib/components/Labels/Labels.shared.svelte.ts
@@ -0,0 +1 @@
+export type { LabelsProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Labels/Labels.svelte b/packages/webgl/src/lib/components/Labels/Labels.svelte
new file mode 100644
index 0000000000..69fc7fc39d
--- /dev/null
+++ b/packages/webgl/src/lib/components/Labels/Labels.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Labels/Labels.webgl.svelte b/packages/webgl/src/lib/components/Labels/Labels.webgl.svelte
new file mode 100644
index 0000000000..833c345bc8
--- /dev/null
+++ b/packages/webgl/src/lib/components/Labels/Labels.webgl.svelte
@@ -0,0 +1,16 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Line/Line.marker.svelte b/packages/webgl/src/lib/components/Line/Line.marker.svelte
new file mode 100644
index 0000000000..21d5b1e09c
--- /dev/null
+++ b/packages/webgl/src/lib/components/Line/Line.marker.svelte
@@ -0,0 +1,208 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Line/Line.markers.svelte b/packages/webgl/src/lib/components/Line/Line.markers.svelte
new file mode 100644
index 0000000000..1636e9033e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Line/Line.markers.svelte
@@ -0,0 +1,45 @@
+
+
+
+
+
+{#if markerStart}
+
+{/if}
+{#if markerMid}
+
+{/if}
+{#if markerEnd}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Line/Line.shared.svelte.ts b/packages/webgl/src/lib/components/Line/Line.shared.svelte.ts
new file mode 100644
index 0000000000..19da8f9f02
--- /dev/null
+++ b/packages/webgl/src/lib/components/Line/Line.shared.svelte.ts
@@ -0,0 +1,121 @@
+import type { ColorProp, DataProp } from 'layerchart';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+import type { MarkerOptions } from './markers.js';
+
+/**
+ * The core `Line`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`style`)
+ */
+export type LineProps = {
+ /**
+ * The x-coordinate of the line's starting point.
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via xScale
+ * - `function(d)`: accessor called per data item, result passed through xScale
+ *
+ * @required
+ */
+ x1: DataProp;
+ /** The initial x-coordinate of the line's starting point (pixel mode only). @default x1 */
+ initialX1?: number;
+ /**
+ * The y-coordinate of the line's starting point.
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via yScale
+ * - `function(d)`: accessor called per data item, result passed through yScale
+ *
+ * @required
+ */
+ y1: DataProp;
+ /** The initial y-coordinate of the line's starting point (pixel mode only). @default y1 */
+ initialY1?: number;
+ /**
+ * The x-coordinate of the line's ending point.
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via xScale
+ * - `function(d)`: accessor called per data item, result passed through xScale
+ *
+ * @required
+ */
+ x2: DataProp;
+ /** The initial x-coordinate of the line's ending point (pixel mode only). @default x2 */
+ initialX2?: number;
+ /**
+ * The y-coordinate of the line's ending point.
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via yScale
+ * - `function(d)`: accessor called per data item, result passed through yScale
+ *
+ * @default y2
+ */
+ y2: DataProp;
+ /**
+ * The height of the line's start off the floor (on an `isometric` chart, or in a 3D view): a
+ * data property or accessor (through zScale), or pixels.
+ *
+ * @default 0
+ */
+ z1?: DataProp;
+ /** The height of the line's end (see `z1`). @default 0 */
+ z2?: DataProp;
+ /** The initial y-coordinate of the line's ending point (pixel mode only). @default y2 */
+ initialY2?: number;
+ /**
+ * Data array to iterate over in data mode.
+ * Falls back to chart context data when not provided.
+ */
+ data?: any[];
+ /**
+ * Key function for each row in data mode, which its `motion` eases by.
+ *
+ * @default (d, i) => i
+ */
+ key?: (d: any, index: number) => any;
+ /**
+ * Marker to attach to both start and end points of the line: drawn flat on the floor, turned
+ * along the line, in its color
+ */
+ marker?: MarkerOptions;
+ /** Marker to attach to the start point of the line */
+ markerStart?: MarkerOptions;
+ /** Marker to attach to the mid point of the line (a straight line has none) */
+ markerMid?: MarkerOptions;
+ /** Marker to attach to the end point of the line */
+ markerEnd?: MarkerOptions;
+ /**
+ * Motion configuration: each end eased to where it's asked to be (ex. `'tween'`, or per end,
+ * `{ x2: { type: 'tween', duration: 300 } }`), from `initialX1` ... in pixel mode
+ */
+ motion?: MotionProp;
+ /**
+ * Dashed-line pattern. Accepts a number (single dash length), a `[dash, gap, ...]` array, or a
+ * string (same syntax as SVG `stroke-dasharray`), in pixels: its first dash and gap.
+ */
+ dashArray?: number | number[] | string;
+ /**
+ * The stroke color.
+ * - `string`: in data mode, if it matches a data property name, the value is extracted and
+ * passed through cScale. Otherwise used as a literal CSS color.
+ * - `function(d)`: accessor called per data item, result passed through cScale.
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ stroke?: ColorProp;
+ /** The stroke opacity (0 to 1) @default 1 */
+ strokeOpacity?: number;
+ /** The stroke width, in pixels @default 1 */
+ strokeWidth?: number;
+ /** The opacity (0 to 1) @default 1 */
+ opacity?: number;
+ /**
+ * CSS class name(s), as the core marks take them (ex. `stroke-primary`): the stroke, stroke
+ * width, and opacity they set, where its props don't say
+ */
+ class?: string;
+
+ /**
+ * Inline CSS, as on the core marks' elements (ex. `--fill-color: var(--color-primary)`): the
+ * colors it sets, as LayerChart's styles read them
+ */
+ style?: string;
+};
diff --git a/packages/webgl/src/lib/components/Line/Line.svelte b/packages/webgl/src/lib/components/Line/Line.svelte
new file mode 100644
index 0000000000..6fa38ada9c
--- /dev/null
+++ b/packages/webgl/src/lib/components/Line/Line.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Line/Line.webgl.svelte b/packages/webgl/src/lib/components/Line/Line.webgl.svelte
new file mode 100644
index 0000000000..2358802dbd
--- /dev/null
+++ b/packages/webgl/src/lib/components/Line/Line.webgl.svelte
@@ -0,0 +1,152 @@
+
+
+
+
+
+{#if marker || markerStart || markerMid || markerEnd}
+
+ lines.map((t) => ({
+ points: [t.x1, t.z1 + LIFT, t.y1, t.x2, t.z2 + LIFT, t.y2],
+ color: t.stroke,
+ }))}
+ {strokeWidth}
+ opacity={opacity * (look?.opacity ?? 1)}
+ />
+{/if}
diff --git a/packages/webgl/src/lib/components/Line/markers.ts b/packages/webgl/src/lib/components/Line/markers.ts
new file mode 100644
index 0000000000..056b4002ac
--- /dev/null
+++ b/packages/webgl/src/lib/components/Line/markers.ts
@@ -0,0 +1,84 @@
+import { line, type CurveFactory } from 'd3-shape';
+import type { LineProps as CoreLineProps } from 'layerchart';
+import { flattenPath } from '../../utils/path.js';
+
+/**
+ * A marker, as the core marks take one: a type (`arrow`, `triangle`, `line`, `circle`,
+ * `circle-stroke`, `dot`, `square`, `square-stroke`), or the core `Marker`'s props. A snippet
+ * (custom SVG) can't be drawn in a scene, so draws nothing.
+ */
+export type MarkerOptions = NonNullable;
+
+/** A line to mark: its points (`[x, height, y]` each), color, and vertices for `markerMid` */
+export type MarkedLine = {
+ points: ArrayLike;
+ color: string;
+ /** The points between its first and last a mid marker goes on (ex. a path's corners) */
+ mids?: number[];
+};
+
+/**
+ * Where SVG path data's commands end, as indices into `flattenPath(d)`'s points, but for its
+ * first and last: the vertices an SVG path draws its `marker-mid` on, rather than every point
+ * its curves are drawn in
+ */
+export function pathVertices(d: string): number[] {
+ const fine = flattenPath(d);
+ // A piece per curve, so just where each command ends
+ const coarse = flattenPath(d, 1);
+ const vertices: number[] = [];
+ let from = 0;
+ for (const [x, y] of coarse) {
+ let i = from;
+ while (i < fine.length && (fine[i][0] !== x || fine[i][1] !== y)) i++;
+ if (i < fine.length) {
+ vertices.push(i);
+ from = i + 1;
+ }
+ }
+ return vertices.slice(1, -1);
+}
+
+/**
+ * Where the commands of a d3 `curve` through `points` end, as indices into `sampled` (the curve's
+ * points `[x, height, y]` each, as `curvePoints` samples it): the vertices an SVG path of it draws
+ * its `marker-mid` on, first and last included
+ */
+export function curveVertices(
+ points: [number, number][],
+ curve: CurveFactory,
+ sampled: ArrayLike
+): number[] {
+ const ends: [number, number][] = [];
+ let start: [number, number] = [0, 0];
+ line()
+ .curve(curve)
+ .context({
+ moveTo: (x: number, y: number) => ends.push((start = [x, y])),
+ lineTo: (x: number, y: number) => ends.push([x, y]),
+ bezierCurveTo: (_a: number, _b: number, _c: number, _d: number, x: number, y: number) =>
+ ends.push([x, y]),
+ quadraticCurveTo: (_a: number, _b: number, x: number, y: number) => ends.push([x, y]),
+ closePath: () => ends.push(start),
+ arc() {},
+ arcTo() {},
+ rect() {},
+ } as unknown as CanvasRenderingContext2D)(points);
+ // Each command's end is one of the points sampled, exactly (a curve's last step lands on it)
+ const vertices: number[] = [];
+ const count = Math.floor(sampled.length / 3);
+ let from = 0;
+ for (const [x, y] of ends) {
+ let i = from;
+ while (
+ i < count &&
+ (Math.abs(sampled[3 * i] - x) > 1e-6 || Math.abs(sampled[3 * i + 2] - y) > 1e-6)
+ )
+ i++;
+ if (i < count) {
+ vertices.push(i);
+ from = i + 1;
+ }
+ }
+ return vertices;
+}
diff --git a/packages/webgl/src/lib/components/LinearGradient/LinearGradient.svelte b/packages/webgl/src/lib/components/LinearGradient/LinearGradient.svelte
new file mode 100644
index 0000000000..49d002af06
--- /dev/null
+++ b/packages/webgl/src/lib/components/LinearGradient/LinearGradient.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/LinearGradient/LinearGradient.webgl.svelte b/packages/webgl/src/lib/components/LinearGradient/LinearGradient.webgl.svelte
new file mode 100644
index 0000000000..71e5070ffe
--- /dev/null
+++ b/packages/webgl/src/lib/components/LinearGradient/LinearGradient.webgl.svelte
@@ -0,0 +1,60 @@
+
+
+
+{@render children?.({ id, gradient: `url(#${id})` })}
diff --git a/packages/webgl/src/lib/components/Link/Link.shared.svelte.ts b/packages/webgl/src/lib/components/Link/Link.shared.svelte.ts
new file mode 100644
index 0000000000..5e34830665
--- /dev/null
+++ b/packages/webgl/src/lib/components/Link/Link.shared.svelte.ts
@@ -0,0 +1,170 @@
+import type { Snippet } from 'svelte';
+import type { draw as drawTransition } from 'svelte/transition';
+import type { MotionNoneOption, MotionTweenOption } from 'layerchart/utils/motion.svelte';
+import type { CurveFactory } from 'd3-shape';
+import type { ColorProp, DataProp } from 'layerchart';
+import type { LinkSweep, LinkType } from 'layerchart/utils/linkUtils';
+import type { ValueProp } from '../../utils/values.js';
+import type { MarkerOptions } from '../Line/markers.js';
+
+/**
+ * The core `Link`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`arc`)
+ */
+export type LinkProps = {
+ /**
+ * Where each link starts across the plot: a data property name or function of the row
+ * through the chart's `x` scale (longitude on a map), or pixels
+ */
+ x1?: DataProp;
+ /** Where each link starts down the plot, as `x1` through the `y` scale (latitude on a map) */
+ y1?: DataProp;
+ /** Where each link ends across the plot, as `x1`. Defaults to `x1`. */
+ x2?: DataProp;
+ /** Where each link ends down the plot, as `y1`. Defaults to `y1`. */
+ y2?: DataProp;
+ /**
+ * The height of each link's start: a data property name or function of the row through the
+ * chart's `z` scale, or pixels.
+ *
+ * @default 0
+ */
+ z1?: DataProp;
+ /** The height of each link's end, as `z1`. @default 0 */
+ z2?: DataProp;
+ /**
+ * Rows to draw a link each for, or one link (as the core `Link` takes it). Falls back to the
+ * chart's data when `x1` / `y1` read rows.
+ */
+ data?: any[] | any;
+ /**
+ * Draw a `Sankey` layout's link (`data`), as the core `Link`: from its source node's right
+ * edge (`x1`) at its `y0` to its target's left edge (`x0`) at its `y1`, across horizontally.
+ *
+ * @default false
+ */
+ sankey?: boolean;
+ /**
+ * Without `x1` / `y1`: the node each link starts at (ex. a hierarchy's links), placed by `x`
+ * and `y` in pixels.
+ *
+ * @default (d) => d.source (with `sankey`, the source node, at the link's `y0`)
+ */
+ source?: (d: any) => any;
+ /** The node each link ends at, as `source`. @default (d) => d.target */
+ target?: (d: any) => any;
+ /**
+ * A node's pixels across the plot, for `source` / `target`.
+ *
+ * @default (node) => node.x (`node.y` with a horizontal `orientation`)
+ */
+ x?: (node: any) => number;
+ /**
+ * A node's pixels down the plot, for `source` / `target`.
+ *
+ * @default (node) => node.y (`node.x` with a horizontal `orientation`)
+ */
+ y?: (node: any) => number;
+ /**
+ * The path's shape across the floor, as the core `Link`: a d3 `curve` (`d3`), or a preset
+ * (`straight`, `square`, `beveled`, `rounded`, `swoop`). Straight around a `globe`.
+ *
+ * @default 'd3'
+ */
+ type?: LinkType;
+ /** A `rounded` path's corner radius. @default 20 */
+ radius?: number;
+ /** A `swoop` path's bend, in degrees. @default 22.5 */
+ bend?: number;
+ /** The d3 curve for `type="d3"`. @default curveBumpY (curveBumpX with a horizontal `orientation`) */
+ curve?: CurveFactory;
+ /** Which way a preset path turns first, as the core `Link` */
+ sweep?: LinkSweep;
+ /** Which way the tree it links grows. @default 'vertical' ('horizontal' with `sankey`) */
+ orientation?: 'vertical' | 'horizontal';
+ /**
+ * Lay the link out around a circle, as the core `Link` on a `radial` chart: a node's `x` is
+ * its angle (radians) and `y` its distance from the center, which is the origin (ex. inside a
+ * `Group center`). Defaults to the chart's `radial`.
+ */
+ radial?: boolean;
+ /**
+ * Marker to attach to both start and end points of the line: drawn flat on the floor, turned
+ * along the link, in its color
+ */
+ marker?: MarkerOptions;
+ /** Marker to attach to the middle point of the line (each corner between its ends) */
+ markerMid?: MarkerOptions;
+ /** Marker to attach to the start point of the line */
+ markerStart?: MarkerOptions;
+ /** Marker to attach to the end point of the line */
+ markerEnd?: MarkerOptions;
+ /**
+ * Tween each link to where it's asked to be, as the core `Link` (ex. `'tween'`, or `{ type:
+ * 'tween', duration: 300 }`)
+ */
+ motion?: MotionTweenOption | MotionNoneOption;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `stroke-surface-content/20`):
+ * the stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+ /**
+ * The `d` attribute of the rendered ``: SVG path data in the chart's pixels, drawn in
+ * place of the path between each link's ends (eased from its start's height to its end's).
+ *
+ * Accepts either a value (resolved at call site) or a function that returns the current value.
+ */
+ pathData?: string | null | (() => string | null | undefined);
+ /**
+ * Whether to animate the drawing of the path over time. Pass either `true` or an object with
+ * transition options (`duration`, `delay`, `speed`, `easing`) to enable the transition. Each
+ * link is drawn from its start, again as the links change.
+ *
+ * Works best with `tweened` disabled.
+ */
+ draw?: boolean | Parameters[1];
+ /**
+ * Add additional content at the start of each link (ex. a `Text`, inside a `Group` there).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ startContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Add additional content at the end of each link (following it as `draw` draws it).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ endContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Raise every link `z` pixels off the floor, or to the end of `[start, end]` (an unfilled path
+ * is only raised, as the core `Path`'s), over its ends' own `z1` / `z2`. @default 0
+ */
+ z?: number | [start: number, end: number];
+ /**
+ * The fill color of the element, or a function of the row: between a link's path and the
+ * chord across its ends, as an SVG path fills an open one. Only for a link lying flat (its
+ * ends at one height, without an `arc`, off a `globe`).
+ */
+ fill?: string | null | ((d: any) => string | null | undefined);
+ /** The fill opacity of the element. @default 1 */
+ fillOpacity?: number;
+ /**
+ * A CSS color, or a data key / function run through the chart's color scale.
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ stroke?: ColorProp;
+ /** The stroke opacity (0 to 1) @default 1 */
+ strokeOpacity?: number;
+ /** @default 1 */
+ strokeWidth?: number;
+ /** @default 1 */
+ opacity?: number;
+
+ /**
+ * How high each link arches above the straight line between its ends, in pixels (ex. flight
+ * paths over a map), or per row (a data key or function).
+ *
+ * @default 0 (straight)
+ */
+ arc?: ValueProp;
+};
diff --git a/packages/webgl/src/lib/components/Link/Link.svelte b/packages/webgl/src/lib/components/Link/Link.svelte
index 380d7e2ba7..41931b37bc 100644
--- a/packages/webgl/src/lib/components/Link/Link.svelte
+++ b/packages/webgl/src/lib/components/Link/Link.svelte
@@ -1,134 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Link/Link.webgl.svelte b/packages/webgl/src/lib/components/Link/Link.webgl.svelte
new file mode 100644
index 0000000000..073b06d954
--- /dev/null
+++ b/packages/webgl/src/lib/components/Link/Link.webgl.svelte
@@ -0,0 +1,373 @@
+
+
+
+
+{#if marker || markerStart || markerMid || markerEnd}
+
+ links.map((link, i) => ({
+ points: drawn[i],
+ color: link.stroke,
+ // Where its path's commands end (ex. a `square` link's corners), for `markerMid` alone
+ get mids() {
+ const d = link.path?.();
+ return d ? pathVertices(d) : [];
+ },
+ }))}
+ {strokeWidth}
+ opacity={opacity * (look?.opacity ?? 1)}
+ />
+{/if}
+
+{#if startContent || endContent}
+ {#each drawn as line, i (i)}
+ {@const ends = pathEnds([line], progress?.[i] ?? 1)}
+ {#if ends}
+
+ {/if}
+ {/each}
+{/if}
diff --git a/packages/webgl/src/lib/components/Month/Month.shared.svelte.ts b/packages/webgl/src/lib/components/Month/Month.shared.svelte.ts
new file mode 100644
index 0000000000..c8b68a3a6c
--- /dev/null
+++ b/packages/webgl/src/lib/components/Month/Month.shared.svelte.ts
@@ -0,0 +1 @@
+export type { MonthProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Month/Month.svelte b/packages/webgl/src/lib/components/Month/Month.svelte
new file mode 100644
index 0000000000..913d870e73
--- /dev/null
+++ b/packages/webgl/src/lib/components/Month/Month.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Month/Month.webgl.svelte b/packages/webgl/src/lib/components/Month/Month.webgl.svelte
new file mode 100644
index 0000000000..c7d53e0a55
--- /dev/null
+++ b/packages/webgl/src/lib/components/Month/Month.webgl.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Path/Path.ends.svelte b/packages/webgl/src/lib/components/Path/Path.ends.svelte
new file mode 100644
index 0000000000..a2e816d9a0
--- /dev/null
+++ b/packages/webgl/src/lib/components/Path/Path.ends.svelte
@@ -0,0 +1,44 @@
+
+
+
+
+
+{#if startContent && start}
+
+ {@render startContent(propsAt(start))}
+
+{/if}
+{#if endContent && end}
+
+ {@render endContent(propsAt(end))}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Path/Path.shared.svelte.ts b/packages/webgl/src/lib/components/Path/Path.shared.svelte.ts
new file mode 100644
index 0000000000..661328826a
--- /dev/null
+++ b/packages/webgl/src/lib/components/Path/Path.shared.svelte.ts
@@ -0,0 +1,78 @@
+import type { Snippet } from 'svelte';
+import type { draw as drawTransition } from 'svelte/transition';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+import type { MarkerOptions } from '../Line/markers.js';
+
+/**
+ * The core `Path`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`class`)
+ */
+export type PathProps = {
+ /**
+ * The `d` attribute of the rendered ``: SVG path data in the chart's pixels (ex. a d3
+ * shape's), lines, curves, and arcs, absolute or relative, in any number of subpaths.
+ *
+ * Accepts either a value (resolved at call site) or a function that returns the current value.
+ */
+ pathData?: string | null | (() => string | null | undefined);
+ /**
+ * Whether to animate the drawing of the path over time. Pass either `true` or an object with
+ * transition options (`duration`, `delay`, `speed`, `easing`) to enable the transition. Drawn
+ * again as the path data changes.
+ *
+ * Works best with `tweened` disabled.
+ */
+ draw?: boolean | Parameters[1];
+ /**
+ * Marker to attach to both start and end points of the line: drawn flat on the floor, turned
+ * along the path, in its stroke color
+ */
+ marker?: MarkerOptions;
+ /** Marker to attach to the middle point of the line (each vertex between its ends) */
+ markerMid?: MarkerOptions;
+ /** Marker to attach to the start point of the line */
+ markerStart?: MarkerOptions;
+ /** Marker to attach to the end point of the line */
+ markerEnd?: MarkerOptions;
+ /**
+ * Add additional content at the start of the line (ex. a `Text`, inside a `Group` there).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ startContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Add additional content at the end of the line (following it as `draw` draws it).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ endContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Tween to new path data, as the core `Path` (ex. `'tween'`, or `{ type: 'tween', duration:
+ * 300 }`)
+ */
+ motion?: MotionProp;
+ /**
+ * Stand the shape up `z` pixels off the floor (on an `isometric` chart, or in a 3D view), or
+ * between `[start, end]` (it lies at the top). @default 0
+ */
+ z?: number | [start: number, end: number];
+ /** The fill color of the element. Drawn only with one (here or in `class`), between its subpaths */
+ fill?: string | null;
+ /** The fill opacity of the element. @default 1 */
+ fillOpacity?: number;
+ /**
+ * The stroke color of the element. Drawn without a `fill` in `surface-content` unless
+ * `none`.
+ */
+ stroke?: string | null;
+ /** The stroke width of the element, in pixels. @default 1 */
+ strokeWidth?: number;
+ /** The stroke opacity of the element. (0 to 1) @default 1 */
+ strokeOpacity?: number;
+ /** The opacity of the element. (0 to 1) @default 1 */
+ opacity?: number;
+
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-primary/20
+ * stroke-primary`): the fill, stroke, stroke width, and opacity they set, where its props don't
+ */
+ class?: string;
+};
diff --git a/packages/webgl/src/lib/components/Path/Path.svelte b/packages/webgl/src/lib/components/Path/Path.svelte
new file mode 100644
index 0000000000..722e935697
--- /dev/null
+++ b/packages/webgl/src/lib/components/Path/Path.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Path/Path.webgl.svelte b/packages/webgl/src/lib/components/Path/Path.webgl.svelte
new file mode 100644
index 0000000000..66a05030e8
--- /dev/null
+++ b/packages/webgl/src/lib/components/Path/Path.webgl.svelte
@@ -0,0 +1,171 @@
+
+
+
+
+
+{#if outlined && (marker || markerStart || markerMid || markerEnd)}
+ [
+ {
+ points: outlines.flat(),
+ color: strokeColor!,
+ get mids() {
+ return vertices;
+ },
+ },
+ ]}
+ {strokeWidth}
+ opacity={opacity * (look?.opacity ?? 1)}
+ />
+{/if}
+
+{#if ends}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Path/draw.svelte.ts b/packages/webgl/src/lib/components/Path/draw.svelte.ts
new file mode 100644
index 0000000000..23235bddb1
--- /dev/null
+++ b/packages/webgl/src/lib/components/Path/draw.svelte.ts
@@ -0,0 +1,126 @@
+import { untrack } from 'svelte';
+import { cubicInOut, linear } from 'svelte/easing';
+import { Tween } from 'svelte/motion';
+import type { PathProps } from './Path.shared.svelte.js';
+
+/** A path's `draw`, as the core `Path` takes it */
+export type DrawOption = PathProps['draw'];
+
+/**
+ * Drawing paths from their starts, as the core `Path`'s `draw` (an SVG `draw` transition): again
+ * whenever the lengths read in `lengths` change (ex. new path data). Each path takes as long as
+ * `draw` gives one of its length (`duration`, or its length over `speed`), so the paths of one
+ * mark keep their own pace, as each SVG path's transition does. Call during component setup, and
+ * only with a `draw`.
+ */
+export function createDraw(draw: () => DrawOption, lengths: () => number[]) {
+ const options = () => {
+ const value = draw();
+ return typeof value === 'object' ? value : {};
+ };
+ /** How long a path of `length` pixels takes, as the SVG `draw` transition works it out */
+ const durationOf = (length: number) => {
+ const { duration, speed } = options();
+ if (typeof duration === 'function') return duration(length);
+ return duration ?? (speed ? length / speed : 800);
+ };
+
+ /** Milliseconds since it started, up to the longest path's duration */
+ const elapsed = new Tween(0, { easing: linear });
+ let end = $state(0);
+
+ $effect(() => {
+ const all = lengths();
+ untrack(() => {
+ const longest = all.reduce((max, length) => Math.max(max, durationOf(length)), 0);
+ end = longest;
+ elapsed.set(0, { duration: 0 });
+ elapsed.set(longest, { duration: longest, delay: options().delay ?? 0 });
+ });
+ });
+
+ return {
+ /** Whether every path is drawn */
+ get done() {
+ return elapsed.current >= end;
+ },
+ /** How much of a path of `length` pixels is drawn so far (0 to 1) */
+ progress(length: number) {
+ if (elapsed.current >= end) return 1;
+ const duration = durationOf(length);
+ if (!(duration > 0)) return 1;
+ return (options().easing ?? cubicInOut)(Math.min(1, elapsed.current / duration));
+ },
+ };
+}
+
+/** A line's length, its points `[x, height, y]` each in a flat array, in pixels */
+export function lengthOf(points: ArrayLike) {
+ let length = 0;
+ for (let i = 3; i + 2 < points.length; i += 3) {
+ length += Math.hypot(
+ points[i] - points[i - 3],
+ points[i + 1] - points[i - 2],
+ points[i + 2] - points[i - 1]
+ );
+ }
+ return length;
+}
+
+/**
+ * A line's first `length` pixels (points `[x, height, y]` each): its points up to there, and one
+ * part way to the next. Its `i`th point is the line's own, but the last, which heads to it.
+ */
+export function truncate(points: ArrayLike, length: number): number[] {
+ const out: number[] = [];
+ if (points.length < 3) return out;
+ out.push(points[0], points[1], points[2]);
+ let left = length;
+ for (let i = 3; i + 2 < points.length && left > 0; i += 3) {
+ const [ax, ah, ay] = [points[i - 3], points[i - 2], points[i - 1]];
+ const [bx, bh, by] = [points[i], points[i + 1], points[i + 2]];
+ const step = Math.hypot(bx - ax, bh - ah, by - ay);
+ if (step <= left) out.push(bx, bh, by);
+ else {
+ const t = left / step;
+ out.push(ax + (bx - ax) * t, ah + (bh - ah) * t, ay + (by - ay) * t);
+ }
+ left -= step;
+ }
+ return out;
+}
+
+/**
+ * Each of a path's subpaths as far as `draw` has drawn it (`progress` of their total length): from
+ * its own start, as SVG dashes each subpath
+ */
+export function drawnSubpaths(subpaths: number[][], progress: number): number[][] {
+ if (progress >= 1) return subpaths;
+ const length = progress * subpaths.reduce((sum, s) => sum + lengthOf(s), 0);
+ return subpaths.map((s) => truncate(s, length));
+}
+
+/**
+ * Where a path's `startContent` / `endContent` go, as the core `Path` places them: its first
+ * point, and the point `progress` of the way along it (its last, once drawn), `[x, height, y]`
+ */
+export function pathEnds(
+ subpaths: ArrayLike[],
+ progress = 1
+): { start: number[]; end: number[] } | null {
+ const first = subpaths.find((s) => s.length >= 3);
+ if (!first) return null;
+ const start = [first[0], first[1], first[2]];
+ let rest =
+ progress >= 1 ? Infinity : progress * subpaths.reduce((sum, s) => sum + lengthOf(s), 0);
+ let end = start;
+ for (const s of subpaths) {
+ if (s.length < 3) continue;
+ const length = lengthOf(s);
+ const reached = rest < length ? truncate(s, rest) : s;
+ end = [reached[reached.length - 3], reached[reached.length - 2], reached[reached.length - 1]];
+ if (rest < length) break;
+ rest -= length;
+ }
+ return { start, end };
+}
diff --git a/packages/webgl/src/lib/components/Pattern/Pattern.svelte b/packages/webgl/src/lib/components/Pattern/Pattern.svelte
new file mode 100644
index 0000000000..164ad83a6a
--- /dev/null
+++ b/packages/webgl/src/lib/components/Pattern/Pattern.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Pattern/Pattern.webgl.svelte b/packages/webgl/src/lib/components/Pattern/Pattern.webgl.svelte
new file mode 100644
index 0000000000..08ac5a722a
--- /dev/null
+++ b/packages/webgl/src/lib/components/Pattern/Pattern.webgl.svelte
@@ -0,0 +1,46 @@
+
+
+
+{@render children?.({ id, pattern: `url(#${id})` })}
diff --git a/packages/webgl/src/lib/components/Pie/Pie.shared.svelte.ts b/packages/webgl/src/lib/components/Pie/Pie.shared.svelte.ts
new file mode 100644
index 0000000000..3f96a4a1dc
--- /dev/null
+++ b/packages/webgl/src/lib/components/Pie/Pie.shared.svelte.ts
@@ -0,0 +1 @@
+export type { PieProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Pie/Pie.svelte b/packages/webgl/src/lib/components/Pie/Pie.svelte
new file mode 100644
index 0000000000..c6d3bab824
--- /dev/null
+++ b/packages/webgl/src/lib/components/Pie/Pie.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Pie/Pie.webgl.svelte b/packages/webgl/src/lib/components/Pie/Pie.webgl.svelte
new file mode 100644
index 0000000000..bd1178c2d3
--- /dev/null
+++ b/packages/webgl/src/lib/components/Pie/Pie.webgl.svelte
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Points/Points.base.svelte b/packages/webgl/src/lib/components/Points/Points.base.svelte
new file mode 100644
index 0000000000..b0e660e36e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Points/Points.base.svelte
@@ -0,0 +1,398 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Points/Points.shared.svelte.ts b/packages/webgl/src/lib/components/Points/Points.shared.svelte.ts
new file mode 100644
index 0000000000..dfb578658c
--- /dev/null
+++ b/packages/webgl/src/lib/components/Points/Points.shared.svelte.ts
@@ -0,0 +1,152 @@
+import type { Snippet } from 'svelte';
+import type { Point } from 'layerchart/base';
+import type { Accessor, ColorProp, DataProp } from 'layerchart';
+import type { ImageSource } from '../../utils/texture.js';
+import type { Offset } from '../../utils/marks.js';
+import type { ValueProp } from '../../utils/values.js';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+
+/**
+ * The core `Points`' props (in its order, as it describes them, then those it takes from
+ * `Circle`), then those of a `WebGL` layer's own (`glow`, `image`, ...)
+ */
+export type PointsProps = {
+ /** Override data instead of using context */
+ data?: any[];
+ /** Override `x` accessor from Chart context */
+ x?: Accessor;
+ /** Override `y` accessor from Chart context */
+ y?: Accessor;
+ /** Series key to use for accessor. */
+ seriesKey?: string;
+ /**
+ * Override `r` accessor from Chart context: a radius in pixels, or per row (a data key or
+ * function, in pixels). Defaults to the chart's `r` scale when it has one.
+ *
+ * @default 5
+ */
+ r?: ValueProp;
+ /** The offset of the point in the x direction */
+ offsetX?: Offset;
+ /** The offset of the point in the y direction */
+ offsetY?: Offset;
+ /** Draws in place of the points, given each row's point (ex. `Labels`' text at each) */
+ children?: Snippet<[{ points: Point[] }]>;
+ /**
+ * Fill color: a CSS color, or a data key / function run through the chart's color scale.
+ * Defaults to the chart's `c`, else `var(--color-primary)`.
+ */
+ fill?: ColorProp;
+ /** Fill opacity (0-1) */
+ fillOpacity?: number;
+ /**
+ * Stroke color: a CSS color, or a data key / function run through the chart's color scale.
+ * Drawn flat (2D), where points are discs; a 3D view's lit spheres have none.
+ */
+ stroke?: ColorProp;
+ /** Stroke width in pixels @default 1 */
+ strokeWidth?: number;
+ /** Stroke opacity (0-1) */
+ strokeOpacity?: number;
+ /** Overall opacity (0-1) @default 1 */
+ opacity?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set. A `mix-blend-mode` of `plus-lighter`
+ * or `screen` (ex. `mix-blend-plus-lighter`) adds the points' light together where they
+ * overlap.
+ */
+ class?: string;
+ /**
+ * Height off the floor: a data key or function (through the chart's `z` scale), or a number
+ * of pixels. Defaults to the chart's `z`.
+ */
+ z?: DataProp;
+ /**
+ * The initial center x position of each new point, in pixels, to ease from with `motion`.
+ *
+ * @default its own
+ */
+ initialCx?: number;
+ /**
+ * The initial center y position of each new point, in pixels, to ease from with `motion` (ex.
+ * the plot's bottom, to rise in).
+ *
+ * @default its own
+ */
+ initialCy?: number;
+ /**
+ * Keep the points facing the viewer (round) on an `isometric` chart, as the core `Points`:
+ * without it they lie on the floor as it does. A 3D view's are always spheres, round from any
+ * side.
+ *
+ * @default false
+ */
+ viewport?: boolean;
+ /**
+ * The initial radius of each new point, to ease from with `motion` (ex. `0` to grow in).
+ *
+ * @default its own
+ */
+ initialR?: number;
+ /**
+ * Which point each row is as rows change, for `motion` (a new key eases in from
+ * `initialCx` / `initialCy` / `initialR`).
+ *
+ * @default (d, i) => i
+ */
+ key?: (d: any, index: number) => unknown;
+ /**
+ * Ease each point to where it's asked to be, as the core `Points` (a `Circle` each) do (ex.
+ * `'spring'`, or `{ type: 'tween', duration: 300 }`), or each of `cx`, `cy`, and `r` by its
+ * own (ex. `{ r: 'spring' }`). None without it, at no cost.
+ */
+ motion?: MotionProp<'cx' | 'cy' | 'r'>;
+ /**
+ * Dashed-border pattern. Accepts a number (single dash length), a
+ * `[dash, gap, ...]` array, or a string (same syntax as SVG
+ * `stroke-dasharray`), in pixels: its ring's (drawn flat), its first dash and gap repeating.
+ */
+ dashArray?: number | number[] | string;
+
+ /**
+ * Scale of the hovered point.
+ *
+ * @default 1.4
+ */
+ hoverScale?: number;
+ /**
+ * Show the tooltip for the row the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+ /**
+ * Draw each sphere in its own color (or image), whatever the lights: ex. a star, lighting the
+ * rest with a `Light type="point"` inside it.
+ *
+ * @default false
+ */
+ glow?: boolean;
+ /**
+ * An equirectangular image to wrap each sphere in (ex. a planet's surface): a URL, or an image
+ * or canvas already drawn, or per row, a data key or function. A string names the row's field
+ * when the row has one by that name, else is a URL when it looks like one (`"earth.jpg"`).
+ * Rows without one are colored by `fill`.
+ */
+ image?: ValueProp;
+ /**
+ * Degrees to turn an image-wrapped sphere about its axis (ex. a planet's spin), or per row (a
+ * data key or function).
+ *
+ * @default 0
+ */
+ rotate?: ValueProp;
+ /**
+ * Degrees an image-wrapped sphere's axis leans from upright (ex. `23.4` for the Earth), or per
+ * row (a data key or function).
+ *
+ * @default 0
+ */
+ tilt?: ValueProp;
+};
diff --git a/packages/webgl/src/lib/components/Points/Points.svelte b/packages/webgl/src/lib/components/Points/Points.svelte
index 6e6e351808..6dfbec981e 100644
--- a/packages/webgl/src/lib/components/Points/Points.svelte
+++ b/packages/webgl/src/lib/components/Points/Points.svelte
@@ -1,367 +1,31 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Points/Points.webgl.svelte b/packages/webgl/src/lib/components/Points/Points.webgl.svelte
new file mode 100644
index 0000000000..7bc49e22ea
--- /dev/null
+++ b/packages/webgl/src/lib/components/Points/Points.webgl.svelte
@@ -0,0 +1,21 @@
+
+
+
+
+{#if children && c}
+ {@render children({ points: c.points })}
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Polygon/Polygon.shared.svelte.ts b/packages/webgl/src/lib/components/Polygon/Polygon.shared.svelte.ts
new file mode 100644
index 0000000000..7051fc3c67
--- /dev/null
+++ b/packages/webgl/src/lib/components/Polygon/Polygon.shared.svelte.ts
@@ -0,0 +1,105 @@
+import type { ColorProp, DataProp } from 'layerchart';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+
+/**
+ * The core `Polygon`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`tooltip`)
+ */
+export type PolygonProps = {
+ /**
+ * Center across: a data property name or function of the row through the chart's `x` scale
+ * (or longitude, through its projection), or pixels
+ */
+ cx?: DataProp;
+ /** The initial center across a polygon placed by pixels eases from with `motion`. @default cx */
+ initialCx?: number;
+ /**
+ * Center down: a data property name or function of the row through the chart's `y` scale (or
+ * latitude, through its projection), or pixels
+ */
+ cy?: DataProp;
+ /** The initial center down, as `initialCx`. @default cy */
+ initialCy?: number;
+ /**
+ * Radius: a data property name or function of the row through the chart's `r` scale, or
+ * pixels.
+ *
+ * @default 1
+ */
+ r?: DataProp;
+ /** The initial radius, as `initialCx`. @default r */
+ initialR?: number;
+ /** Rows to draw a polygon each for. Falls back to the chart's data when the props read rows. */
+ data?: any[];
+ /**
+ * Key function for each row in data mode, which its `motion` eases by.
+ *
+ * @default (d, i) => i
+ */
+ key?: (d: any, index: number) => any;
+ /**
+ * The number of corners of a regular polygon about `cx` / `cy`, or the corners themselves, in
+ * pixels.
+ *
+ * @default 4
+ */
+ points?: number | { x: number; y: number }[];
+ /** The radius of the curve for rounded corners. @default 0 */
+ cornerRadius?: number;
+ /** The rotation of the polygon, in degrees. @default 0 */
+ rotate?: number;
+ /** The percent to inset the odd points of the star (<1 inset, >1 outset). @default 0 */
+ inset?: number;
+ /** The horizontal stretch factor of the polygon. @default 1 */
+ scaleX?: number;
+ /** The vertical stretch factor of the polygon. @default 1 */
+ scaleY?: number;
+ /** The skew angle in degrees along the X axis. @default 0 */
+ skewX?: number;
+ /** The skew angle in degrees along the Y axis. @default 0 */
+ skewY?: number;
+ /** The tilt factor for x-coordinates. @default 0 */
+ tiltX?: number;
+ /** The tilt factor for y-coordinates. @default 0 */
+ tiltY?: number;
+ /**
+ * Ease each polygon's center and radius to where they're asked to be (ex. `'tween'`, or per
+ * prop, `{ r: { type: 'spring' } }`): a row at a time by its `key`, and one placed by pixels
+ * from `initialCx` ...
+ */
+ motion?: MotionProp;
+ /**
+ * How tall it stands, as the core `Polygon` on an `isometric` chart: a data property name
+ * or function of the row through the chart's `z` scale, pixels, or a `[start, end]` pair of
+ * pixels to float it between. Defaults to the chart's `z` with rows, else it lies flat.
+ */
+ z?: DataProp | [start: number, end: number];
+ /**
+ * A CSS color, or a key / function of the row run through the chart's color scale.
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ fill?: ColorProp;
+ /** The outline: a CSS color, or a key / function of the row run through the color scale */
+ stroke?: ColorProp;
+ /** The fill opacity (0 to 1) @default 1 */
+ fillOpacity?: number;
+ /** The stroke opacity (0 to 1) @default 1 */
+ strokeOpacity?: number;
+ /** @default 1 */
+ strokeWidth?: number;
+ /** @default 1 */
+ opacity?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+
+ /**
+ * Show the tooltip for the row the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/Polygon/Polygon.svelte b/packages/webgl/src/lib/components/Polygon/Polygon.svelte
index 67ddeb3e64..ace41bd2ea 100644
--- a/packages/webgl/src/lib/components/Polygon/Polygon.svelte
+++ b/packages/webgl/src/lib/components/Polygon/Polygon.svelte
@@ -1,199 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Polygon/Polygon.webgl.svelte b/packages/webgl/src/lib/components/Polygon/Polygon.webgl.svelte
new file mode 100644
index 0000000000..aa53f59c1b
--- /dev/null
+++ b/packages/webgl/src/lib/components/Polygon/Polygon.webgl.svelte
@@ -0,0 +1,196 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Raster/Raster.shared.svelte.ts b/packages/webgl/src/lib/components/Raster/Raster.shared.svelte.ts
new file mode 100644
index 0000000000..74d5436512
--- /dev/null
+++ b/packages/webgl/src/lib/components/Raster/Raster.shared.svelte.ts
@@ -0,0 +1,72 @@
+import type { GridDataProps } from '../../utils/grid.js';
+
+/**
+ * The core `Raster`'s props (in its order, as it describes them), then those of a `WebGL`
+ * layer's own (`z`, `tooltip`)
+ */
+export type RasterProps = {
+ /**
+ * Row-major grid values (with `width` and `height`), or rows of scattered samples (with `x`,
+ * `y`, and `value`) to interpolate onto a grid.
+ */
+ data?: GridDataProps['data'];
+ /** Columns in a `data` grid */
+ width?: number;
+ /** Rows in a `data` grid */
+ height?: number;
+ /** Where a `data` grid's first column starts, in data coordinates (longitude on a map) */
+ x1?: number;
+ /** Where a `data` grid's first row starts, in data coordinates (latitude on a map) */
+ y1?: number;
+ /** Where a `data` grid's last column ends, in data coordinates */
+ x2?: number;
+ /** Where a `data` grid's last row ends, in data coordinates */
+ y2?: number;
+ /**
+ * A scattered row's value (a key or accessor), or a function `(x, y) => value` sampled across
+ * the plot in data coordinates (longitude and latitude on a map).
+ *
+ * @default 'value'
+ */
+ value?: GridDataProps['value'];
+ /** A scattered row's `x`. Defaults to the chart's. */
+ x?: GridDataProps['x'];
+ /** A scattered row's `y`. Defaults to the chart's. */
+ y?: GridDataProps['y'];
+ /** @default 'barycentric' */
+ interpolate?: GridDataProps['interpolate'];
+ /**
+ * Pixels between samples of a function, scattered rows, or a grid on a map.
+ *
+ * @default 1
+ */
+ pixelSize?: number;
+ /**
+ * Blur the image over this many cells, smoothing between them.
+ *
+ * @default 0
+ */
+ blur?: number;
+ /**
+ * `'pixelated'` shows each cell as a hard-edged square; `'auto'` blends between them.
+ * `'crisp-edges'` is `'pixelated'`.
+ *
+ * @default 'auto'
+ */
+ imageRendering?: 'auto' | 'pixelated' | 'crisp-edges';
+ /** The opacity of the element. (0 to 1) @default 1 */
+ opacity?: number;
+
+ /**
+ * Height off the floor, in pixels.
+ *
+ * @default 0
+ */
+ z?: number;
+ /**
+ * Show the tooltip for the row the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/Raster/Raster.svelte b/packages/webgl/src/lib/components/Raster/Raster.svelte
index 61096e1c0a..963c28a7fa 100644
--- a/packages/webgl/src/lib/components/Raster/Raster.svelte
+++ b/packages/webgl/src/lib/components/Raster/Raster.svelte
@@ -1,176 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Raster/Raster.webgl.svelte b/packages/webgl/src/lib/components/Raster/Raster.webgl.svelte
new file mode 100644
index 0000000000..bee22d288f
--- /dev/null
+++ b/packages/webgl/src/lib/components/Raster/Raster.webgl.svelte
@@ -0,0 +1,164 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Rect/Rect.shared.svelte.ts b/packages/webgl/src/lib/components/Rect/Rect.shared.svelte.ts
new file mode 100644
index 0000000000..dfe6be8fec
--- /dev/null
+++ b/packages/webgl/src/lib/components/Rect/Rect.shared.svelte.ts
@@ -0,0 +1,190 @@
+import type { Corners, Insets } from 'layerchart/utils/rect.svelte';
+import type { MotionOptions } from 'layerchart/utils/motion.svelte';
+import type { ColorProp, DataProp } from 'layerchart';
+import type { MarkEvents } from '../../contexts/scene.svelte.js';
+
+/**
+ * The core `Rect`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`tooltip`)
+ */
+export type RectProps = {
+ /**
+ * The x position of the rectangle (its left edge).
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via xScale
+ * - `function(d)`: accessor called per data item, result passed through xScale
+ *
+ * @default 0
+ */
+ x?: DataProp;
+ /**
+ * The initial x position (pixel mode only), as it eases in with `motion`.
+ *
+ * @default x
+ */
+ initialX?: number;
+ /**
+ * The y position of the rectangle (its top edge: its far side, before the view turns).
+ * - `number`: pixel value (direct)
+ * - `string`: data property name, resolved via yScale
+ * - `function(d)`: accessor called per data item, result passed through yScale
+ *
+ * @default 0
+ */
+ y?: DataProp;
+ /**
+ * The initial y position (pixel mode only), as it eases in with `motion`.
+ *
+ * @default y
+ */
+ initialY?: number;
+ /**
+ * The width of the rectangle (pixels): a number, data property name, or function of the row.
+ *
+ * @default 0
+ */
+ width?: DataProp;
+ /** The initial width (pixel mode only), as it eases in with `motion` */
+ initialWidth?: number;
+ /**
+ * The height of the rectangle (pixels, down `y`): a number, data property name, or function of
+ * the row.
+ *
+ * @default 0
+ */
+ height?: DataProp;
+ /** The initial height (pixel mode only), as it eases in with `motion` */
+ initialHeight?: number;
+ /**
+ * Left/start x edge (data mode).
+ * - `string`: data property name, resolved via xScale
+ * - `function(d)`: accessor called per data item, result passed through xScale
+ * - `number`: pixel value
+ */
+ x0?: DataProp;
+ /**
+ * Right/end x edge (data mode).
+ * - `string`: data property name, resolved via xScale
+ * - `function(d)`: accessor called per data item, result passed through xScale
+ * - `number`: pixel value
+ */
+ x1?: DataProp;
+ /**
+ * Top/start y edge (data mode).
+ * - `string`: data property name, resolved via yScale
+ * - `function(d)`: accessor called per data item, result passed through yScale
+ * - `number`: pixel value
+ */
+ y0?: DataProp;
+ /**
+ * Bottom/end y edge (data mode).
+ * - `string`: data property name, resolved via yScale
+ * - `function(d)`: accessor called per data item, result passed through yScale
+ * - `number`: pixel value
+ */
+ y1?: DataProp;
+ /**
+ * Height to raise the rectangle into a box, defaulting to the chart's `z` in data mode (else a
+ * thin tile).
+ * - `string`: data property name, resolved via zScale
+ * - `function(d)`: accessor called per data item, result passed through zScale (or returning
+ * `[start, end]` to float the box between them)
+ * - `number`: pixel height (also in pixel mode)
+ * - `[start, end]`: pixel heights to float the box between
+ */
+ z?: DataProp | [start: number, end: number];
+ /**
+ * Whether a box raised by `z` shades its sides, by the scene's lights. Without, each face is
+ * its own color, unlit.
+ *
+ * @default true
+ */
+ shade?: boolean;
+ /**
+ * Insets to shrink the rendered rectangle.
+ * Supports `all`, `x`, `y`, `left`, `right`, `top`, `bottom`.
+ */
+ insets?: Insets;
+ /**
+ * Data array to iterate over in data mode.
+ * Falls back to chart context data when not provided.
+ */
+ data?: any[];
+ /**
+ * Which box each row is as rows change, for `motion`.
+ *
+ * @default (d, i) => i
+ */
+ key?: (d: any, index: number) => unknown;
+ /**
+ * Motion configuration, easing each box to where it's asked to be (ex. `'spring'`, or
+ * `{ type: 'tween', duration: 300 }`)
+ */
+ motion?: MotionOptions;
+ /**
+ * Dashed-border pattern. Accepts a number (single dash length), a
+ * `[dash, gap, ...]` array, or a string (same syntax as SVG
+ * `stroke-dasharray`). Its first dash and gap repeat.
+ */
+ dashArray?: number | number[] | string;
+ /**
+ * Per-corner radii, rounding a flat rect. Accepts a number (all corners equal — same as `rx`),
+ * a `[tl, tr, br, bl]` tuple, or `{ topLeft, topRight, bottomRight, bottomLeft }`.
+ * Takes precedence over `rx`.
+ */
+ corners?: Corners;
+ /**
+ * The fill color: a CSS color, or a key / function of the row run through the chart's color
+ * scale. `none` draws only its outline.
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ fill?: ColorProp;
+ /** The fill opacity (0 to 1). @default 1 */
+ fillOpacity?: number;
+ /**
+ * The stroke color, as the core isometric boxes draw theirs: around each box's top and up its
+ * corners (ex. lines between a treemap's siblings). A CSS color, or a key / function of the
+ * row run through the color scale. None without one (here or in `class`).
+ */
+ stroke?: ColorProp;
+ /** The stroke width in pixels, the same at any depth. @default 1 */
+ strokeWidth?: number;
+ /** The stroke opacity (0 to 1). @default 1 */
+ strokeOpacity?: number;
+ /** The opacity (0 to 1). @default 1 */
+ opacity?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+ /**
+ * Inline CSS, as on the core marks' elements (ex. `--fill-color: var(--color-primary)`): the
+ * colors it sets, as LayerChart's styles read them
+ */
+ style?: string;
+ /** Corner radius in pixels, rounding a flat rect. @default 0 */
+ rx?: number;
+ /** Click event handler, called with the box's row (`{ data }`, none in pixel mode) */
+ onclick?: MarkEvents['onclick'];
+ /** Double click event handler, called with the box's row */
+ ondblclick?: MarkEvents['ondblclick'];
+ /** Pointer enter event handler, called with the box's row */
+ onpointerenter?: MarkEvents['onpointerenter'];
+ /** Pointer move event handler, called with the box's row */
+ onpointermove?: MarkEvents['onpointermove'];
+ /** Pointer leave event handler, called with the box's row */
+ onpointerleave?: MarkEvents['onpointerleave'];
+ /** Pointer over event handler, called with the box's row */
+ onpointerover?: MarkEvents['onpointerover'];
+ /** Pointer out event handler, called with the box's row */
+ onpointerout?: MarkEvents['onpointerout'];
+
+ /**
+ * Show the tooltip for the row the pointer is over (with the chart's `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/Rect/Rect.svelte b/packages/webgl/src/lib/components/Rect/Rect.svelte
index 8db4ebff79..4a951e8691 100644
--- a/packages/webgl/src/lib/components/Rect/Rect.svelte
+++ b/packages/webgl/src/lib/components/Rect/Rect.svelte
@@ -1,176 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Rect/Rect.webgl.svelte b/packages/webgl/src/lib/components/Rect/Rect.webgl.svelte
new file mode 100644
index 0000000000..94e00c7475
--- /dev/null
+++ b/packages/webgl/src/lib/components/Rect/Rect.webgl.svelte
@@ -0,0 +1,282 @@
+
+
+
+
+{#if roundedRects}
+ (outlined ? strokeOf(d) : null)}
+ {strokeWidth}
+ opacity={fillAlpha}
+ lineOpacity={strokeAlpha}
+ tooltip={tooltip && dataMode}
+ {events}
+ {dashArray}
+ />
+{/if}
diff --git a/packages/webgl/src/lib/components/RectClipPath/RectClipPath.svelte b/packages/webgl/src/lib/components/RectClipPath/RectClipPath.svelte
new file mode 100644
index 0000000000..6acb09a9c8
--- /dev/null
+++ b/packages/webgl/src/lib/components/RectClipPath/RectClipPath.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/RectClipPath/RectClipPath.webgl.svelte b/packages/webgl/src/lib/components/RectClipPath/RectClipPath.webgl.svelte
new file mode 100644
index 0000000000..d8f422067c
--- /dev/null
+++ b/packages/webgl/src/lib/components/RectClipPath/RectClipPath.webgl.svelte
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Ribbon/Ribbon.shared.svelte.ts b/packages/webgl/src/lib/components/Ribbon/Ribbon.shared.svelte.ts
new file mode 100644
index 0000000000..25e455f14d
--- /dev/null
+++ b/packages/webgl/src/lib/components/Ribbon/Ribbon.shared.svelte.ts
@@ -0,0 +1 @@
+export type { RibbonProps } from 'layerchart/graph';
diff --git a/packages/webgl/src/lib/components/Ribbon/Ribbon.svelte b/packages/webgl/src/lib/components/Ribbon/Ribbon.svelte
new file mode 100644
index 0000000000..23876a3bbe
--- /dev/null
+++ b/packages/webgl/src/lib/components/Ribbon/Ribbon.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Ribbon/Ribbon.webgl.svelte b/packages/webgl/src/lib/components/Ribbon/Ribbon.webgl.svelte
new file mode 100644
index 0000000000..05d0d6e387
--- /dev/null
+++ b/packages/webgl/src/lib/components/Ribbon/Ribbon.webgl.svelte
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Rule/Rule.shared.svelte.ts b/packages/webgl/src/lib/components/Rule/Rule.shared.svelte.ts
new file mode 100644
index 0000000000..3779a87ffa
--- /dev/null
+++ b/packages/webgl/src/lib/components/Rule/Rule.shared.svelte.ts
@@ -0,0 +1,61 @@
+import type { Accessor } from 'layerchart';
+
+/**
+ * The core `Rule`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`z`, and its line's look)
+ */
+export type RuleProps = {
+ /** Override the data from the context */
+ data?: any[];
+ /**
+ * Create a vertical `x` line
+ * - If true or '$left', will draw at chart left (xRange[0])
+ * - If '$right', will draw at chart right (xRange[1])
+ * - Use number | Date value for annotation (xScale(value))
+ * - Use an accessor for a line per row
+ *
+ * @default false
+ */
+ x?: number | Date | boolean | '$left' | '$right' | Accessor;
+ /** Pixel offset to apply to `x` coordinate. @default 0 */
+ xOffset?: number;
+ /**
+ * Create a horizontal `y` line
+ * - If true or '$bottom', will draw at chart bottom (yRange[0])
+ * - If '$top', will draw at chart top (yRange[1])
+ * - Use number | Date value for annotation (yScale(value))
+ * - Use an accessor for a line per row
+ *
+ * @default false
+ */
+ y?: number | Date | boolean | '$top' | '$bottom' | Accessor;
+ /** Pixel offset to apply to `y` coordinate. @default 0 */
+ yOffset?: number;
+ /**
+ * Series key to follow, fading the rule while another series is highlighted and removing it
+ * while the series is hidden. Only applicable if `` uses `series`.
+ */
+ seriesKey?: string;
+
+ /** Pixels up off the floor to draw at. @default 0 */
+ z?: number;
+ /**
+ * The line's CSS color. Rows' lines take the chart's color scale (`c`) without one.
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ stroke?: string;
+ /**
+ * Width in pixels, the same at any depth.
+ *
+ * @default 1
+ */
+ strokeWidth?: number;
+ /** @default 1 */
+ opacity?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `stroke-red-500`): the
+ * stroke, stroke width, and opacity they set, where its props don't say
+ */
+ class?: string;
+};
diff --git a/packages/webgl/src/lib/components/Rule/Rule.svelte b/packages/webgl/src/lib/components/Rule/Rule.svelte
index 49db540bed..0971bf2dc3 100644
--- a/packages/webgl/src/lib/components/Rule/Rule.svelte
+++ b/packages/webgl/src/lib/components/Rule/Rule.svelte
@@ -1,167 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Rule/Rule.webgl.svelte b/packages/webgl/src/lib/components/Rule/Rule.webgl.svelte
new file mode 100644
index 0000000000..9ce1997d3b
--- /dev/null
+++ b/packages/webgl/src/lib/components/Rule/Rule.webgl.svelte
@@ -0,0 +1,141 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Spline/Spline.fill.svelte b/packages/webgl/src/lib/components/Spline/Spline.fill.svelte
new file mode 100644
index 0000000000..8675b8f50e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Spline/Spline.fill.svelte
@@ -0,0 +1,35 @@
+
+
diff --git a/packages/webgl/src/lib/components/Spline/Spline.shared.svelte.ts b/packages/webgl/src/lib/components/Spline/Spline.shared.svelte.ts
new file mode 100644
index 0000000000..22ee3ad473
--- /dev/null
+++ b/packages/webgl/src/lib/components/Spline/Spline.shared.svelte.ts
@@ -0,0 +1,119 @@
+import type { Snippet } from 'svelte';
+import type { draw as drawTransition } from 'svelte/transition';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+import type { Accessor, ColorProp, DataProp, StyleProp } from 'layerchart';
+import type { CurveFactory } from 'd3-shape';
+import type { MarkerOptions } from '../Line/markers.js';
+
+/**
+ * The core `Spline`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`tooltip`)
+ */
+export type SplineProps = {
+ /** Override data instead of using context */
+ data?: any[];
+ /**
+ * Height off the floor: a data key or function (through the chart's `z` scale), or a number
+ * of pixels. Defaults to the chart's `z`.
+ */
+ z?: DataProp;
+ /** Override `x` accessor from Chart context */
+ x?: Accessor;
+ /** Override `y` accessor from Chart context */
+ y?: Accessor;
+ /**
+ * Draw one line per distinct value, in data order. Defaults to the chart's `g`, else the
+ * categorical data key `stroke` names, else the chart's `c` (as the core `Spline`). A numeric
+ * key (`stroke="z"`) colors along the line instead.
+ */
+ g?: Accessor;
+ /**
+ * Series key to use for accessor. Only applicable if `` uses `series` and `x`/`y` are
+ * not set.
+ */
+ seriesKey?: string;
+ /** Whether a row is drawn: a line breaks at rows it isn't, as the core `Spline` does */
+ defined?: (d: any, index: number, data: any[]) => boolean;
+ /**
+ * Curve of path drawn. Imported via d3-shape (ex. `curveMonotoneX`). Straight between rows
+ * without one.
+ */
+ curve?: CurveFactory;
+ /**
+ * A CSS color, or a data key / function run through the chart's color scale — per row, so a
+ * line can change color along its length. Defaults to the chart's `c`, else its series'
+ * color, else `var(--color-primary)`.
+ */
+ stroke?: ColorProp;
+ /**
+ * A CSS color to fill the shape each line closes around, as an SVG path fills an open line (ex.
+ * a `Hull`'s). None without one (here or in `class`).
+ */
+ fill?: string | null;
+ /**
+ * Opacity, or a function returning it per row: a line splits into a piece per run of rows
+ * it gives the same, as the core `Spline`'s. @default 1
+ */
+ opacity?: StyleProp;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `fill-red-500 opacity-50`):
+ * the fill, stroke, stroke width, dashes, and opacity they set, where its props don't say. Or a
+ * function returning them per row, splitting a line into a piece per run of rows it gives the
+ * same (ex. dashed across missing data), as the core `Spline`'s.
+ */
+ class?: StyleProp;
+ /**
+ * Tween each line to where it's asked to be, as the core `Spline` (ex. `'tween'`, or `{ type:
+ * 'tween', duration: 300 }`), a new one up from the baseline. A spring leaves it, as core's.
+ */
+ motion?: MotionProp;
+
+ /**
+ * Pass ` ` explicitly, drawn in place of the line its rows make: SVG path data in
+ * the chart's pixels, as the core `Path` draws it
+ */
+ pathData?: string | null | (() => string | null | undefined);
+ /**
+ * Whether to animate the drawing of the path over time. Pass either `true` or an object with
+ * transition options (`duration`, `delay`, `speed`, `easing`) to enable the transition. Each
+ * line is drawn from its start, again as its rows change.
+ *
+ * Works best with `tweened` disabled.
+ */
+ draw?: boolean | Parameters[1];
+ /**
+ * Marker to attach to both start and end points of the line: drawn flat on the floor, turned
+ * along the line, in its stroke color
+ */
+ marker?: MarkerOptions;
+ /** Marker to attach to the middle point of the line (each row between its ends) */
+ markerMid?: MarkerOptions;
+ /** Marker to attach to the start point of the line */
+ markerStart?: MarkerOptions;
+ /** Marker to attach to the end point of the line */
+ markerEnd?: MarkerOptions;
+ /**
+ * Add additional content at the start of the line (one per line).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ startContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /**
+ * Add additional content at the end of the line (following it as `draw` draws it).
+ * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
+ */
+ endContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
+ /** The fill opacity of the element. @default 1 */
+ fillOpacity?: number;
+ /** The stroke opacity of the element. (0 to 1) @default 1 */
+ strokeOpacity?: number;
+ /** Line width in pixels, the same at any depth. @default 1 */
+ strokeWidth?: number;
+
+ /**
+ * Show the tooltip for the row nearest where the pointer is over a line (with the chart's
+ * `tooltipContext`).
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/Spline/Spline.svelte b/packages/webgl/src/lib/components/Spline/Spline.svelte
index 749d9e4dd6..7cb58dc4df 100644
--- a/packages/webgl/src/lib/components/Spline/Spline.svelte
+++ b/packages/webgl/src/lib/components/Spline/Spline.svelte
@@ -1,261 +1,31 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Spline/Spline.webgl.svelte b/packages/webgl/src/lib/components/Spline/Spline.webgl.svelte
new file mode 100644
index 0000000000..9024ca0c90
--- /dev/null
+++ b/packages/webgl/src/lib/components/Spline/Spline.webgl.svelte
@@ -0,0 +1,763 @@
+
+
+
+
+
+{#if pathData != null}
+
+{/if}
+
+{#if pathData == null && (marker || markerStart || markerMid || markerEnd)}
+
+ groups.map((members) => ({
+ // One path through its segments, as the core `Spline`'s
+ points: members.flatMap((i) => drawn[i] ?? lines[i].positions),
+ color: lines[members[0]].colors[0],
+ // Each vertex between its ends (a gap's ends too, as an SVG path's subpaths')
+ get mids() {
+ return vertices(members).slice(1, -1);
+ },
+ }))}
+ strokeWidth={markerWidth}
+ opacity={opacityValue * seriesOpacity * (look?.opacity ?? 1)}
+ />
+{/if}
+
+{#if pathData == null && (startContent || endContent)}
+ {#each groups as members, g (g)}
+ {@const ends = pathEnds(
+ members.map((i) => drawn[i] ?? lines[i].positions),
+ progress[g]
+ )}
+ {#if ends}
+
+ {/if}
+ {/each}
+{/if}
+
+
+{#if fillColor}
+ ({ positions: drawn[i] ?? line.positions, data: line.data }))}
+ fill={fillColor}
+ opacity={opacityValue * fillOpacity * seriesOpacity * (look?.opacity ?? 1)}
+ />
+{/if}
diff --git a/packages/webgl/src/lib/components/Text/Text.shared.svelte.ts b/packages/webgl/src/lib/components/Text/Text.shared.svelte.ts
new file mode 100644
index 0000000000..b05a1a576b
--- /dev/null
+++ b/packages/webgl/src/lib/components/Text/Text.shared.svelte.ts
@@ -0,0 +1,187 @@
+import type { ColorProp, DataProp, TruncateTextOptions } from 'layerchart';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+import type { FormatConfig, FormatType } from '@layerstack/utils';
+import type { ValueProp } from '../../utils/values.js';
+
+/** A run of text in its own style, as the core `Text`'s `segments` take them */
+export type TextSegment = {
+ value: string | number;
+ /** Classes styling this run (ex. `font-bold fill-primary`), over the label's own */
+ class?: string;
+};
+
+/**
+ * The core `Text`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`fontWeight`), and its letters' look
+ */
+export type TextProps = {
+ /**
+ * Text value to render.
+ * - `number`: direct value
+ * - `string`: in data mode, treated as a data property name (e.g. `"label"` → `d.label`);
+ * in pixel mode, used as literal text
+ * - `function(d)`: accessor called per data item to get the text value
+ */
+ value?: string | number | ((d: any) => string | number | null | undefined);
+ /**
+ * Array of styled text segments for inline mixed styling.
+ * Each segment has its own value and optional class (its color, font size, and weight).
+ * Mutually exclusive with `value`.
+ */
+ segments?: TextSegment[];
+ /** Wrap words onto more lines to keep each label within this many pixels */
+ width?: number;
+ /**
+ * Across the plot: a data property name or function of the row through the chart's `x` scale
+ * (longitude on a map), or pixels. Defaults to the chart's `x` with rows.
+ */
+ x?: DataProp;
+ /**
+ * Initial x position of the text (pixel mode only), in pixels, to ease from with `motion`.
+ *
+ * @default x
+ */
+ initialX?: number;
+ /**
+ * Down the plot: a data property name or function of the row through the chart's `y` scale
+ * (latitude on a map), or pixels. Defaults to the chart's `y` with rows.
+ */
+ y?: DataProp;
+ /**
+ * Initial y position of the text (pixel mode only), in pixels, to ease from with `motion`.
+ *
+ * @default y
+ */
+ initialY?: number;
+ /** Pixels to move each label across: on screen with `viewport`, else across the plot */
+ dx?: number;
+ /** Pixels to move each label down: on screen with `viewport`, else down the plot */
+ dy?: number;
+ /** Line spacing of wrapped labels, in multiples of the font size (or `'1.2em'`) */
+ lineHeight?: number | string;
+ /**
+ * Font size in pixels of the plot, for labels lying on the surface, or per row (a data key or
+ * function). When set, `capHeight` defaults to `fontSize * 0.71`.
+ *
+ * @default the chart's (or its `class`'s) font size, as a core label
+ */
+ fontSize?: ValueProp;
+ /**
+ * Cap height of the text — used by vertical anchor math to align the text to its visual
+ * center (as opposed to the font box), for labels lying on the surface: pixels, or `'px'` /
+ * `'em'` (of 16px) as the core `Text` reads it.
+ *
+ * @default '0.71em' (or `fontSize * 0.71` when `fontSize` is set)
+ */
+ capHeight?: string | number;
+ /** Shrink a label lying on the surface to fit `width`, rather than wrapping it */
+ scaleToFit?: boolean;
+ /**
+ * Which end of a label is at its point: its `start`, `middle`, or `end` as it reads. Lying on
+ * the surface, it stays on that side of the point as the view turns.
+ *
+ * @default 'start'
+ */
+ textAnchor?: 'start' | 'middle' | 'end';
+ /**
+ * Which part of a label is at its point, as the core `Text`: its cap height's top (`start`),
+ * its middle (`middle`), or its baseline (`end`).
+ *
+ * @default 'end'
+ */
+ verticalAnchor?: 'start' | 'middle' | 'end';
+ /** Where its baseline sits on `path` (`'hanging'`, `'middle'`, else on it) */
+ dominantBaseline?: string;
+ /**
+ * Which way labels lying on the surface run, in degrees clockwise from left to right across the plot,
+ * or per row (a data key or function).
+ * Turned half round whenever they'd read backwards from where the view is.
+ *
+ * @default 0
+ */
+ rotate?: ValueProp;
+ /**
+ * Keep each label facing the viewer, drawn over the scene upright and crisp however the view
+ * turns (styled with `class`). Otherwise it lies on the surface at its height (ex. the tops
+ * of boxes), turning and tipping with the view, and hidden behind whatever's nearer.
+ *
+ * @default false
+ */
+ viewport?: boolean;
+ /**
+ * Height off the floor: a data property name or function of the row through the chart's `z`
+ * scale, or pixels. Defaults to the chart's `z` with rows, else `0`.
+ */
+ z?: DataProp;
+ /**
+ * How to format a number or date `value` (as the core `format`). When set with `motion` and a
+ * numeric `value`, the number will tween smoothly and be formatted for display.
+ */
+ format?: FormatType | FormatConfig;
+ /**
+ * Ease each label to where it's asked to be, as the core `Text` (ex. `'spring'`, or
+ * `{ type: 'tween', duration: 300 }`), each by its `key`, or each of `x` and `y` by its own
+ * (ex. `{ y: 'spring' }`). A numeric `value` tweens too (pixel mode, with a `{ type }`).
+ */
+ motion?: MotionProp<'x' | 'y'>;
+ /** Shorten each label with an ellipsis to fit `width` (or as the options say) */
+ truncate?: boolean | TruncateTextOptions;
+ /**
+ * SVG path data to place it along, as the core `Text` sets it on a path (ex. from `Arc`'s
+ * `getArcTextProps('outer')`): at `startOffset`, turned the way the path runs there (straight,
+ * rather than bent along it)
+ */
+ path?: string;
+ /** How far along `path`: pixels, or a percentage of its length (ex. `'50%'`). @default 0 */
+ startOffset?: string | number;
+ /** Rows to draw a label each for. Falls back to the chart's data when `x` / `y` read rows. */
+ data?: any[];
+ /**
+ * Which label each row is as rows change, for `motion`.
+ *
+ * @default (d, i) => i
+ */
+ key?: (d: any, index: number) => unknown;
+
+ /**
+ * Font weight, for labels lying on the surface.
+ *
+ * @default the chart's (or its `class`'s) font weight, as a core label
+ */
+ fontWeight?: number | string;
+ /**
+ * The labels' color: a CSS color, or a data key / function run through the chart's color
+ * scale. `viewport` labels without one take their color from `class`.
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ fill?: ColorProp;
+ /**
+ * A halo around the letters, behind them, as the core `Text` draws its stroke (ex. to read
+ * over a busy surface): a CSS color, or a data key / function run through the chart's color
+ * scale. None without one.
+ */
+ stroke?: ColorProp;
+ /** The halo's width in pixels, half of it outside the letters. @default 1 */
+ strokeWidth?: number;
+ /**
+ * The fill opacity (0 to 1).
+ * - `number`: static value
+ * - `function(d)`: accessor called per data item
+ */
+ fillOpacity?: number | ((d: any) => number | undefined);
+ /**
+ * The stroke opacity (0 to 1): its halo's.
+ * - `number`: static value
+ * - `function(d)`: accessor called per data item
+ */
+ strokeOpacity?: number | ((d: any) => number | undefined);
+ /**
+ * The opacity (0 to 1): of the whole label, its halo and letters together.
+ * - `number`: static value
+ * - `function(d)`: accessor called per data item
+ */
+ opacity?: number | ((d: any) => number | undefined);
+ /** Class added to each `viewport` label */
+ class?: string;
+};
diff --git a/packages/webgl/src/lib/components/Text/Text.svelte b/packages/webgl/src/lib/components/Text/Text.svelte
index 3e1530ed15..35c098561d 100644
--- a/packages/webgl/src/lib/components/Text/Text.svelte
+++ b/packages/webgl/src/lib/components/Text/Text.svelte
@@ -1,344 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Text/Text.webgl.svelte b/packages/webgl/src/lib/components/Text/Text.webgl.svelte
new file mode 100644
index 0000000000..b10cc0a1b3
--- /dev/null
+++ b/packages/webgl/src/lib/components/Text/Text.webgl.svelte
@@ -0,0 +1,586 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Trail/Trail.shared.svelte.ts b/packages/webgl/src/lib/components/Trail/Trail.shared.svelte.ts
new file mode 100644
index 0000000000..ee236e1551
--- /dev/null
+++ b/packages/webgl/src/lib/components/Trail/Trail.shared.svelte.ts
@@ -0,0 +1 @@
+export type { TrailProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Trail/Trail.svelte b/packages/webgl/src/lib/components/Trail/Trail.svelte
new file mode 100644
index 0000000000..bd07104a78
--- /dev/null
+++ b/packages/webgl/src/lib/components/Trail/Trail.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Trail/Trail.webgl.svelte b/packages/webgl/src/lib/components/Trail/Trail.webgl.svelte
new file mode 100644
index 0000000000..b26fcade1a
--- /dev/null
+++ b/packages/webgl/src/lib/components/Trail/Trail.webgl.svelte
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Vector/Vector.shared.svelte.ts b/packages/webgl/src/lib/components/Vector/Vector.shared.svelte.ts
new file mode 100644
index 0000000000..c5aecdf936
--- /dev/null
+++ b/packages/webgl/src/lib/components/Vector/Vector.shared.svelte.ts
@@ -0,0 +1,111 @@
+import type { ColorProp, DataProp, StyleProp } from 'layerchart';
+import type { MotionProp } from 'layerchart/utils/motion.svelte';
+
+/**
+ * The core `Vector`'s props (in its order, as it describes them), then those of a `WebGL` layer's
+ * own (`tilt`, `z`, `tooltip`)
+ */
+export type VectorProps = {
+ /**
+ * Where it's anchored across: a data property name or function of the row through the chart's
+ * `x` scale (or longitude, through its projection), or pixels.
+ *
+ * @default 0
+ */
+ x?: DataProp;
+ /** Where a vector placed by pixels eases across from with `motion`. @default x */
+ initialX?: number;
+ /**
+ * Where it's anchored down: a data property name or function of the row through the chart's
+ * `y` scale (or latitude, through its projection), or pixels.
+ *
+ * @default 0
+ */
+ y?: DataProp;
+ /** Where it eases down from, as `initialX`. @default y */
+ initialY?: number;
+ /**
+ * How long: a data property name or function of the row through the chart's `r` scale, or
+ * pixels.
+ *
+ * @default 12
+ */
+ length?: DataProp;
+ /** The length it eases from, as `initialX`. @default length */
+ initialLength?: number;
+ /**
+ * Which way it points, in degrees clockwise from up the plot (its far edge, before the view
+ * turns): a number, data property name, or function of the row.
+ *
+ * @default 0
+ */
+ rotate?: DataProp;
+ /** @default 'arrow' */
+ shape?: 'arrow' | 'arrow-filled' | 'spike';
+ /** Which part of it is at `x` / `y`. Defaults to `'start'` for filled shapes, else `'middle'`. */
+ anchor?: 'start' | 'middle' | 'end';
+ /** Width of the vector shape in pixels. Defaults to a quarter of its length. */
+ width?: number;
+ /** Rows to draw a vector each for. Falls back to the chart's data when the props read rows. */
+ data?: any[];
+ /**
+ * Key function for each row in data mode, which its `motion` eases by.
+ *
+ * @default (d, i) => i
+ */
+ key?: (d: any, index: number) => any;
+ /**
+ * Ease each vector's anchor and length to where they're asked to be (ex. `'tween'`, or per
+ * prop, `{ length: { type: 'spring' } }`): a row at a time by its `key`, and one placed by
+ * pixels from `initialX` ...
+ */
+ motion?: MotionProp;
+ /**
+ * A filled shape's color: a CSS color, or a key / function of the row run through the chart's
+ * color scale
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ fill?: ColorProp;
+ /**
+ * An arrow's color (or a filled shape's outline): a CSS color, or a key / function of the row
+ * run through the chart's color scale
+ *
+ * @default 'var(--color-surface-content)'
+ */
+ stroke?: ColorProp;
+ /** The fill opacity (0 to 1) @default 1 */
+ fillOpacity?: number;
+ /** The stroke opacity (0 to 1) @default 1 */
+ strokeOpacity?: number;
+ /** @default 1 */
+ strokeWidth?: number;
+ /** @default 1 */
+ opacity?: number;
+ /**
+ * CSS classes to style it by, as the core marks take them (ex. `stroke-red-500`): the
+ * fill, stroke, stroke width, and opacity they set, where its props don't say. A string, or a
+ * function of the row returning one.
+ */
+ class?: StyleProp;
+
+ /**
+ * In a 3D view, how far it points up out of the floor, in degrees: `0` along the floor, `90`
+ * straight up, `-90` straight down. A number, data property name, or function of the row.
+ *
+ * @default 0
+ */
+ tilt?: DataProp;
+ /**
+ * Where it's anchored up off the floor: a data property name or function of the row through
+ * the chart's `z` scale, or pixels. On the floor without one.
+ */
+ z?: DataProp;
+ /**
+ * Show the tooltip for the row the pointer is over (with the chart's `tooltipContext`). Only
+ * filled shapes can be picked.
+ *
+ * @default false
+ */
+ tooltip?: boolean;
+};
diff --git a/packages/webgl/src/lib/components/Vector/Vector.svelte b/packages/webgl/src/lib/components/Vector/Vector.svelte
index 7601afab4f..56feae9a86 100644
--- a/packages/webgl/src/lib/components/Vector/Vector.svelte
+++ b/packages/webgl/src/lib/components/Vector/Vector.svelte
@@ -1,268 +1,24 @@
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Vector/Vector.webgl.svelte b/packages/webgl/src/lib/components/Vector/Vector.webgl.svelte
new file mode 100644
index 0000000000..547934db3d
--- /dev/null
+++ b/packages/webgl/src/lib/components/Vector/Vector.webgl.svelte
@@ -0,0 +1,248 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/Violin/Violin.shared.svelte.ts b/packages/webgl/src/lib/components/Violin/Violin.shared.svelte.ts
new file mode 100644
index 0000000000..4db3b53ef0
--- /dev/null
+++ b/packages/webgl/src/lib/components/Violin/Violin.shared.svelte.ts
@@ -0,0 +1 @@
+export type { ViolinProps } from 'layerchart';
diff --git a/packages/webgl/src/lib/components/Violin/Violin.svelte b/packages/webgl/src/lib/components/Violin/Violin.svelte
new file mode 100644
index 0000000000..2c37f051d6
--- /dev/null
+++ b/packages/webgl/src/lib/components/Violin/Violin.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Violin/Violin.webgl.svelte b/packages/webgl/src/lib/components/Violin/Violin.webgl.svelte
new file mode 100644
index 0000000000..57e5607cf4
--- /dev/null
+++ b/packages/webgl/src/lib/components/Violin/Violin.webgl.svelte
@@ -0,0 +1,16 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Voronoi/Voronoi.svelte b/packages/webgl/src/lib/components/Voronoi/Voronoi.svelte
new file mode 100644
index 0000000000..691e0e854e
--- /dev/null
+++ b/packages/webgl/src/lib/components/Voronoi/Voronoi.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Voronoi/Voronoi.webgl.svelte b/packages/webgl/src/lib/components/Voronoi/Voronoi.webgl.svelte
new file mode 100644
index 0000000000..fea59730e0
--- /dev/null
+++ b/packages/webgl/src/lib/components/Voronoi/Voronoi.webgl.svelte
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/packages/webgl/src/lib/components/Waffle/Waffle.svelte b/packages/webgl/src/lib/components/Waffle/Waffle.svelte
new file mode 100644
index 0000000000..826b3944b5
--- /dev/null
+++ b/packages/webgl/src/lib/components/Waffle/Waffle.svelte
@@ -0,0 +1,20 @@
+
+
+
+
+{#if inScene}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/Waffle/Waffle.webgl.svelte b/packages/webgl/src/lib/components/Waffle/Waffle.webgl.svelte
new file mode 100644
index 0000000000..194c396569
--- /dev/null
+++ b/packages/webgl/src/lib/components/Waffle/Waffle.webgl.svelte
@@ -0,0 +1,251 @@
+
+
+
+
+
+{#if rounded}
+ {
+ const r = (bar as Instance & { radius: number }).radius;
+ return [r, r, r, r];
+ }}
+ height={0.1}
+ stroke={() => null}
+ strokeWidth={0}
+ opacity={fillAlpha}
+ tooltip={!!tooltip}
+ {events}
+ />
+{/if}
diff --git a/packages/webgl/src/lib/components/__fixtures__/AxisGrid.svelte b/packages/webgl/src/lib/components/__fixtures__/AxisGrid.svelte
new file mode 100644
index 0000000000..481880453a
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/AxisGrid.svelte
@@ -0,0 +1,45 @@
+
+
+{#snippet marks()}
+ {#each axes as axis, i (i)}
+
+ {/each}
+ {#if grid}
+
+ {/if}
+{/snippet}
+
+
+
+
+
+ {#if center}
+ {@render marks()}
+ {:else}
+ {@render marks()}
+ {/if}
+
+
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/Clips.svelte b/packages/webgl/src/lib/components/__fixtures__/Clips.svelte
new file mode 100644
index 0000000000..55049627a7
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/Clips.svelte
@@ -0,0 +1,138 @@
+
+
+{#snippet fill()}
+
+
+{/snippet}
+
+
+
+ {#snippet children({ context }: { context: ChartState })}
+
+ {#if clip === 'rect'}
+
+ {@render fill()}
+
+ {:else if clip === 'circle'}
+
+ {@render fill()}
+
+ {:else if clip === 'path'}
+
+
+ {@render fill()}
+
+ {:else if clip === 'snippet'}
+
+
+ {#snippet clip()}
+
+
+ {/snippet}
+ {@render fill()}
+
+ {:else if clip === 'elements'}
+
+
+ {#snippet clip()}
+
+
+
+
+ {/snippet}
+ {@render fill()}
+
+ {:else if clip === 'geo'}
+
+ {@render fill()}
+
+ {:else if clip === 'chart'}
+
+ {@render fill()}
+
+ {:else if clip === 'crossing'}
+
+ 0}
+ fill="red"
+ line={false}
+ />
+ {:else if clip === 'labels'}
+
+
+
+
+
+ {/if}
+
+
+ {/snippet}
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/Components8.svelte b/packages/webgl/src/lib/components/__fixtures__/Components8.svelte
new file mode 100644
index 0000000000..90386f8f4d
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/Components8.svelte
@@ -0,0 +1,69 @@
+
+
+
+ {#if mark === 'waffle'}
+
+
+
+
+
+
+ {:else if mark === 'geobin'}
+
+
+
+
+
+
+ {:else}
+
+
+
+ {#if mark === 'ellipse'}
+
+ {:else if mark === 'image'}
+
+ {:else}
+
+ {/if}
+
+
+ {/if}
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/Geo2.svelte b/packages/webgl/src/lib/components/__fixtures__/Geo2.svelte
new file mode 100644
index 0000000000..797f05b213
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/Geo2.svelte
@@ -0,0 +1,67 @@
+
+
+
+
+
+ {#if mark === 'geopoint'}
+
+ {:else if mark === 'geopoint-children'}
+
+
+
+
+ {:else if mark === 'hull'}
+
+ {:else if mark === 'geopath'}
+
+ {:else if mark === 'vector'}
+
+ {:else if mark === 'circle'}
+
+ {:else if mark === 'points'}
+
+ {/if}
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/Lines.svelte b/packages/webgl/src/lib/components/__fixtures__/Lines.svelte
new file mode 100644
index 0000000000..20f27095fa
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/Lines.svelte
@@ -0,0 +1,64 @@
+
+
+{#snippet start(props: { point: DOMPoint; value: any })}
+ {onContent?.('start', props)}
+{/snippet}
+{#snippet end(props: { point: DOMPoint; value: any })}
+ {onContent?.('end', props)}
+{/snippet}
+
+
+
+
+ {#if mark === 'line'}
+
+ {:else if mark === 'path'}
+
+ {:else if mark === 'link'}
+
+ {:else if mark === 'polygon'}
+
+ {:else if mark === 'vector'}
+
+ {:else if mark === 'graticule'}
+
+ {/if}
+
+
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/Marks.svelte b/packages/webgl/src/lib/components/__fixtures__/Marks.svelte
index bb7448fdb0..7a796a6da7 100644
--- a/packages/webgl/src/lib/components/__fixtures__/Marks.svelte
+++ b/packages/webgl/src/lib/components/__fixtures__/Marks.svelte
@@ -7,6 +7,7 @@
Axis,
Bars,
Bin,
+ Circle,
Chart,
Contour,
GeoPath,
@@ -36,6 +37,7 @@
surface,
geopath,
bin,
+ circle,
light,
text,
rect,
@@ -60,6 +62,7 @@
| 'geopath'
| 'light'
| 'bin'
+ | 'circle'
| 'text'
| 'rect'
| 'link'
@@ -80,6 +83,7 @@
surface?: ComponentProps;
geopath?: ComponentProps;
bin?: ComponentProps;
+ circle?: ComponentProps;
light?: ComponentProps;
text?: ComponentProps;
rect?: ComponentProps;
@@ -113,6 +117,8 @@
{:else if mark === 'bin'}
+ {:else if mark === 'circle'}
+
{:else if mark === 'text'}
{:else if mark === 'rect'}
diff --git a/packages/webgl/src/lib/components/__fixtures__/Paints.svelte b/packages/webgl/src/lib/components/__fixtures__/Paints.svelte
new file mode 100644
index 0000000000..38bb84cee6
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/Paints.svelte
@@ -0,0 +1,60 @@
+
+
+
+
+
+ {#if mark === 'plain-rect'}
+
+ {:else if mark === 'pattern'}
+
+ {#snippet children({ pattern })}
+
+ {/snippet}
+
+ {:else}
+
+ {#snippet children({ gradient })}
+ {#if mark === 'rect'}
+
+ {:else if mark === 'area'}
+
+ {:else}
+
+ {/if}
+ {/snippet}
+
+ {/if}
+
+
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/ParityScales.svelte b/packages/webgl/src/lib/components/__fixtures__/ParityScales.svelte
new file mode 100644
index 0000000000..851a287199
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/ParityScales.svelte
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+ {#if mark === 'grid'}
+
+ {:else if mark === 'raster'}
+
+ {:else if mark === 'georaster' && georaster}
+
+ {/if}
+
+
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/Paths.svelte b/packages/webgl/src/lib/components/__fixtures__/Paths.svelte
new file mode 100644
index 0000000000..96741faacd
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/Paths.svelte
@@ -0,0 +1,58 @@
+
+
+{#snippet start(props: { point: DOMPoint; value: any })}
+ {onContent?.('start', props)}
+{/snippet}
+{#snippet end(props: { point: DOMPoint; value: any })}
+ {onContent?.('end', props)}
+{/snippet}
+
+
+
+
+ {#if mark === 'spline'}
+
+ {:else if mark === 'area'}
+
+ {:else if mark === 'link'}
+
+ {:else if mark === 'geoPath'}
+
+ {:else if mark === 'graticule'}
+
+ {/if}
+
+
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/SimplifiedChart.svelte b/packages/webgl/src/lib/components/__fixtures__/SimplifiedChart.svelte
new file mode 100644
index 0000000000..af217591f4
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/SimplifiedChart.svelte
@@ -0,0 +1,24 @@
+
+
+
+ {#if chart === 'bar'}
+
+ {:else if chart === 'line'}
+
+ {:else}
+
+ {/if}
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/SplineArea.svelte b/packages/webgl/src/lib/components/__fixtures__/SplineArea.svelte
new file mode 100644
index 0000000000..03cee76795
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/SplineArea.svelte
@@ -0,0 +1,43 @@
+
+
+
+
+
+ {#if area}
+
+ {/if}
+ {#if spline}
+
+ {/if}
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/__fixtures__/ThrelteProbe.svelte b/packages/webgl/src/lib/components/__fixtures__/ThrelteProbe.svelte
new file mode 100644
index 0000000000..2f45a6663f
--- /dev/null
+++ b/packages/webgl/src/lib/components/__fixtures__/ThrelteProbe.svelte
@@ -0,0 +1,26 @@
+
diff --git a/packages/webgl/src/lib/components/charts.svelte.test.ts b/packages/webgl/src/lib/components/charts.svelte.test.ts
new file mode 100644
index 0000000000..65558f8704
--- /dev/null
+++ b/packages/webgl/src/lib/components/charts.svelte.test.ts
@@ -0,0 +1,20 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+
+import SimplifiedChart from './__fixtures__/SimplifiedChart.svelte';
+
+describe('simplified charts', () => {
+ it.each(['bar', 'line', 'pie'] as const)(
+ 'draws a %s chart, its axes and marks, in a WebGL layer',
+ async (chart) => {
+ const { container } = render(SimplifiedChart, { chart });
+ // A WebGL canvas, and none of LayerChart's SVG or Canvas layers drawing in its place
+ await expect
+ .poll(() => [...container.querySelectorAll('canvas')].some((c) => !c.getContext('2d')))
+ .toBe(true);
+ // (an `Svg` of the tooltip's hit areas aside, as every layer has)
+ expect(container.querySelector('svg path, svg text')).toBeNull();
+ expect(container.querySelector('.lc-layout-canvas canvas')).toBeNull();
+ }
+ );
+});
diff --git a/packages/webgl/src/lib/components/charts/ArcChart.svelte b/packages/webgl/src/lib/components/charts/ArcChart.svelte
new file mode 100644
index 0000000000..18ed60f135
--- /dev/null
+++ b/packages/webgl/src/lib/components/charts/ArcChart.svelte
@@ -0,0 +1,17 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/charts/AreaChart.svelte b/packages/webgl/src/lib/components/charts/AreaChart.svelte
new file mode 100644
index 0000000000..cc18358115
--- /dev/null
+++ b/packages/webgl/src/lib/components/charts/AreaChart.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/charts/BarChart.svelte b/packages/webgl/src/lib/components/charts/BarChart.svelte
new file mode 100644
index 0000000000..69521ecd8c
--- /dev/null
+++ b/packages/webgl/src/lib/components/charts/BarChart.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/charts/LineChart.svelte b/packages/webgl/src/lib/components/charts/LineChart.svelte
new file mode 100644
index 0000000000..57b7de2aa5
--- /dev/null
+++ b/packages/webgl/src/lib/components/charts/LineChart.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/charts/PieChart.svelte b/packages/webgl/src/lib/components/charts/PieChart.svelte
new file mode 100644
index 0000000000..ef392ee392
--- /dev/null
+++ b/packages/webgl/src/lib/components/charts/PieChart.svelte
@@ -0,0 +1,18 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/charts/ScatterChart.svelte b/packages/webgl/src/lib/components/charts/ScatterChart.svelte
new file mode 100644
index 0000000000..095b1b3ab4
--- /dev/null
+++ b/packages/webgl/src/lib/components/charts/ScatterChart.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/packages/webgl/src/lib/components/clipping-r8.svelte.test.ts b/packages/webgl/src/lib/components/clipping-r8.svelte.test.ts
new file mode 100644
index 0000000000..adf2c0c617
--- /dev/null
+++ b/packages/webgl/src/lib/components/clipping-r8.svelte.test.ts
@@ -0,0 +1,306 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import type { Material, Mesh, Object3D, WebGLRenderer } from 'three';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Clips from './__fixtures__/Clips.svelte';
+
+type Threlte = { scene: SceneState; render: () => void; renderer: WebGLRenderer };
+
+/** Render a clip around a red rectangle filling the plot (and past it) */
+async function renderClip(props: Omit>[1], 'onThrelte'>) {
+ let threlte: Threlte | undefined;
+ render(Clips, { ...(props as any), onThrelte: (t: Threlte) => (threlte = t) });
+ await expect.poll(() => meshes(threlte?.scene).length).toBeGreaterThan(0);
+ return threlte!;
+}
+
+function meshes(scene: SceneState | undefined) {
+ const found: Mesh[] = [];
+ scene?.root.traverse((o: Object3D) => {
+ if ((o as Mesh).isMesh) found.push(o as Mesh);
+ });
+ return found;
+}
+
+/**
+ * Whether the frame is painted at points of the chart (pixels across and down its 400 × 300),
+ * drawn now and read before the browser shows it
+ */
+function painted(threlte: Threlte, points: [number, number][]) {
+ threlte.render();
+ const gl = threlte.renderer.getContext();
+ const k = gl.drawingBufferWidth / 400;
+ return points.map(([x, y]) => {
+ const pixel = new Uint8Array(4);
+ gl.readPixels(
+ Math.round(x * k),
+ Math.round(gl.drawingBufferHeight - y * k),
+ 1,
+ 1,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ pixel
+ );
+ return pixel[3] > 128;
+ });
+}
+
+/** Painted where expected, once the clip's ready (a mask's code loads first) */
+async function expectPainted(threlte: Threlte, points: [number, number][], expected: boolean[]) {
+ await expect.poll(() => painted(threlte, points)).toEqual(expected);
+}
+
+describe('RectClipPath', () => {
+ it('clips to its rectangle with planes', async () => {
+ const threlte = await renderClip({ clip: 'rect' });
+ await expectPainted(
+ threlte,
+ [
+ [50, 50],
+ [150, 50],
+ [50, 150],
+ [300, 250],
+ ],
+ [true, false, false, false]
+ );
+ const material = meshes(threlte.scene)[0].material as Material;
+ expect(material.clippingPlanes).toHaveLength(4);
+ expect(material.userData.lcMask).toBeUndefined();
+ });
+
+ it('draws everything when `disabled`', async () => {
+ const threlte = await renderClip({ clip: 'rect', disabled: true });
+ await expectPainted(
+ threlte,
+ [
+ [50, 50],
+ [300, 250],
+ ],
+ [true, true]
+ );
+ });
+
+ it('draws only outside its rectangle when `invert`', async () => {
+ const threlte = await renderClip({ clip: 'rect', invert: true });
+ await expectPainted(
+ threlte,
+ [
+ [50, 50],
+ [150, 50],
+ [300, 250],
+ ],
+ [false, true, true]
+ );
+ });
+});
+
+describe('CircleClipPath', () => {
+ it('clips to its circle, not its bounds', async () => {
+ const threlte = await renderClip({ clip: 'circle' });
+ // Its center, past its edge, and inside its bounds' corner but outside the circle
+ await expectPainted(
+ threlte,
+ [
+ [200, 150],
+ [260, 150],
+ [240, 190],
+ [20, 20],
+ ],
+ [true, false, false, false]
+ );
+ });
+
+ it('draws only outside its circle when `invert`', async () => {
+ const threlte = await renderClip({ clip: 'circle', invert: true });
+ await expectPainted(
+ threlte,
+ [
+ [200, 150],
+ [240, 190],
+ [20, 20],
+ ],
+ [false, true, true]
+ );
+ });
+});
+
+describe('ClipPath', () => {
+ it('clips to its `path`', async () => {
+ const threlte = await renderClip({ clip: 'path' });
+ await expectPainted(
+ threlte,
+ [
+ [50, 50],
+ [350, 250],
+ [300, 50],
+ [100, 250],
+ ],
+ [true, false, true, false]
+ );
+ });
+});
+
+describe('ClipPath with a `clip` snippet', () => {
+ it('clips to its marks’ shapes, drawing none of them', async () => {
+ const threlte = await renderClip({ clip: 'snippet' });
+ await expectPainted(
+ threlte,
+ [
+ [50, 50],
+ [200, 150],
+ [150, 50],
+ [240, 190],
+ [350, 250],
+ ],
+ [true, true, false, false, false]
+ );
+ // None of its marks in the scene: only what the clipped rectangle draws, as clipped otherwise
+ const shown = meshes(threlte.scene).length;
+ const plain = await renderClip({ clip: 'rect' });
+ expect(shown).toBe(meshes(plain.scene).length);
+ });
+});
+
+describe('ClipPath with SVG elements in its `clip` snippet', () => {
+ it('clips to their shapes', async () => {
+ const threlte = await renderClip({ clip: 'elements' });
+ await expectPainted(
+ threlte,
+ [
+ [50, 50],
+ [200, 150],
+ [150, 50],
+ [240, 190],
+ [350, 250],
+ ],
+ [true, true, false, false, false]
+ );
+ });
+});
+
+describe('GeoClipPath', () => {
+ it('clips to its `geojson`, through the projection (centered on the plot)', async () => {
+ const threlte = await renderClip({ clip: 'geo' });
+ await expectPainted(
+ threlte,
+ [
+ [250, 200],
+ [150, 200],
+ [350, 200],
+ [50, 50],
+ ],
+ [true, false, false, false]
+ );
+ });
+
+ it('draws only outside it when `invert`', async () => {
+ const threlte = await renderClip({ clip: 'geo', invert: true });
+ await expectPainted(
+ threlte,
+ [
+ [250, 200],
+ [150, 200],
+ [350, 200],
+ [50, 50],
+ ],
+ [false, true, true, true]
+ );
+ });
+});
+
+describe('ChartClipPath', () => {
+ const padding = { left: 50, top: 50, right: 50, bottom: 50 };
+
+ it('clips to the plot, though the scene doesn’t', async () => {
+ const threlte = await renderClip({ clip: 'chart', padding });
+ await expectPainted(
+ threlte,
+ [
+ [200, 150],
+ [25, 150],
+ [200, 25],
+ ],
+ [true, false, false]
+ );
+ });
+
+ it('clips to the chart, with its padding, when `full`', async () => {
+ const threlte = await renderClip({ clip: 'chart', padding, full: true });
+ await expectPainted(
+ threlte,
+ [
+ [200, 150],
+ [25, 150],
+ [200, 25],
+ ],
+ [true, true, true]
+ );
+ });
+
+ it('draws everything when `disabled`', async () => {
+ const threlte = await renderClip({ clip: 'chart', padding, disabled: true });
+ await expectPainted(
+ threlte,
+ [
+ [200, 150],
+ [25, 150],
+ ],
+ [true, true]
+ );
+ });
+});
+
+/** Whether any pixel is painted in a box of the chart (`[x0, y0, x1, y1]`), drawn now */
+function paintedIn(threlte: Threlte, [x0, y0, x1, y1]: [number, number, number, number]) {
+ threlte.render();
+ const gl = threlte.renderer.getContext();
+ const k = gl.drawingBufferWidth / 400;
+ const width = Math.round((x1 - x0) * k);
+ const height = Math.round((y1 - y0) * k);
+ const pixels = new Uint8Array(width * height * 4);
+ gl.readPixels(
+ Math.round(x0 * k),
+ Math.round(gl.drawingBufferHeight - y1 * k),
+ width,
+ height,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ pixels
+ );
+ for (let i = 3; i < pixels.length; i += 4) if (pixels[i] > 128) return true;
+ return false;
+}
+
+describe('Clipped labels', () => {
+ it('clips a label sharing its painting with one that isn’t', async () => {
+ const threlte = await renderClip({ clip: 'labels' });
+ // Both labels' planes, each with its own material: one clipped away, the other drawn
+ await expect.poll(() => meshes(threlte.scene).length).toBe(2);
+ await expect
+ .poll(() => [
+ paintedIn(threlte, [90, 100, 300, 160]),
+ paintedIn(threlte, [90, 200, 300, 260]),
+ ])
+ .toEqual([false, true]);
+ const [a, b] = meshes(threlte.scene);
+ expect(a.material).not.toBe(b.material);
+ });
+});
+
+describe('Area', () => {
+ it('fills both sides of its baseline where its line crosses it, not a quad folded over', async () => {
+ const threlte = await renderClip({ clip: 'crossing' });
+ // Its top falls from 10 to -10 across the plot, crossing its zero baseline at the middle
+ await expectPainted(
+ threlte,
+ [
+ [100, 130],
+ [300, 130],
+ [300, 170],
+ [100, 170],
+ ],
+ [true, false, true, false]
+ );
+ });
+});
diff --git a/packages/webgl/src/lib/components/components-r8.svelte.test.ts b/packages/webgl/src/lib/components/components-r8.svelte.test.ts
new file mode 100644
index 0000000000..c389d6e4f6
--- /dev/null
+++ b/packages/webgl/src/lib/components/components-r8.svelte.test.ts
@@ -0,0 +1,201 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { Box3, Matrix4, type BufferGeometry, type InstancedMesh, type Mesh, type Object3D } from 'three';
+import * as core from 'layerchart';
+import type { BrushState, ChartState } from 'layerchart';
+
+import * as webgl from '../index.js';
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Components8 from './__fixtures__/Components8.svelte';
+
+let chart: ChartState | undefined;
+
+async function renderMark(props: Omit>[1], 'onScene'>) {
+ let scene: SceneState | undefined;
+ const result = render(Components8, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return { scene: scene!, result };
+}
+
+function all(scene: SceneState, is: (o: any) => boolean): T[] {
+ const found: T[] = [];
+ scene.root.traverse((o: Object3D) => {
+ if (is(o)) found.push(o as T);
+ });
+ return found;
+}
+
+/** The bounds of the mesh vertices a mark drew, in the chart's pixels (`x` across, `z` down) */
+function drawnBounds(scene: SceneState) {
+ const box = new Box3();
+ for (const mesh of all(scene, (o) => o.isMesh && !o.isInstancedMesh)) {
+ const geometry = mesh.geometry as BufferGeometry;
+ if (!geometry.getAttribute('position')?.count) continue;
+ geometry.computeBoundingBox();
+ box.union(geometry.boundingBox!);
+ }
+ return box;
+}
+
+describe('re-exports', () => {
+ it("hands out LayerChart's contexts and layouts as they are", () => {
+ expect(webgl.ChartGroup).toBe(core.ChartGroup);
+ expect(webgl.Dodge).toBe(core.Dodge);
+ expect(webgl.Point).toBe(core.Point);
+ expect(webgl.Bounds).toBe(core.Bounds);
+ });
+});
+
+describe('Waffle', () => {
+ it('draws a cell for each unit, the last cut short at a fractional value', async () => {
+ const { scene } = await renderMark({
+ mark: 'waffle',
+ data: [{ x: 'a', y: 2.5 }],
+ markProps: { unit: 1, multiple: 1, gap: 0 },
+ });
+ let cells: InstancedMesh[] = [];
+ await expect
+ .poll(() => {
+ cells = all(scene, (o) => o.isInstancedMesh && o.count > 0);
+ return cells[0]?.count ?? 0;
+ })
+ .toBe(3);
+ const depths = [0, 1, 2].map((i) => {
+ const m = new Matrix4();
+ cells[0].getMatrixAt(i, m);
+ // Scaled by each cell's depth (down the plot) along its third column
+ return Math.hypot(m.elements[8], m.elements[9], m.elements[10]);
+ });
+ // 300 pixels for 100 units: 3 pixels a cell, the last half that
+ expect(depths[0]).toBeCloseTo(3, 1);
+ expect(depths[1]).toBeCloseTo(3, 1);
+ expect(depths[2]).toBeCloseTo(1.5, 1);
+ });
+
+ it('draws rounded cells as shapes', async () => {
+ const { scene } = await renderMark({
+ mark: 'waffle',
+ data: [{ x: 'a', y: 4 }],
+ markProps: { unit: 1, multiple: 2, rx: '100%' },
+ });
+ await expect.poll(() => drawnBounds(scene).isEmpty()).toBe(false);
+ expect(all(scene, (o) => o.isInstancedMesh && o.count > 0)).toHaveLength(0);
+ });
+});
+
+describe('GeoBin', () => {
+ it("draws its cells together, in one mesh, each in its cell's color", async () => {
+ const data = [
+ { lon: 0, lat: 0 },
+ { lon: 60, lat: 30 },
+ { lon: -90, lat: -40 },
+ { lon: 120, lat: 10 },
+ ];
+ const { scene } = await renderMark({ mark: 'geobin', data, markProps: { size: 30 } });
+ const filled = () =>
+ all(
+ scene,
+ (o) =>
+ o.isMesh &&
+ !o.isInstancedMesh &&
+ !o.isLineSegments2 &&
+ o.geometry.getAttribute('position')?.count > 0
+ );
+ await expect.poll(() => filled().length).toBe(1);
+ const colors = filled()[0].geometry.getAttribute('color');
+ // Four cells, each its own shape (several vertices each)
+ expect(colors.count).toBeGreaterThanOrEqual(4 * 3);
+ });
+});
+
+describe('Ellipse', () => {
+ it('spans its `rx` across and `ry` down', async () => {
+ const { scene } = await renderMark({
+ mark: 'ellipse',
+ markProps: { cx: 100, cy: 100, rx: 20, ry: 10, fill: 'red' },
+ });
+ await expect.poll(() => drawnBounds(scene).isEmpty()).toBe(false);
+ const box = drawnBounds(scene);
+ expect(box.max.x - box.min.x).toBeCloseTo(40, 0);
+ expect(box.max.z - box.min.z).toBeCloseTo(20, 0);
+ expect((box.min.x + box.max.x) / 2).toBeCloseTo(100, 0);
+ });
+
+ it('turns by `rotate`', async () => {
+ const { scene } = await renderMark({
+ mark: 'ellipse',
+ markProps: { cx: 100, cy: 100, rx: 20, ry: 10, rotate: 90, fill: 'red' },
+ });
+ await expect.poll(() => drawnBounds(scene).isEmpty()).toBe(false);
+ const box = drawnBounds(scene);
+ expect(box.max.x - box.min.x).toBeCloseTo(20, 0);
+ expect(box.max.z - box.min.z).toBeCloseTo(40, 0);
+ });
+});
+
+/** A 2 × 1 image */
+function wideImage() {
+ const canvas = document.createElement('canvas');
+ canvas.width = 20;
+ canvas.height = 10;
+ const context = canvas.getContext('2d')!;
+ context.fillStyle = 'red';
+ context.fillRect(0, 0, 20, 10);
+ return canvas.toDataURL();
+}
+
+describe('Image', () => {
+ it('fits the image in its box, as `preserveAspectRatio="xMidYMid meet"`', async () => {
+ const { scene } = await renderMark({
+ mark: 'image',
+ markProps: { href: wideImage(), x: 100, y: 100, width: 40, height: 40 },
+ });
+ await expect.poll(() => drawnBounds(scene).isEmpty()).toBe(false);
+ const box = drawnBounds(scene);
+ expect(box.max.x - box.min.x).toBeCloseTo(40, 1);
+ expect(box.max.z - box.min.z).toBeCloseTo(20, 1);
+ });
+
+ it('fills its circle `r`, as `preserveAspectRatio="xMidYMid slice"`', async () => {
+ const { scene } = await renderMark({
+ mark: 'image',
+ markProps: { href: wideImage(), x: 100, y: 100, r: 15, preserveAspectRatio: 'xMidYMid slice' },
+ });
+ await expect.poll(() => drawnBounds(scene).isEmpty()).toBe(false);
+ const box = drawnBounds(scene);
+ expect(box.max.x - box.min.x).toBeCloseTo(30, 0);
+ expect(box.max.z - box.min.z).toBeCloseTo(30, 0);
+ });
+});
+
+describe('Brush', () => {
+ it('brushes a selection by dragging over the scene', async () => {
+ let brush: BrushState | undefined;
+ const { result } = await renderMark({ mark: 'brush', onBrush: (b: BrushState | undefined) => (brush = b) });
+ await expect.poll(() => brush).toBeDefined();
+ const container = result.container.querySelector('.lc-root-container') as HTMLElement | null;
+ const target = (container ?? chart!.containerRef)!;
+ const rect = target.getBoundingClientRect();
+ const at = (type: string, x: number) =>
+ new PointerEvent(type, {
+ clientX: rect.left + x,
+ clientY: rect.top + 150,
+ bubbles: true,
+ pointerId: 1,
+ buttons: type === 'pointerup' ? 0 : 1,
+ });
+ chart!.containerRef!.querySelector('canvas')!.dispatchEvent(at('pointerdown', 100));
+ window.dispatchEvent(at('pointermove', 200));
+ window.dispatchEvent(at('pointerup', 200));
+ await expect.poll(() => brush?.active).toBe(true);
+ // 400 pixels for 0 to 10
+ expect(Number(brush!.x[0])).toBeCloseTo(2.5, 1);
+ expect(Number(brush!.x[1])).toBeCloseTo(5, 1);
+ });
+});
diff --git a/packages/webgl/src/lib/components/gradients-r8.svelte.test.ts b/packages/webgl/src/lib/components/gradients-r8.svelte.test.ts
new file mode 100644
index 0000000000..1a64ee9503
--- /dev/null
+++ b/packages/webgl/src/lib/components/gradients-r8.svelte.test.ts
@@ -0,0 +1,217 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { Color, SRGBColorSpace, type Object3D } from 'three';
+import type { ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import { gradientAffine, paintOf, type LinearGradientPaint } from '../utils/paint.svelte.js';
+import { ShapeContext } from '../utils/shapes.js';
+import Paints from './__fixtures__/Paints.svelte';
+
+let chart: ChartState | undefined;
+
+async function renderPaints(props: Omit>[1], 'onScene'>) {
+ let scene: SceneState | undefined;
+ render(Paints, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+function all(scene: SceneState, is: (o: any) => boolean) {
+ const found: any[] = [];
+ scene.root.traverse((o: Object3D) => {
+ if (is(o)) found.push(o);
+ });
+ return found;
+}
+
+/** The merged meshes' vertices that have any, as `[x, y (down the plot), r, g, b, a]` (sRGB) */
+function vertices(scene: SceneState) {
+ const out: number[][] = [];
+ const srgb = { r: 0, g: 0, b: 0 };
+ for (const mesh of all(
+ scene,
+ (o) => o.isMesh && !o.isInstancedMesh && o.geometry.attributes.color?.itemSize === 4
+ )) {
+ const position = mesh.geometry.attributes.position;
+ const color = mesh.geometry.attributes.color;
+ for (let i = 0; i < position.count; i++) {
+ new Color(color.getX(i), color.getY(i), color.getZ(i)).getRGB(srgb, SRGBColorSpace);
+ out.push([position.getX(i), position.getZ(i), srgb.r, srgb.g, srgb.b, color.getW(i)]);
+ }
+ }
+ return out;
+}
+
+const close = (a: number, b: number) => Math.abs(a - b) < 0.02;
+
+describe('LinearGradient', () => {
+ it('paints a rect from its first stop to its last across its own box', async () => {
+ const scene = await renderPaints({ mark: 'rect', rect: { x: 50, width: 100 } });
+ await expect.poll(() => vertices(scene).length).toBeGreaterThan(0);
+ const points = vertices(scene);
+ const left = points.filter((p) => close(p[0], 50));
+ const right = points.filter((p) => close(p[0], 150));
+ expect(left.length).toBeGreaterThan(0);
+ expect(right.length).toBeGreaterThan(0);
+ for (const p of left) expect([p[2], p[4]].map((v) => Math.round(v))).toEqual([1, 0]);
+ for (const p of right) expect([p[2], p[4]].map((v) => Math.round(v))).toEqual([0, 1]);
+ // Halfway, halfway between them (in sRGB, as SVG blends)
+ const middle = points.filter((p) => close(p[0], 100));
+ expect(middle.length).toBeGreaterThan(0);
+ for (const p of middle) expect(close(p[2], 0.5) && close(p[4], 0.5)).toBe(true);
+ });
+
+ it('cuts a shape at a hard stop, each side in its own color (`userSpaceOnUse`)', async () => {
+ const scene = await renderPaints({
+ mark: 'rect',
+ rect: { x: 0, y: 0, width: 100, height: 300 },
+ gradient: {
+ stops: [
+ [0.5, 'rgb(255, 0, 0)'],
+ [0.5, 'rgb(0, 0, 255)'],
+ ],
+ vertical: true,
+ units: 'userSpaceOnUse',
+ },
+ });
+ await expect.poll(() => vertices(scene).length).toBeGreaterThan(0);
+ const points = vertices(scene);
+ // Half the chart's height, as SVG's percentages of its viewport
+ const cut = chart!.containerHeight / 2;
+ const atCut = points.filter((p) => close(p[1], cut));
+ expect(atCut.some((p) => p[2] > 0.99 && p[4] < 0.01)).toBe(true);
+ expect(atCut.some((p) => p[4] > 0.99 && p[2] < 0.01)).toBe(true);
+ for (const p of points.filter((p) => p[1] < cut - 1)) expect(p[2]).toBeGreaterThan(0.99);
+ for (const p of points.filter((p) => p[1] > cut + 1)) expect(p[4]).toBeGreaterThan(0.99);
+ });
+
+ it("turns by `rotate` in its box's own space, as SVG's `gradientTransform`", () => {
+ const paint = {
+ type: 'linear',
+ stops: [],
+ classes: undefined,
+ x1: '0%',
+ y1: '0%',
+ x2: '100%',
+ y2: '0%',
+ rotate: 90,
+ units: 'objectBoundingBox',
+ viewport: { width: 400, height: 300 },
+ } satisfies LinearGradientPaint;
+ const [a, b, c] = gradientAffine(paint, { x: 10, y: 20, width: 100, height: 200 });
+ // Turned a quarter, it runs down the box: 0 at its top, 1 at its bottom
+ expect(a).toBeCloseTo(0);
+ expect(b * 20 + c).toBeCloseTo(0);
+ expect(b * 220 + c).toBeCloseTo(1);
+ });
+
+ it("strokes a line with its stops' colors and alphas along it", async () => {
+ const scene = await renderPaints({
+ mark: 'spline',
+ gradient: { stops: ['rgb(255 0 0 / 0.5)', 'rgb(0 0 255)'] },
+ });
+ await expect
+ .poll(() => all(scene, (o) => o.isLine2 && o.geometry.attributes.instanceAlphaStart).length)
+ .toBe(1);
+ const [line] = all(scene, (o) => o.isLine2);
+ const start = line.geometry.attributes.instanceColorStart;
+ const alpha = line.geometry.attributes.instanceAlphaStart;
+ // Red and half clear at its start, blue and opaque at its end
+ expect(start.getX(0)).toBeGreaterThan(0.99);
+ expect(alpha.getX(0)).toBeCloseTo(0.5);
+ const end = line.geometry.attributes.instanceColorEnd;
+ const last = end.count - 1;
+ expect(end.getZ(last)).toBeGreaterThan(0.99);
+ expect(line.geometry.attributes.instanceAlphaEnd.getX(last)).toBeGreaterThan(0.99);
+ });
+
+ it('strokes each run of rows a `stroke` function gives a gradient across its own bounds', async () => {
+ const scene = await renderPaints({
+ mark: 'spline',
+ // The first stretch (row 0 to 1) red to blue, the next (row 1 to 2) plain green
+ spline: { stroke: (d: { x: number }) => (d.x === 0 ? 'url(#run)' : 'rgb(0, 255, 0)') },
+ gradient: { id: 'run' },
+ });
+ await expect
+ .poll(() => all(scene, (o) => o.isLine2 && o.geometry.attributes.instanceAlphaStart).length)
+ .toBe(1);
+ const [line] = all(scene, (o) => o.isLine2);
+ const start = line.geometry.attributes.instanceColorStart;
+ const end = line.geometry.attributes.instanceColorEnd;
+ const last = end.count - 1;
+ // Red at its start, blue where the run ends (at row 1, not the line's end), then green
+ expect(start.getX(0)).toBeGreaterThan(0.99);
+ const at = line.geometry.attributes.instanceStart;
+ const row1 = chart!.xScale(1);
+ const before = [...Array(end.count).keys()].filter((k) => at.getX(k) < row1 - 0.5);
+ expect(end.getZ(before[before.length - 1])).toBeGreaterThan(0.99);
+ expect(end.getY(last)).toBeGreaterThan(0.99);
+ expect(end.getX(last)).toBeLessThan(0.01);
+ });
+
+ it("fills an area and strokes its line across each's bounds", async () => {
+ const scene = await renderPaints({ mark: 'area', gradient: { vertical: true } });
+ await expect.poll(() => vertices(scene).length).toBeGreaterThan(0);
+ const points = vertices(scene);
+ const top = Math.min(...points.map((p) => p[1]));
+ const bottom = Math.max(...points.map((p) => p[1]));
+ for (const p of points.filter((p) => close(p[1], top))) expect(p[2]).toBeGreaterThan(0.99);
+ for (const p of points.filter((p) => close(p[1], bottom))) expect(p[4]).toBeGreaterThan(0.99);
+ const outlines = all(
+ scene,
+ (o) => o.isLineSegments2 && o.geometry.attributes.instanceAlphaStart
+ );
+ expect(outlines.length).toBe(1);
+ });
+});
+
+describe('Pattern', () => {
+ it('fills a rect with its tile, repeating from the plot origin', async () => {
+ const scene = await renderPaints({
+ mark: 'pattern',
+ pattern: { size: 8, lines: { rotate: 45, color: 'red' }, background: 'white' },
+ });
+ await expect
+ .poll(() => all(scene, (o) => o.isMesh && o.material.map && o.visible).length)
+ .toBe(1);
+ const [mesh] = all(scene, (o) => o.isMesh && o.material.map);
+ const image = mesh.material.map.image as HTMLCanvasElement;
+ expect(image.width).toBe(image.height);
+ expect(image.width / 8).toBeGreaterThanOrEqual(2);
+ // Each vertex's place in the tiles: its pixels over the tile's size
+ const position = mesh.geometry.attributes.position;
+ const uv = mesh.geometry.attributes.uv;
+ for (let i = 0; i < position.count; i++) {
+ expect(uv.getX(i)).toBeCloseTo(position.getX(i) / 8);
+ expect(uv.getY(i)).toBeCloseTo(position.getZ(i) / 8);
+ }
+ });
+});
+
+describe('Pay only when used', () => {
+ it('looks up no paint for a plain color, and draws a plain rect as an instance', async () => {
+ const scene = await renderPaints({ mark: 'plain-rect' });
+ expect(paintOf(scene, 'red')).toBeNull();
+ expect(paintOf(scene, 'var(--color-primary)')).toBeNull();
+ await expect.poll(() => all(scene, (o) => o.isInstancedMesh && o.count > 0).length).toBe(1);
+ expect(vertices(scene).length).toBe(0);
+ });
+});
+
+describe('ShapeContext', () => {
+ it("outlines an arc the short way round a canvas' `arc` goes, across ±π", () => {
+ // A rounded corner's arc (as `d3.arc` draws one), from just under π to just over -π
+ const context = new ShapeContext();
+ context.arc(0, 0, 10, Math.PI - 0.2, -Math.PI + 0.2);
+ const [line] = context.lines;
+ // All of it about the left of the circle, not most of a turn round through its right
+ for (const [x] of line) expect(x).toBeLessThan(-9);
+ });
+});
diff --git a/packages/webgl/src/lib/components/layers/Layer.svelte b/packages/webgl/src/lib/components/layers/Layer.svelte
new file mode 100644
index 0000000000..a8978e6d76
--- /dev/null
+++ b/packages/webgl/src/lib/components/layers/Layer.svelte
@@ -0,0 +1,56 @@
+
+
+
+
+
+{#snippet panels(children: any)}
+ {#if ctx.facet.enabled}
+ {#each ctx.facet.panels as facet (facet.key)}
+
+ {/each}
+ {:else}
+ {@render children?.({ facet: ctx.facet.panels[0] })}
+ {/if}
+{/snippet}
+
+{#if layer === 'webgl'}
+ {@const {
+ type: _,
+ center,
+ children,
+ ...rest
+ } = props as { type?: 'webgl'; center?: boolean | 'x' | 'y' } & WebGLProps}
+
+
+ {#if center}
+ {@render panels(children)}
+ {:else}
+ {@render panels(children)}
+ {/if}
+
+{:else}
+
+{/if}
diff --git a/packages/webgl/src/lib/components/layers/Layer.svelte.test.ts b/packages/webgl/src/lib/components/layers/Layer.svelte.test.ts
new file mode 100644
index 0000000000..81eeef6c47
--- /dev/null
+++ b/packages/webgl/src/lib/components/layers/Layer.svelte.test.ts
@@ -0,0 +1,41 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+
+import Switched from './__fixtures__/Switched.svelte';
+
+/** Whether a canvas has a WebGL context (one only a `` scene asks for) */
+function isWebGL(canvas: HTMLCanvasElement) {
+ return canvas.getContext('2d') === null;
+}
+
+describe('layer-agnostic marks', () => {
+ it('draws LayerChart’s marks in an `svg` layer', async () => {
+ const { container } = render(Switched, { type: 'svg' });
+ await expect.poll(() => container.querySelectorAll('svg circle').length).toBe(5);
+ expect(container.querySelector('canvas')).toBeNull();
+ });
+
+ it('draws LayerChart’s marks in a `canvas` layer', async () => {
+ const { container } = render(Switched, { type: 'canvas' });
+ await expect.poll(() => container.querySelectorAll('canvas').length).toBeGreaterThan(0);
+ expect([...container.querySelectorAll('canvas')].some(isWebGL)).toBe(false);
+ expect(container.querySelector('svg circle')).toBeNull();
+ });
+
+ it('draws LayerChart’s marks in an `html` layer', async () => {
+ const { container } = render(Switched, { type: 'html' });
+ await expect.poll(() => container.querySelectorAll('.lc-circle').length).toBe(5);
+ expect(container.querySelector('canvas')).toBeNull();
+ });
+
+ it('draws a `` scene with `type="webgl"`', async () => {
+ const { container } = render(Switched, { type: 'webgl' });
+ await expect.poll(() => [...container.querySelectorAll('canvas')].some(isWebGL)).toBe(true);
+ expect(container.querySelector('svg circle')).toBeNull();
+ });
+
+ it('draws the layer in `settings.layer`, `webgl` included, with no `type`', async () => {
+ const { container } = render(Switched, { layer: 'webgl' });
+ await expect.poll(() => [...container.querySelectorAll('canvas')].some(isWebGL)).toBe(true);
+ });
+});
diff --git a/packages/webgl/src/lib/components/WebGL/WebGL.svelte b/packages/webgl/src/lib/components/layers/WebGL.svelte
similarity index 75%
rename from packages/webgl/src/lib/components/WebGL/WebGL.svelte
rename to packages/webgl/src/lib/components/layers/WebGL.svelte
index 41f14a7456..65d73ee7be 100644
--- a/packages/webgl/src/lib/components/WebGL/WebGL.svelte
+++ b/packages/webgl/src/lib/components/layers/WebGL.svelte
@@ -46,7 +46,7 @@
import { NoToneMapping, PCFShadowMap, WebGLRenderer } from 'three';
import { getChartContext } from 'layerchart';
- import { SceneState, setSceneContext } from '../../contexts/scene.svelte.js';
+ import { SceneState, setSceneContext, type SceneMarker } from '../../contexts/scene.svelte.js';
import { ColorResolver } from '../../utils/color.js';
import WebGLSetup from './WebGLSetup.svelte';
@@ -74,6 +74,40 @@
}: WebGLProps = $props();
const sceneState = setSceneContext(new SceneState());
+
+ /** `color` at `opacity` (a label's letters or halo), as it is without one */
+ function alpha(color: string, opacity: number | undefined) {
+ return opacity == null ? color : `color-mix(in srgb, ${color} ${opacity * 100}%, transparent)`;
+ }
+
+ /** Whether a marker takes the pointer: only one with handlers does, while the scene takes it */
+ const takesPointer = (marker: SceneMarker) =>
+ pointerEvents !== false && !!(marker.onclick || marker.onpointerenter || marker.onpointerleave);
+
+ /**
+ * Pass a pointer's move over a marker on to the scene beneath, so what's under it is still
+ * hovered (ex. a tooltip from the marks), and its leaving when it leaves for outside the scene
+ * rather than for the scene itself (which the scene sees for itself)
+ */
+ function toScene(e: PointerEvent) {
+ const canvas = element?.querySelector('canvas');
+ const to = e.relatedTarget as Element | null;
+ if (
+ !canvas ||
+ (e.type === 'pointerleave' && (to === canvas || to?.closest?.('.lc-webgl-markers')))
+ )
+ return;
+ canvas.dispatchEvent(
+ new PointerEvent(e.type, {
+ clientX: e.clientX,
+ clientY: e.clientY,
+ buttons: e.buttons,
+ pointerId: e.pointerId,
+ pointerType: e.pointerType,
+ relatedTarget: to,
+ })
+ );
+ }
const ctx = getChartContext();
$effect.pre(() => {
sceneState.clip = clip ?? ctx.props.transform?.mode === 'domain';
@@ -162,6 +196,9 @@
{#each markers as marker (marker.key)}
{@const point = sceneState.project(marker.x, marker.y, marker.z)}
{#if point}
+
+
+
e.stopPropagation())}
+ onpointerenter={marker.onpointerenter}
+ onpointermove={takesPointer(marker) ? (e: PointerEvent) => toScene(e) : undefined}
+ onpointerleave={takesPointer(marker)
+ ? (e: PointerEvent) => {
+ marker.onpointerleave?.(e);
+ toScene(e);
+ }
+ : undefined}
/>
{/if}
{/each}
@@ -197,8 +246,12 @@
style:max-width={label.width ? `${label.width}px` : undefined}
style:color={label.color}
style:-webkit-text-stroke={label.stroke
- ? `${label.strokeWidth ?? 1}px ${label.stroke}`
+ ? `${label.strokeWidth ?? 1}px ${alpha(label.stroke, label.strokeOpacity)}`
: undefined}
+ style:-webkit-text-fill-color={label.fillOpacity == null
+ ? undefined
+ : alpha('currentColor', label.fillOpacity)}
+ style:opacity={label.opacity}
style:paint-order={label.stroke ? 'stroke fill' : undefined}
style:white-space={label.width ? 'normal' : undefined}
>
diff --git a/packages/webgl/src/lib/components/WebGL/WebGL.svelte.test.ts b/packages/webgl/src/lib/components/layers/WebGL.svelte.test.ts
similarity index 100%
rename from packages/webgl/src/lib/components/WebGL/WebGL.svelte.test.ts
rename to packages/webgl/src/lib/components/layers/WebGL.svelte.test.ts
diff --git a/packages/webgl/src/lib/components/WebGL/WebGLSetup.svelte b/packages/webgl/src/lib/components/layers/WebGLSetup.svelte
similarity index 87%
rename from packages/webgl/src/lib/components/WebGL/WebGLSetup.svelte
rename to packages/webgl/src/lib/components/layers/WebGLSetup.svelte
index 2aaeee043a..67b9e4e855 100644
--- a/packages/webgl/src/lib/components/WebGL/WebGLSetup.svelte
+++ b/packages/webgl/src/lib/components/layers/WebGLSetup.svelte
@@ -12,6 +12,7 @@
Plane,
Quaternion,
Raycaster,
+ type Camera,
type Mesh,
type Object3D,
Vector2,
@@ -20,10 +21,11 @@
import { getChartContext } from 'layerchart';
import { createControlledMotion } from 'layerchart/utils/motion.svelte';
- import { getSceneContext } from '../../contexts/scene.svelte.js';
+ import { getSceneContext, type Pickable } from '../../contexts/scene.svelte.js';
import { frameOrthographic, framePerspective, viewDirection } from '../../utils/camera.js';
import { geoPath } from 'd3-geo';
import { getSphere } from '../../utils/globe.js';
+ import { clipKeeps, clipMaterial, type ClipChain, type SceneClip } from '../../utils/clip.js';
let { children }: { children?: Snippet } = $props();
@@ -64,16 +66,28 @@
invalidate();
});
renderer.localClippingEnabled = true;
- /** Clip `object`'s materials, and its children's, unless they're kept from it */
- function clip(object: Object3D, planes: Plane[] | null) {
- if (object.userData.unclipped) planes = null;
+ /**
+ * Clip `object`'s materials, and its children's, to the plot box unless they're kept from it,
+ * and to the `ClipPath`s they're in (`userData.clip`, see `SceneClip`)
+ */
+ let clipFrame = 0;
+ function clip(object: Object3D, plot: boolean, chain: ClipChain | null, camera: Camera) {
+ if (object.userData.unclipped) plot = false;
+ const region = object.userData.clip as SceneClip | undefined;
+ if (region) chain = region.chain(object, chain, clipPlanes, camera);
+ const planes = chain ? (plot ? chain.withPlot : chain.planes) : plot ? clipPlanes : null;
const material = (object as Mesh).material;
- if (material) {
- for (const m of Array.isArray(material) ? material : [material]) m.clippingPlanes = planes;
+ if (Array.isArray(material)) {
+ for (const m of material) clipMaterial(null, m, planes, chain, clipFrame);
+ } else if (material) {
+ clipMaterial(object as Mesh, material, planes, chain, clipFrame);
}
- for (const child of object.children) clip(child, planes);
+ for (const child of object.children) clip(child, plot, chain, camera);
}
- scene.onBeforeRender = () => clip(sceneState.root, sceneState.clip ? clipPlanes : null);
+ scene.onBeforeRender = (_renderer, _scene, camera) => {
+ clipFrame++;
+ clip(sceneState.root, sceneState.clip, null, camera);
+ };
// Even light all round, plus a key light from above and to the left of the camera (it moves
// with it) so faces turned different ways read apart. Lambert shading divides by π, so these
@@ -245,7 +259,8 @@
// Flat: straight down on the floor, each chart pixel on a pixel of the layer, where a flat
// layer would draw it (so `Svg` / `Html` layers line up over it)
const { left, top } = ctx.padding;
- const distance = Math.max(box.width, box.height, box.depth, 1) * 2;
+ // Above every mark's layer, however many are stacked
+ const distance = Math.max(box.width, box.height, box.depth, 1) * 2 + sceneState.stackHeight;
fitTarget.set(0, 0, 0);
Object.assign(cam, {
left: -(left + ctx.width / 2),
@@ -491,7 +506,8 @@
({ object, point }) =>
(object as Mesh).isMesh &&
shown(object) &&
- (!sceneState.clip || clipPlanes.every((p) => p.distanceToPoint(point) >= 0))
+ (!sceneState.clip || clipPlanes.every((p) => p.distanceToPoint(point) >= 0)) &&
+ clipKeeps(object, point)
);
if (hit) return hit.point;
// The floor only where the plot is: past it, towards the horizon, it goes on without end
@@ -735,14 +751,8 @@
$effect(() => {
const element = renderer.domElement;
- const onPointerMove = (e: PointerEvent) => {
- // Nothing here shows a tooltip, so leave it to the chart's (ex. a `quadtree` over the rows)
- if (!sceneState.pickables.size) return;
- // A drag turns or pans the view
- if (e.buttons || ctx.transform.dragging) {
- ctx.tooltip.hide(e);
- return;
- }
+ /** What's under the pointer: the pickable mark it hits first, and that hit's row */
+ const pick = (e: MouseEvent) => {
const rect = element.getBoundingClientRect();
pointer.set(
((e.clientX - rect.left) / rect.width) * 2 - 1,
@@ -757,20 +767,81 @@
false
)
.find(
- ({ point }) => !sceneState.clip || clipPlanes.every((p) => p.distanceToPoint(point) >= 0)
+ ({ object, point }) =>
+ (!sceneState.clip || clipPlanes.every((p) => p.distanceToPoint(point) >= 0)) &&
+ clipKeeps(object, point)
);
- const datum = hit ? pickables.find((p) => p.object === hit.object)?.datum(hit) : undefined;
- if (datum != null) ctx.tooltip.show(e, datum);
- else ctx.tooltip.hide(e);
+ const pickable = hit ? pickables.find((p) => p.object === hit.object) : undefined;
+ return pickable && hit ? { pickable, datum: pickable.datum(hit) } : null;
+ };
+
+ /** The mark and row the pointer was last over, for its enter / leave handlers */
+ let over: { pickable: Pickable; datum: unknown } | null = null;
+ const leave = (e: PointerEvent) => {
+ if (!over) return;
+ const events = over.pickable.events?.();
+ events?.onpointerleave?.(e, { data: over.datum });
+ events?.onpointerout?.(e, { data: over.datum });
+ over = null;
+ element.style.cursor = '';
+ };
+ const enter = (e: PointerEvent, next: { pickable: Pickable; datum: unknown }) => {
+ over = next;
+ const events = next.pickable.events?.();
+ events?.onpointerenter?.(e, { data: next.datum });
+ events?.onpointerover?.(e, { data: next.datum });
+ // Clickable, as the core marks with an `onclick` show
+ if (events?.onclick || events?.ondblclick) element.style.cursor = 'pointer';
+ };
+
+ const onPointerMove = (e: PointerEvent) => {
+ // Nothing here shows a tooltip or takes the pointer, so leave it to the chart's (ex. a
+ // `quadtree` over the rows)
+ if (!sceneState.pickables.size) return;
+ // A drag turns or pans the view
+ if (e.buttons || ctx.transform.dragging) {
+ ctx.tooltip.hide(e);
+ leave(e);
+ return;
+ }
+ const picked = pick(e);
+ const datum = picked?.datum;
+ if (picked?.pickable !== over?.pickable || datum !== over?.datum) {
+ leave(e);
+ if (picked && datum != null) enter(e, picked);
+ }
+ if (picked && datum != null) picked.pickable.events?.()?.onpointermove?.(e, { data: datum });
+ // The tooltip from the marks that show it, and only them
+ if (picked && datum != null && (picked.pickable.tooltip?.() ?? true))
+ ctx.tooltip.show(e, datum);
+ else if ([...sceneState.pickables].some((p) => p.tooltip?.() ?? true)) ctx.tooltip.hide(e);
};
const onPointerLeave = (e: PointerEvent) => {
- if (sceneState.pickables.size) ctx.tooltip.hide(e);
+ // Onto a marker over the scene (ex. a `Highlight`'s point taking clicks), which passes its
+ // moves on here, and its leaving
+ if ((e.relatedTarget as Element | null)?.closest?.('.lc-webgl-markers')) return;
+ leave(e);
+ if ([...sceneState.pickables].some((p) => p.tooltip?.() ?? true)) ctx.tooltip.hide(e);
+ };
+ /** A click on a mark that takes one, with its row */
+ const onClick = (type: 'onclick' | 'ondblclick') => (e: MouseEvent) => {
+ if (!sceneState.pickables.size) return;
+ const picked = pick(e);
+ if (picked && picked.datum != null) {
+ picked.pickable.events?.()?.[type]?.(e, { data: picked.datum });
+ }
};
+ const onclick = onClick('onclick');
+ const ondblclick = onClick('ondblclick');
element.addEventListener('pointermove', onPointerMove);
element.addEventListener('pointerleave', onPointerLeave);
+ element.addEventListener('click', onclick);
+ element.addEventListener('dblclick', ondblclick);
return () => {
element.removeEventListener('pointermove', onPointerMove);
element.removeEventListener('pointerleave', onPointerLeave);
+ element.removeEventListener('click', onclick);
+ element.removeEventListener('dblclick', ondblclick);
};
});
diff --git a/packages/webgl/src/lib/components/WebGL/__fixtures__/Orbit.svelte b/packages/webgl/src/lib/components/layers/__fixtures__/Orbit.svelte
similarity index 100%
rename from packages/webgl/src/lib/components/WebGL/__fixtures__/Orbit.svelte
rename to packages/webgl/src/lib/components/layers/__fixtures__/Orbit.svelte
diff --git a/packages/webgl/src/lib/components/WebGL/__fixtures__/Scatter.svelte b/packages/webgl/src/lib/components/layers/__fixtures__/Scatter.svelte
similarity index 100%
rename from packages/webgl/src/lib/components/WebGL/__fixtures__/Scatter.svelte
rename to packages/webgl/src/lib/components/layers/__fixtures__/Scatter.svelte
diff --git a/packages/webgl/src/lib/components/layers/__fixtures__/Switched.svelte b/packages/webgl/src/lib/components/layers/__fixtures__/Switched.svelte
new file mode 100644
index 0000000000..aad9f991de
--- /dev/null
+++ b/packages/webgl/src/lib/components/layers/__fixtures__/Switched.svelte
@@ -0,0 +1,24 @@
+
+
+
diff --git a/packages/webgl/src/lib/components/WebGL/__screenshots__/Scene.svelte.test.ts/Scene-hands-orbiting-back-through--bind-rotate-----bind-tilt--1.png b/packages/webgl/src/lib/components/layers/__screenshots__/Scene.svelte.test.ts/Scene-hands-orbiting-back-through--bind-rotate-----bind-tilt--1.png
similarity index 100%
rename from packages/webgl/src/lib/components/WebGL/__screenshots__/Scene.svelte.test.ts/Scene-hands-orbiting-back-through--bind-rotate-----bind-tilt--1.png
rename to packages/webgl/src/lib/components/layers/__screenshots__/Scene.svelte.test.ts/Scene-hands-orbiting-back-through--bind-rotate-----bind-tilt--1.png
diff --git a/packages/webgl/src/lib/components/marks.svelte.test.ts b/packages/webgl/src/lib/components/marks.svelte.test.ts
index 5f16dc1233..ceab820182 100644
--- a/packages/webgl/src/lib/components/marks.svelte.test.ts
+++ b/packages/webgl/src/lib/components/marks.svelte.test.ts
@@ -13,6 +13,7 @@ import {
type InstancedMesh,
type Object3D,
type PerspectiveCamera,
+ Color,
} from 'three';
import { geoIdentity, geoMercator } from 'd3-geo';
@@ -106,6 +107,66 @@ describe('Spline', () => {
await expect.poll(() => children(scene, 'isLine2').length).toBe(3);
});
+ it('tweens a line up from the baseline with `motion`, as LayerChart’s', async () => {
+ const scene = await renderMarks({
+ mark: 'spline',
+ chart: {
+ data: [
+ { x: 0, y: 8 },
+ { x: 10, y: 8 },
+ ],
+ x: 'x',
+ y: 'y',
+ xDomain: [0, 10],
+ yDomain: [0, 10],
+ },
+ spline: { motion: { type: 'tween', duration: 400 } },
+ });
+ /** Where the line's first point is down the plot */
+ const first = () => {
+ const [line] = children(scene, 'isLine2') as any[];
+ return line?.geometry.attributes.instanceStart?.getZ(0) ?? NaN;
+ };
+ const baseline = chart!.yScale(0);
+ const target = chart!.yScale(8);
+ // On its way up...
+ await expect.poll(() => first() < baseline - 1 && first() > target + 1).toBe(true);
+ // ...and there
+ await expect.poll(first).toBeCloseTo(target);
+ });
+
+ it('tweens an area up from the baseline with `motion`, as LayerChart’s', async () => {
+ const scene = await renderMarks({
+ mark: 'area',
+ chart: {
+ data: [
+ { x: 0, y: 8 },
+ { x: 10, y: 8 },
+ ],
+ x: 'x',
+ y: 'y',
+ xDomain: [0, 10],
+ yDomain: [0, 10],
+ },
+ area: { motion: { type: 'tween', duration: 400 } },
+ });
+ /** How far up the plot the fill's top reaches */
+ const top = () => {
+ const mesh = layered(scene).find((o: any) => o.isMesh && !o.isLineSegments2) as any;
+ const position = mesh?.geometry.getAttribute('position');
+ if (!position?.count) return NaN;
+ let min = Infinity;
+ for (let i = 0; i < position.count; i++) min = Math.min(min, position.getZ(i));
+ return min;
+ };
+ const baseline = chart!.yScale(0);
+ const target = chart!.yScale(8);
+ // On its way up...
+ await expect.poll(() => top() < baseline - 1 && top() > target + 1).toBe(true);
+ // ...and there
+ await expect.poll(top).toBeCloseTo(target);
+ });
+
it('colors along one line by a numeric data key `stroke` names, rather than splitting it', async () => {
const scene = await renderMarks({
mark: 'spline',
@@ -164,6 +225,19 @@ describe('Spline and Area, as LayerChart draws them', () => {
expect(Math.max(...downs)).toBeCloseTo(chart!.yScale(0), 0);
expect(Math.min(...downs)).toBeCloseTo(chart!.yScale(7), 0);
});
+
+ it('draws an `Area`’s `line` with its own `stroke` and `strokeWidth`, as the core `Area` takes it', async () => {
+ const scene = await renderMarks({
+ mark: 'area',
+ chart: { ...chartProps, data: series.filter((d) => d.y != null) },
+ area: { line: { stroke: 'rgb(255, 0, 0)', strokeWidth: 3 } },
+ });
+ const lines = () => layered(scene).find((o) => (o as any).isLineSegments2) as any;
+ await expect.poll(() => lines()?.visible).toBe(true);
+ expect(lines().material.linewidth).toBe(3);
+ const [r, g, b] = lines().geometry.attributes.instanceColorStart.array;
+ expect([r, g, b]).toEqual([1, 0, 0]);
+ });
});
describe('Polygon, as LayerChart draws it', () => {
@@ -876,7 +950,7 @@ describe('GeoPath', () => {
const scene = await renderMarks({
mark: 'geopath',
chart: { geo: { projection: geoIdentity } },
- geopath: { geojson: square, z: 20 },
+ geopath: { geojson: square, z: 20, fill: 'gray' },
});
const mesh = layered(scene).find((o: any) => o.isMesh) as any;
await expect.poll(() => mesh.geometry.getAttribute('position')?.count ?? 0).toBeGreaterThan(0);
@@ -1113,7 +1187,7 @@ describe('placed as LayerChart places its namesakes', () => {
const props = (x: number) => ({
mark: 'text' as const,
chart: chartProps,
- text: { x, y: 20, value: 'moving' },
+ text: { x, y: 20, value: 'moving', textAnchor: 'middle' },
onScene: (s: SceneState, c: ChartState) => {
latest = s;
chart = c;
@@ -1139,7 +1213,7 @@ describe('placed as LayerChart places its namesakes', () => {
const scene = await renderMarks({
mark: 'text',
chart: chartProps,
- text: { x: 'x', y: 'y', value: 'name' },
+ text: { x: 'x', y: 'y', value: 'name', textAnchor: 'middle' },
});
await expect
.poll(() => {
@@ -1158,7 +1232,8 @@ describe('placed as LayerChart places its namesakes', () => {
});
const [a] = planes;
expect(a.position.x).toBeCloseTo(chart!.xScale(2));
- expect(a.position.z).toBeCloseTo(chart!.yScale(8));
+ // On its baseline (as the core `Text`), so its middle is within a line of its row's place
+ expect(Math.abs(a.position.z - chart!.yScale(8))).toBeLessThan(12);
expect(a.position.y).toBeLessThan(1);
});
@@ -1190,6 +1265,32 @@ describe('placed as LayerChart places its namesakes', () => {
expect(size.y).toBeCloseTo(10);
});
+ it('eases a `Rect` to where it moves with `motion`, rather than jumping', async () => {
+ let scene: SceneState | undefined;
+ const props = (x: number) => ({
+ mark: 'rect' as const,
+ chart: chartProps,
+ rect: { x, y: 10, width: 20, height: 20, motion: { type: 'tween' as const, duration: 400 } },
+ onScene: (s: SceneState) => (scene = s),
+ });
+ const { rerender } = render(Marks, props(10));
+ const left = () => {
+ const [mesh] = scene ? (children(scene, 'isInstancedMesh') as InstancedMesh[]) : [];
+ if (!mesh) return NaN;
+ const matrix = new Matrix4();
+ mesh.getMatrixAt(0, matrix);
+ return new Vector3().setFromMatrixPosition(matrix).x;
+ };
+ // Where it's first asked to be, at once
+ await expect.poll(left).toBeCloseTo(10);
+
+ await rerender(props(110));
+ // On its way...
+ await expect.poll(() => left() > 15 && left() < 105).toBe(true);
+ // ...and there
+ await expect.poll(left).toBeCloseTo(110);
+ });
+
it('outlines a `Rect` with a `stroke`, around its top and up its corners, and not without', async () => {
const box = {
data: [{ x0: 1, x1: 3, y0: 6, y1: 8, depth: 2 }],
@@ -1257,7 +1358,119 @@ describe('placed as LayerChart places its namesakes', () => {
});
const segments = layered(scene).find((o) => (o as any).isLineSegments2) as any;
const ends = Array.from(segments.geometry.attributes.instanceStart.data.array as Float32Array);
- expect(ends.slice(0, 6)).toEqual([10, 0, 20, 30, 0, 40]);
+ // From its source to its target, along the core `Link`'s bump curve (in pieces)
+ expect(ends.slice(0, 3)).toEqual([10, 0, 20]);
+ expect(ends.slice(-3)).toEqual([30, 0, 40]);
+ expect(ends.length / 6).toBeGreaterThan(1);
+ });
+
+ it('tweens a `Link` to where its nodes move with `motion`, as the core `Link`', async () => {
+ let scene: SceneState | undefined;
+ const props = (targetX: number) => ({
+ mark: 'link' as const,
+ chart: chartProps,
+ link: {
+ data: [{ source: { x: 10, y: 20 }, target: { x: targetX, y: 40 } }],
+ type: 'straight' as const,
+ motion: { type: 'tween' as const, duration: 400 },
+ },
+ onScene: (s: SceneState) => (scene = s),
+ });
+ const { rerender } = render(Marks, props(30));
+ /** Where the link ends across the plot */
+ const end = () => {
+ const segments = scene && (layered(scene).find((o) => (o as any).isLineSegments2) as any);
+ const ends = segments?.geometry.attributes.instanceStart?.data.array as
+ | Float32Array
+ | undefined;
+ return ends?.length ? ends[ends.length - 3] : NaN;
+ };
+ // Where it's first asked to be, at once
+ await expect.poll(end).toBeCloseTo(30);
+
+ await rerender(props(130));
+ // On its way...
+ await expect.poll(() => end() > 35 && end() < 125).toBe(true);
+ // ...and there
+ await expect.poll(end).toBeCloseTo(130);
+ });
+
+ it('draws a `Link` `type="straight"` as one segment', async () => {
+ const scene = await renderMarks({
+ mark: 'link',
+ chart: chartProps,
+ link: { data: [{ source: { x: 10, y: 20 }, target: { x: 30, y: 40 } }], type: 'straight' },
+ });
+ const segments = layered(scene).find((o) => (o as any).isLineSegments2) as any;
+ const ends = Array.from(segments.geometry.attributes.instanceStart.data.array as Float32Array);
+ expect(ends).toEqual([10, 0, 20, 30, 0, 40]);
+ });
+
+ it('links one link given as `data`, in its `class`’s stroke, as the core `Link` takes it', async () => {
+ const style = document.createElement('style');
+ style.textContent = '.test-link { stroke: rgb(255, 0, 0) }';
+ document.head.append(style);
+ try {
+ const scene = await renderMarks({
+ mark: 'link',
+ chart: chartProps,
+ link: {
+ data: { source: { x: 10, y: 20 }, target: { x: 30, y: 40 } },
+ class: 'test-link',
+ },
+ });
+ const segments = () => layered(scene).find((o) => (o as any).isLineSegments2) as any;
+ await expect
+ .poll(() => segments()?.geometry.attributes.instanceStart?.count ?? 0)
+ .toBeGreaterThan(0);
+ const [r, g, b] = segments().geometry.attributes.instanceColorStart.array;
+ expect([r, g, b]).toEqual([1, 0, 0]);
+ } finally {
+ style.remove();
+ }
+ });
+
+ it('draws a `Circle` at `cx` / `cy` pixels, and through the scales with rows', async () => {
+ const center = (scene: SceneState, i = 0) => {
+ const matrix = new Matrix4();
+ (children(scene, 'isInstancedMesh')[0] as InstancedMesh).getMatrixAt(i, matrix);
+ const position = new Vector3();
+ const size = new Vector3();
+ matrix.decompose(position, new Quaternion(), size);
+ return { x: position.x, y: position.z, r: size.x };
+ };
+ const pixels = await renderMarks({
+ mark: 'circle',
+ chart: chartProps,
+ circle: { cx: 40, cy: 30, r: 6 },
+ });
+ expect(center(pixels)).toEqual({ x: 40, y: 30, r: 6 });
+
+ const scene = await renderMarks({
+ mark: 'circle',
+ chart: chartProps,
+ circle: { data: rows, cx: 'x', cy: 'y', r: 4 },
+ });
+ await expect
+ .poll(() => (children(scene, 'isInstancedMesh')[0] as InstancedMesh)?.count)
+ .toBe(rows.length);
+ expect(center(scene).x).toBeCloseTo(chart!.xScale(rows[0].x));
+ expect(center(scene).y).toBeCloseTo(chart!.yScale(rows[0].y));
+ });
+
+ it('colors a `Circle` by the `--fill-color` its `style` sets, at its `fillOpacity`', async () => {
+ const scene = await renderMarks({
+ mark: 'circle',
+ chart: chartProps,
+ circle: { cx: 40, cy: 30, r: 6, style: '--fill-color: rgb(255, 0, 0)', fillOpacity: 0.25 },
+ });
+ const mesh = () => children(scene, 'isInstancedMesh')[0] as InstancedMesh | undefined;
+ await expect.poll(() => mesh()?.count).toBe(1);
+ const color = new Color();
+ mesh()!.getColorAt(0, color);
+ expect(color.r).toBeCloseTo(1);
+ expect(color.g).toBeCloseTo(0);
+ expect((mesh()!.material as any).opacity).toBeCloseTo(0.25);
});
});
@@ -1282,6 +1495,52 @@ describe('Axis', () => {
return found;
};
+ /** The axis' rule and tick marks (and not a `Grid`'s lines), as `[x, height, y]` pairs */
+ const ruleSegments = (scene: SceneState) => {
+ const lines = layered(scene).find((o) => (o as any).isLineSegments2) as any;
+ const start = lines?.visible ? lines.geometry.attributes.instanceStart : null;
+ const positions = Array.from((start?.data.array as Float32Array) ?? []);
+ return Array.from({ length: positions.length / 6 }, (_, i) =>
+ positions.slice(i * 6, i * 6 + 6).map((v) => Math.round(v))
+ );
+ };
+ const flat = { ...chartProps, view: undefined, z: undefined, transform: undefined };
+
+ it('draws a `top` / `right` axis along the edges across from `bottom` / `left`', async () => {
+ const top = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'top', ticks: [], rule: true },
+ });
+ await expect.poll(() => ruleSegments(top)).toEqual([[0, 0, 0, Math.round(chart!.width), 0, 0]]);
+
+ const right = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'right', ticks: [], rule: true },
+ });
+ const w = Math.round(chart!.width);
+ await expect
+ .poll(() => ruleSegments(right))
+ .toEqual([[w, 0, 0, w, 0, Math.round(chart!.height)]]);
+ });
+
+ it('draws a `grid` across the plot at its ticks, as the core `Axis`', async () => {
+ const lineSets = (scene: SceneState) =>
+ layered(scene).filter((o) => (o as any).isLineSegments || (o as any).isLineSegments2).length;
+ const plain = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'left', ticks: [0, 5, 10] },
+ });
+ const gridded = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'left', ticks: [0, 5, 10], grid: true },
+ });
+ await expect.poll(() => lineSets(gridded)).toBeGreaterThan(lineSets(plain));
+ });
+
it('lays the floor’s tick labels on it, as an `isometric` chart’s', async () => {
const scene = await renderMarks({
mark: 'axis',
@@ -2133,7 +2392,12 @@ describe('GeoPath motion', () => {
const { rerender } = render(Marks, {
mark: 'geopath',
chart: { geo: { projection: geoIdentity as any } },
- geopath: { geojson: square(10), z: 10, motion: { type: 'tween', duration: 400 } },
+ geopath: {
+ geojson: square(10),
+ z: 10,
+ fill: 'gray',
+ motion: { type: 'tween', duration: 400 },
+ },
onScene: (s: SceneState) => (scene = s),
});
await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
@@ -2145,7 +2409,12 @@ describe('GeoPath motion', () => {
await expect.poll(top).toBeCloseTo(10);
await rerender({
- geopath: { geojson: square(40), z: 40, motion: { type: 'tween', duration: 400 } },
+ geopath: {
+ geojson: square(40),
+ z: 40,
+ fill: 'gray',
+ motion: { type: 'tween', duration: 400 },
+ },
});
// Partway there, then all the way
await expect.poll(top).toBeGreaterThan(11);
@@ -2154,6 +2423,43 @@ describe('GeoPath motion', () => {
});
});
+describe('Circle motion', () => {
+ it('eases to a new place rather than jumping, as the core `Circle`', async () => {
+ let scene: SceneState | undefined;
+ const props = (cx: number) => ({
+ data: [{}],
+ cx: () => cx,
+ cy: () => 5,
+ r: 4,
+ motion: { type: 'tween' as const, duration: 400 },
+ });
+ const { rerender } = render(Marks, {
+ mark: 'circle',
+ chart: { xDomain: [0, 10], yDomain: [0, 10] },
+ circle: props(2),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ const across = () => {
+ const mesh = layered(scene!).find((o: any) => o.isInstancedMesh) as InstancedMesh;
+ const matrix = new Matrix4();
+ mesh.getMatrixAt(0, matrix);
+ return new Vector3().setFromMatrixPosition(matrix).x;
+ };
+ const at = (value: number) => chart!.xScale(value);
+ await expect.poll(across).toBeCloseTo(at(2));
+
+ await rerender({ circle: props(8) });
+ // Partway there, then all the way
+ await expect.poll(across).toBeGreaterThan(at(2) + 1);
+ expect(across()).toBeLessThan(at(8) - 1);
+ await expect.poll(across).toBeCloseTo(at(8));
+ });
+});
+
describe('strokes, as LayerChart’s marks take them', () => {
/** How many line segments a mark's outlines draw */
const segments = (scene: SceneState) => {
@@ -2186,6 +2492,98 @@ describe('strokes, as LayerChart’s marks take them', () => {
expect((instanced(scene)[0].material as any).polygonOffset).toBe(true);
});
+ const columns = {
+ data: [
+ { x: 'a', y: 4 },
+ { x: 'b', y: 8 },
+ ],
+ x: 'x',
+ xScale: scaleBand().padding(0.2),
+ xDomain: ['a', 'b'],
+ y: 'y',
+ yDomain: [0, 10],
+ };
+
+ it('draws `Bars` without a `z` as LayerChart’s 2D bars, flat on the floor', async () => {
+ const scene = await renderMarks({ mark: 'bars', chart: columns, bars: { insets: { x: 2 } } });
+ await expect.poll(() => instanced(scene)[0]?.count ?? 0).toBe(2);
+ const matrix = new Matrix4();
+ instanced(scene)[0].getMatrixAt(1, matrix);
+ const position = new Vector3();
+ const size = new Vector3();
+ matrix.decompose(position, new Quaternion(), size);
+ // Across its band (less its insets), and from the baseline up to its value
+ expect(position.x).toBeCloseTo((chart!.xScale as any)('b') + 2);
+ expect(size.x).toBeCloseTo((chart!.xScale as any).bandwidth() - 4);
+ expect(position.z).toBeCloseTo(chart!.yScale(8));
+ expect(size.z).toBeCloseTo(chart!.yScale(0) - chart!.yScale(8));
+ expect(size.y).toBeLessThan(1);
+ });
+
+ it('grows `Bars` up from the baseline with `motion`, as LayerChart’s bars mount', async () => {
+ const scene = await renderMarks({
+ mark: 'bars',
+ chart: columns,
+ bars: { motion: { type: 'tween', duration: 400 } },
+ });
+ /** The second bar's top and length along `y` */
+ const bar = () => {
+ const [mesh] = instanced(scene);
+ if (!mesh?.count) return null;
+ const matrix = new Matrix4();
+ mesh.getMatrixAt(1, matrix);
+ const position = new Vector3();
+ const size = new Vector3();
+ matrix.decompose(position, new Quaternion(), size);
+ return { top: position.z, length: size.z };
+ };
+ const full = chart!.yScale(0) - chart!.yScale(8);
+ // On its way up from the baseline...
+ await expect
+ .poll(() => (bar()?.length ?? 0) > 1 && (bar()?.length ?? full) < full - 1)
+ .toBe(true);
+ // ...and there
+ await expect.poll(() => bar()?.length).toBeCloseTo(full);
+ expect(bar()?.top).toBeCloseTo(chart!.yScale(8));
+ });
+
+ it('rounds flat `Bars` with a `radius`, each a shape rather than a box', async () => {
+ const scene = await renderMarks({ mark: 'bars', chart: columns, bars: { radius: 4 } });
+ const shapes = () => {
+ // The mesh with the most vertices: the bars' shapes, merged
+ let found: any;
+ scene.root.traverse((o: any) => {
+ const count =
+ o.isMesh && !o.isInstancedMesh ? o.geometry.getAttribute('position')?.count : 0;
+ if (count > (found?.geometry.getAttribute('position').count ?? 0)) found = o;
+ });
+ return found;
+ };
+ await expect
+ .poll(() => shapes()?.geometry.getAttribute('position').count ?? 0)
+ .toBeGreaterThan(12);
+ expect(instanced(scene).every((mesh) => mesh.count === 0)).toBe(true);
+ // Its corners cut in: the second bar's top-left corner isn't in its shape
+ const position = shapes().geometry.getAttribute('position');
+ const left = (chart!.xScale as any)('b');
+ const top = chart!.yScale(8);
+ let corner = false;
+ for (let i = 0; i < position.count; i++) {
+ if (Math.abs(position.getX(i) - left) < 0.01 && Math.abs(position.getZ(i) - top) < 0.01) {
+ corner = true;
+ }
+ }
+ expect(corner).toBe(false);
+ });
+
+ it('outlines `Bars` with a `strokeWidth` alone, as LayerChart’s bars', async () => {
+ const plain = await renderMarks({ mark: 'bars', chart: columns });
+ expect(segments(plain)).toBe(0);
+ const scene = await renderMarks({ mark: 'bars', chart: columns, bars: { strokeWidth: 1 } });
+ // Flat, only around each bar's top: its four sides
+ await expect.poll(() => segments(scene)).toBe(8);
+ });
+
it('outlines `Bin` cells around their tops and up their corners', async () => {
const scene = await renderMarks({
mark: 'bin',
@@ -2207,15 +2605,27 @@ describe('strokes, as LayerChart’s marks take them', () => {
await expect.poll(() => segments(scene)).toBe(2 * 12);
});
- it('draws `Contour` lines `strokeWidth` pixels wide', async () => {
- const scene = await renderMarks({
- mark: 'contour',
- chart: { xDomain: [0, 1], yDomain: [0, 1] },
- contour: { value: (x: number, y: number) => x + y, strokeWidth: 3 },
- });
- await expect.poll(() => segments(scene)).toBeGreaterThan(0);
- const lines = layered(scene).find((o) => (o as any).isLineSegments2) as any;
- expect(lines.material.linewidth).toBe(3);
+ it('draws `Contour` lines `strokeWidth` pixels wide, raised or flat (with a `stroke`, as core)', async () => {
+ for (const contour of [
+ { value: (x: number, y: number) => x + y, strokeWidth: 3, z: 2, fill: 'none' },
+ // Flat, LayerChart's own (filled bands), outlined only with a `stroke`
+ { value: (x: number, y: number) => x + y, strokeWidth: 3, stroke: 'black' },
+ ]) {
+ const scene = await renderMarks({
+ mark: 'contour',
+ chart: { xDomain: [0, 1], yDomain: [0, 1] },
+ contour,
+ });
+ // Anywhere in the scene (flat, in the `Group` LayerChart's `Contour` draws in)
+ const lines = () => {
+ let found: any;
+ scene.root.traverse((o: any) => {
+ if (o.isLineSegments2 && o.visible && o.geometry.attributes.instanceStart) found ??= o;
+ });
+ return found;
+ };
+ await expect.poll(() => lines()?.material.linewidth).toBe(3);
+ }
});
it('draws a halo around `Text` lying on the surface, behind its letters', async () => {
@@ -2237,9 +2647,10 @@ describe('strokes, as LayerChart’s marks take them', () => {
});
const plain = await label();
const haloed = await label('white');
- // Room for the halo's outer half on every side: 4px wide at 4 canvas pixels a pixel
- expect(haloed.width - plain.width).toBe(16);
- expect(haloed.height - plain.height).toBe(16);
+ // Room for the halo's outer half on every side: 4px wide at 4 canvas pixels a pixel, painted
+ // a little wider (4.5px) as the label is painted a step larger (12px at ~13.5px) and shrunk
+ expect(haloed.width - plain.width).toBe(18);
+ expect(haloed.height - plain.height).toBe(18);
});
it('draws a halo around `viewport` labels, behind their letters', async () => {
diff --git a/packages/webgl/src/lib/components/parity-axis-2.svelte.test.ts b/packages/webgl/src/lib/components/parity-axis-2.svelte.test.ts
new file mode 100644
index 0000000000..ca8b44644c
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-axis-2.svelte.test.ts
@@ -0,0 +1,172 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { createRawSnippet } from 'svelte';
+import { pointRadial } from 'd3-shape';
+import type { Object3D } from 'three';
+import type { ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import AxisGrid from './__fixtures__/AxisGrid.svelte';
+
+type Props = Omit>[1], 'onScene'>;
+
+let chart: ChartState | undefined;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderAxes(props: Props) {
+ let scene: SceneState | undefined;
+ render(AxisGrid, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+/** Everything in the scene that `is` */
+function all(scene: SceneState, is: (o: any) => boolean) {
+ const found: any[] = [];
+ scene.root.traverse((o: Object3D) => {
+ if (is(o)) found.push(o);
+ });
+ return found;
+}
+const visibleLines = (scene: SceneState) =>
+ all(scene, (o) => o.isLineSegments2 && o.visible && o.geometry.attributes.instanceStart);
+
+/** A line set's segments, as `[x, y]` pairs across and down the plot */
+const segmentsOf = (lines: any): [number, number][][] => {
+ const start = lines.geometry.attributes.instanceStart;
+ const end = lines.geometry.attributes.instanceEnd;
+ return Array.from({ length: start.count }, (_, i) => [
+ [start.getX(i), start.getZ(i)],
+ [end.getX(i), end.getZ(i)],
+ ]);
+};
+
+/** A `tickLabel` (or `label`) snippet noting the props it's given, by `data-*` attributes */
+const noted = createRawSnippet((args: () => { props: any }) => ({
+ render: () => {
+ const { value, x, y, dx, dy, textAnchor, verticalAnchor, rotate } = args().props;
+ return ` `;
+ },
+}));
+/** The props each noted label was given, by its text */
+function notedLabels() {
+ return Object.fromEntries(
+ [...document.querySelectorAll('[data-parity-label]')].map((e) => [
+ e.dataset.parityLabel,
+ {
+ x: Number(e.dataset.x),
+ y: Number(e.dataset.y),
+ dx: Number(e.dataset.dx),
+ dy: Number(e.dataset.dy),
+ textAnchor: e.dataset.anchor,
+ verticalAnchor: e.dataset.vanchor,
+ rotate: Number(e.dataset.rotate),
+ },
+ ])
+ );
+}
+
+const flat = { xDomain: [0, 10], yDomain: [0, 10], padding: 20 };
+
+describe('Axis tick labels, as the core `Axis` places them', () => {
+ it("hangs `bottom`'s below the tick by their cap height, a tick and 2px down", async () => {
+ await renderAxes({
+ chart: flat,
+ axes: [{ placement: 'bottom', ticks: [0, 5], tickLabel: noted }],
+ });
+ await expect.poll(() => Object.keys(notedLabels())).toEqual(['0', '5']);
+ const five = notedLabels()['5'];
+ expect(five.y).toBeCloseTo(chart!.height);
+ expect(five.verticalAnchor).toBe('start');
+ expect(five.dy).toBeCloseTo(6);
+ });
+
+ it('takes `dx` / `dy` from `tickLabelProps` in place of its own offset', async () => {
+ await renderAxes({
+ chart: flat,
+ axes: [
+ {
+ placement: 'bottom',
+ ticks: [5],
+ tickLabelProps: { textAnchor: 'start', dx: 8, dy: 4 },
+ tickLabel: noted,
+ },
+ ],
+ });
+ await expect.poll(() => notedLabels()['5']?.dy).toBeCloseTo(4);
+ expect(notedLabels()['5']).toMatchObject({ dx: 8, textAnchor: 'start' });
+ });
+
+ it("turns a side's title to read up it, against the padding's edge", async () => {
+ await renderAxes({
+ chart: flat,
+ axes: [{ placement: 'right', ticks: [], label: noted }],
+ });
+ await expect.poll(() => notedLabels()['']?.rotate).toBe(-90);
+ const title = notedLabels()[''];
+ expect(title.x).toBeCloseTo(chart!.width + 20);
+ expect(title.y).toBeCloseTo(chart!.height / 2);
+ expect(title.verticalAnchor).toBe('end');
+ });
+});
+
+describe('Axis and Grid in a `radial` chart', () => {
+ const radial = { xDomain: [0, 100], yDomain: [0, 100], radial: true };
+
+ it("places `angle`'s labels around the rim, and `radius`' out from the center", async () => {
+ await renderAxes({
+ chart: radial,
+ center: true,
+ axes: [
+ { placement: 'angle', ticks: [25], tickLabel: noted },
+ { placement: 'radius', ticks: [50], tickLabel: noted },
+ ],
+ });
+ await expect.poll(() => Object.keys(notedLabels()).sort()).toEqual(['25', '50']);
+ const outer = chart!.height / 2;
+ const [x, y] = pointRadial(Math.PI / 2, outer);
+ expect(notedLabels()['25']).toMatchObject({ textAnchor: 'start', verticalAnchor: 'middle' });
+ expect(notedLabels()['25'].x).toBeCloseTo(x);
+ expect(notedLabels()['25'].y).toBeCloseTo(y);
+ expect(notedLabels()['50'].x).toBeCloseTo(0);
+ expect(notedLabels()['50'].y).toBeCloseTo(outer / 2);
+ });
+
+ it('draws spokes at the `x` ticks and circles at the `y` ticks', async () => {
+ const scene = await renderAxes({
+ chart: radial,
+ center: true,
+ grid: { x: true, xTicks: [0, 25, 50, 75], y: true, yTicks: [50, 100] },
+ });
+ await expect.poll(() => visibleLines(scene).length).toBe(2);
+ const outer = chart!.height / 2;
+ const distances = visibleLines(scene).map((lines) =>
+ segmentsOf(lines).flatMap((segment) => segment.map(([x, y]) => Math.hypot(x, y)))
+ );
+ // The spokes: from the center out to the rim
+ const spokes = distances.find((d) => d.length === 8)!;
+ expect(Math.min(...spokes)).toBeCloseTo(0);
+ expect(Math.max(...spokes)).toBeCloseTo(outer);
+ // The circles: every point at one of the two radii
+ const circles = distances.find((d) => d.length > 8)!;
+ expect(circles.every((r) => Math.abs(r - outer / 2) < 0.01 || Math.abs(r - outer) < 0.01)).toBe(
+ true
+ );
+ });
+});
+
+describe('Grid', () => {
+ it('draws only the lines asked for, as the core `Grid`', async () => {
+ const scene = await renderAxes({ chart: flat, grid: { x: true } });
+ await expect.poll(() => visibleLines(scene).length).toBe(1);
+ // Up and down the plot
+ const [[a, b]] = segmentsOf(visibleLines(scene)[0]);
+ expect(a[0]).toBeCloseTo(b[0]);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-geo-2.svelte.test.ts b/packages/webgl/src/lib/components/parity-geo-2.svelte.test.ts
new file mode 100644
index 0000000000..62ac15e8c8
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-geo-2.svelte.test.ts
@@ -0,0 +1,247 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { geoIdentity, geoMercatorRaw, geoProjection, type GeoRawProjection } from 'd3-geo';
+import { Color, Matrix4, Quaternion, Vector3, type InstancedMesh, type Object3D } from 'three';
+import type { ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Geo2 from './__fixtures__/Geo2.svelte';
+
+type Props = Omit>[1], 'onScene'>;
+
+let chart: ChartState | undefined;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderGeo(props: Props) {
+ let scene: SceneState | undefined;
+ render(Geo2, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+/** Every object under the scene's root */
+function all(scene: SceneState) {
+ const found: Object3D[] = [];
+ scene.root.traverse((o) => void (o !== scene.root && found.push(o)));
+ return found;
+}
+const instanced = (scene: SceneState) =>
+ all(scene).filter((o) => (o as any).isInstancedMesh && (o as any).count > 0) as InstancedMesh[];
+/** Outlines with segments drawn */
+const outlines = (scene: SceneState) =>
+ all(scene).filter(
+ (o) =>
+ (o as any).isLineSegments2 &&
+ o.visible &&
+ ((o as any).geometry.attributes.instanceStart?.count ?? 0) > 0
+ );
+const fills = (scene: SceneState) =>
+ all(scene).filter(
+ (o) => (o as any).isMesh && !(o as any).isInstancedMesh && !(o as any).isLineSegments2
+ ) as any[];
+
+/** An instance's center on the plot (across, down, and up), through the groups it's in */
+function placed(mesh: InstancedMesh, i = 0, scene?: SceneState) {
+ const matrix = new Matrix4();
+ mesh.getMatrixAt(i, matrix);
+ // Through the groups between it and the scene's root
+ mesh.updateWorldMatrix(true, false);
+ matrix.premultiply(mesh.matrixWorld);
+ if (scene) matrix.premultiply(scene.root.matrixWorld.clone().invert());
+ const position = new Vector3();
+ const size = new Vector3();
+ matrix.decompose(position, new Quaternion(), size);
+ return { x: position.x, y: position.z, z: position.y, r: size.x };
+}
+
+const geo = { geo: { projection: geoIdentity } };
+
+describe('GeoPoint', () => {
+ it('draws a circle at its point through the projection', async () => {
+ const scene = await renderGeo({
+ mark: 'geopoint',
+ chart: geo,
+ geopoint: { lat: 50, long: 100, r: 5 },
+ });
+ await expect.poll(() => instanced(scene).length).toBeGreaterThan(0);
+ const at = placed(instanced(scene)[0], 0, scene);
+ const [px, py] = chart!.geo.projection!([100, 50])!;
+ expect([at.x, at.y]).toEqual([expect.closeTo(px), expect.closeTo(py)]);
+ });
+
+ it('places its `children` at its point, as in an `Svg` layer', async () => {
+ const scene = await renderGeo({
+ mark: 'geopoint-children',
+ chart: geo,
+ geopoint: { lat: 50, long: 100 },
+ });
+ await expect.poll(() => instanced(scene).length).toBeGreaterThan(0);
+ const at = placed(instanced(scene)[0], 0, scene);
+ const [px, py] = chart!.geo.projection!([100, 50])!;
+ expect([at.x, at.y]).toEqual([expect.closeTo(px), expect.closeTo(py)]);
+ });
+});
+
+describe('Hull', () => {
+ it('outlines its rows on a map', async () => {
+ const scene = await renderGeo({
+ mark: 'hull',
+ chart: {
+ ...geo,
+ x: 'long',
+ y: 'lat',
+ data: [
+ { long: 10, lat: 10 },
+ { long: 40, lat: 10 },
+ { long: 30, lat: 40 },
+ ],
+ },
+ hull: { stroke: 'red' },
+ });
+ await expect.poll(() => outlines(scene).length).toBeGreaterThan(0);
+ });
+});
+
+describe('GeoPath', () => {
+ const square = {
+ type: 'Polygon' as const,
+ coordinates: [
+ [
+ [10, 10],
+ [10, 50],
+ [50, 50],
+ [50, 10],
+ [10, 10],
+ ],
+ ],
+ };
+
+ it('draws no outline for a class of `stroke: none`', async () => {
+ const scene = await renderGeo({
+ mark: 'geopath',
+ chart: geo,
+ geopath: { geojson: square, class: 'geo2-fill-red geo2-stroke-none' },
+ });
+ await expect.poll(() => fills(scene).length).toBeGreaterThan(0);
+ expect(outlines(scene)).toHaveLength(0);
+ });
+
+ it('stops at a point the projection can’t place, as an SVG path does', async () => {
+ // A raw Mercator, with no clip extent, sends the pole off to infinity
+ const scene = await renderGeo({
+ mark: 'geopath',
+ chart: {
+ geo: {
+ projection: () => geoProjection(geoMercatorRaw as unknown as GeoRawProjection).scale(30),
+ },
+ },
+ geopath: {
+ geojson: {
+ type: 'Polygon',
+ coordinates: [
+ [
+ [-20, -60],
+ [20, -60],
+ [20, -90],
+ [-20, -60],
+ ],
+ ],
+ },
+ fill: 'red',
+ },
+ });
+ await expect.poll(() => fills(scene).length).toBeGreaterThan(0);
+ const positions = Array.from(
+ fills(scene)[0].geometry.attributes.position.array as Float32Array
+ );
+ expect(positions.every(Number.isFinite)).toBe(true);
+ });
+});
+
+describe('Vector', () => {
+ it('takes a `class` of the row', async () => {
+ const scene = await renderGeo({
+ mark: 'vector',
+ chart: { xDomain: [0, 10], yDomain: [0, 10] },
+ vector: {
+ data: [
+ { x: 2, y: 5, party: 'a' },
+ { x: 8, y: 5, party: 'b' },
+ ],
+ x: 'x',
+ y: 'y',
+ length: 30,
+ shape: 'arrow-filled',
+ class: (d: any) => (d.party === 'a' ? 'geo2-fill-red' : 'geo2-fill-blue'),
+ },
+ });
+ const colors = () => {
+ const mesh = fills(scene)[0];
+ const color = mesh?.geometry.attributes.color;
+ if (!color) return [];
+ const seen = new Set();
+ for (let i = 0; i < color.count; i++) {
+ seen.add(new Color(color.getX(i), color.getY(i), color.getZ(i)).getHexString());
+ }
+ return [...seen].sort();
+ };
+ await expect.poll(colors).toEqual(['0000ff', 'ff0000']);
+ });
+});
+
+describe('Circle', () => {
+ it('draws no ring for a `stroke` of `none`', async () => {
+ const scene = await renderGeo({
+ mark: 'circle',
+ chart: {},
+ circle: { cx: 100, cy: 50, r: 10, stroke: 'none' },
+ });
+ await expect.poll(() => instanced(scene).length).toBe(1);
+ });
+
+ it('is raised by the chart’s `z` in data mode, as the core `Circle`', async () => {
+ const scene = await renderGeo({
+ mark: 'circle',
+ chart: {
+ data: [{ x: 5, y: 5, z: 10 }],
+ x: 'x',
+ y: 'y',
+ z: 'z',
+ xDomain: [0, 10],
+ yDomain: [0, 10],
+ zDomain: [0, 10],
+ zRange: [0, 100],
+ },
+ circle: { cx: 'x', cy: 'y', r: 4 },
+ });
+ await expect.poll(() => instanced(scene).length).toBeGreaterThan(0);
+ expect(placed(instanced(scene)[0], 0, scene).z).toBeCloseTo(100);
+ });
+});
+
+describe('Points', () => {
+ it('draws a point at each value of an `x` of several, as the core `Points`', async () => {
+ const scene = await renderGeo({
+ mark: 'points',
+ chart: {
+ data: [
+ { start: 2, end: 6, name: 'a' },
+ { start: 4, end: 9, name: 'b' },
+ ],
+ x: ['start', 'end'],
+ y: 'name',
+ xDomain: [0, 10],
+ },
+ points: {},
+ });
+ await expect.poll(() => instanced(scene)[0]?.count).toBe(4);
+ const across = [0, 1, 2, 3].map((i) => placed(instanced(scene)[0], i, scene).x);
+ expect(across).toEqual([2, 6, 4, 9].map((v) => expect.closeTo(chart!.xScale(v))));
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-lines.svelte.test.ts b/packages/webgl/src/lib/components/parity-lines.svelte.test.ts
new file mode 100644
index 0000000000..85119564bf
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-lines.svelte.test.ts
@@ -0,0 +1,363 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { geoIdentity } from 'd3-geo';
+import type { Object3D } from 'three';
+import type { ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Lines from './__fixtures__/Lines.svelte';
+
+type Props = Omit>[1], 'onScene'>;
+
+let chart: ChartState | undefined;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderLines(props: Props) {
+ let scene: SceneState | undefined;
+ const result = render(Lines, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return {
+ scene: scene!,
+ rerender: (next: Props) => result.rerender({ ...(next as any), onScene: () => {} }),
+ };
+}
+
+/** Each mark's own group of objects, in the order they're declared */
+const layers = (scene: SceneState) => scene.root.children.filter((o) => o.userData.layer);
+/** A layer's outlines, and its filled mesh */
+const linesOf = (layer: Object3D | undefined) =>
+ layer?.children.find((o) => (o as any).isLineSegments2) as any;
+const meshOf = (layer: Object3D | undefined) =>
+ layer?.children.find((o) => (o as any).isMesh && !(o as any).isLineSegments2) as any;
+
+/** A layer's outline segments, as `[x, y]` pairs across and down the plot */
+const segments = (layer: Object3D | undefined): [number, number][][] => {
+ const lines = linesOf(layer);
+ if (!lines?.visible) return [];
+ const start = lines.geometry.attributes.instanceStart;
+ const end = lines.geometry.attributes.instanceEnd;
+ return Array.from({ length: start?.count ?? 0 }, (_, i) => [
+ [start.getX(i), start.getZ(i)],
+ [end.getX(i), end.getZ(i)],
+ ]);
+};
+
+/** The extent of a layer's filled mesh along an axis (`0` across, `2` down the plot) */
+const extent = (layer: Object3D | undefined, axis: number): [number, number] => {
+ const array = meshOf(layer)?.geometry.attributes.position?.array as Float32Array | undefined;
+ const values = Array.from(array ?? []).filter((_, i) => i % 3 === axis);
+ return values.length ? [Math.min(...values), Math.max(...values)] : [NaN, NaN];
+};
+
+const tween = { type: 'tween' as const, duration: 400 };
+
+describe('Line, as the core `Line`', () => {
+ const across = { x1: 100, y1: 50, x2: 200, y2: 50 };
+
+ it('eases from `initialX1` with `motion`', async () => {
+ const { scene } = await renderLines({
+ mark: 'line',
+ line: { ...across, initialX1: 0, motion: tween },
+ });
+ const startX = () => segments(layers(scene)[0])[0]?.[0][0] ?? NaN;
+ // On its way from its initial start...
+ await expect.poll(() => startX() > 1 && startX() < 99).toBe(true);
+ // ...to where it's asked to be
+ await expect.poll(startX).toBeCloseTo(100);
+ });
+
+ it('eases a row to its new place by its `key`, appearing where it is', async () => {
+ const props = (x: number): Props => ({
+ mark: 'line',
+ chart: { xDomain: [0, 10], yDomain: [0, 10] },
+ line: {
+ data: [{ id: 'a', x }],
+ key: (d: any) => d.id,
+ x1: 'x',
+ y1: 10,
+ x2: 'x',
+ y2: 100,
+ initialX1: 0,
+ motion: tween,
+ },
+ });
+ const { scene, rerender } = await renderLines(props(2));
+ const startX = () => segments(layers(scene)[0])[0]?.[0][0] ?? NaN;
+ // At once where it's first asked to be (its `initial` ends are for pixel mode)
+ await expect.poll(startX).toBeCloseTo(chart!.xScale(2));
+ await rerender(props(8));
+ const [from, to] = [chart!.xScale(2), chart!.xScale(8)];
+ await expect.poll(() => startX() > from + 1 && startX() < to - 1).toBe(true);
+ await expect.poll(startX).toBeCloseTo(to);
+ });
+
+ it('dashes with `dashArray`, solid without', async () => {
+ const plain = await renderLines({ mark: 'line', line: across });
+ await expect.poll(() => segments(layers(plain.scene)[0]).length).toBe(1);
+ expect(linesOf(layers(plain.scene)[0]).material.dashed).toBe(false);
+
+ const { scene } = await renderLines({ mark: 'line', line: { ...across, dashArray: '4 2' } });
+ const material = () => linesOf(layers(scene)[0])?.material;
+ await expect.poll(() => material()?.dashed).toBe(true);
+ expect(material().dashSize).toBeCloseTo(4 * scene.unit);
+ expect(material().gapSize).toBeCloseTo(2 * scene.unit);
+ });
+
+ it('dims its stroke by `strokeOpacity`', async () => {
+ const { scene } = await renderLines({
+ mark: 'line',
+ line: { ...across, strokeOpacity: 0.5, opacity: 0.5 },
+ });
+ await expect.poll(() => linesOf(layers(scene)[0])?.material.opacity).toBeCloseTo(0.25);
+ });
+
+ it('adds nothing without a marker', async () => {
+ const { scene } = await renderLines({ mark: 'line', line: across });
+ await expect.poll(() => segments(layers(scene)[0]).length).toBe(1);
+ expect(layers(scene)).toHaveLength(1);
+ });
+
+ it('draws a `markerEnd` triangle with its tip at the end, pointing along the line', async () => {
+ const { scene } = await renderLines({
+ mark: 'line',
+ line: { ...across, markerEnd: 'triangle' },
+ });
+ await expect.poll(() => layers(scene).length).toBe(2);
+ const marker = () => layers(scene)[1];
+ await expect.poll(() => meshOf(marker())?.geometry.attributes.position?.count ?? 0).toBe(3);
+ // As the core `Marker`: 10px, its tip a pixel past the end (`refX` 9)
+ expect(extent(marker(), 0)[0]).toBeCloseTo(191);
+ expect(extent(marker(), 0)[1]).toBeCloseTo(201);
+ expect(extent(marker(), 2)[0]).toBeCloseTo(45);
+ expect(extent(marker(), 2)[1]).toBeCloseTo(55);
+ });
+
+ it('turns a `markerStart` back from the line (`auto-start-reverse`)', async () => {
+ const { scene } = await renderLines({
+ mark: 'line',
+ line: { ...across, markerStart: 'triangle' },
+ });
+ await expect
+ .poll(() => meshOf(layers(scene)[1])?.geometry.attributes.position?.count ?? 0)
+ .toBe(3);
+ expect(extent(layers(scene)[1], 0)[0]).toBeCloseTo(99);
+ expect(extent(layers(scene)[1], 0)[1]).toBeCloseTo(109);
+ });
+
+ it('draws an `arrow` marker as lines, and `marker` at both ends', async () => {
+ const { scene } = await renderLines({
+ mark: 'line',
+ line: { ...across, marker: { type: 'arrow', size: 20 } },
+ });
+ // Its start's and its end's (a straight line has no mid points)
+ await expect.poll(() => layers(scene).length).toBe(4);
+ const end = layers(scene)[3];
+ await expect.poll(() => segments(end).length).toBe(2);
+ // 20px: from 18px back of the end to 2px past it
+ const xs = segments(end)
+ .flat()
+ .map(([x]) => x);
+ expect(Math.min(...xs)).toBeCloseTo(182);
+ expect(Math.max(...xs)).toBeCloseTo(202);
+ expect(segments(layers(scene)[2])).toEqual([]);
+ });
+});
+
+describe('Path, as the core `Path`', () => {
+ it('dims its outline by `strokeOpacity`, not its fill', async () => {
+ const { scene } = await renderLines({
+ mark: 'path',
+ path: { pathData: 'M0,0L100,0L100,100Z', fill: 'red', stroke: 'black', strokeOpacity: 0.5 },
+ });
+ await expect.poll(() => linesOf(layers(scene)[0])?.material.opacity).toBeCloseTo(0.5);
+ expect(meshOf(layers(scene)[0]).material.opacity).toBeCloseTo(1);
+ });
+
+ it('draws a `markerMid` at each vertex between its ends', async () => {
+ const { scene } = await renderLines({
+ mark: 'path',
+ path: { pathData: 'M0,0L50,0L50,50L100,50', markerMid: 'dot' },
+ });
+ await expect.poll(() => layers(scene).length).toBe(2);
+ const mid = layers(scene)[1];
+ // Two dots, a circle 10px across about each corner
+ await expect.poll(() => extent(mid, 0)[0]).toBeCloseTo(45);
+ expect(extent(mid, 0)[1]).toBeCloseTo(55);
+ expect(extent(mid, 2)[0]).toBeCloseTo(-5);
+ expect(extent(mid, 2)[1]).toBeCloseTo(55);
+ });
+
+ it('draws only where its commands end on a curve, not its every piece', async () => {
+ const { scene } = await renderLines({
+ mark: 'path',
+ path: { pathData: 'M0,0C30,0 30,50 60,50L120,50', markerMid: 'dot' },
+ });
+ await expect
+ .poll(() => meshOf(layers(scene)[1])?.geometry.attributes.position?.count ?? 0)
+ .toBeGreaterThan(0);
+ // One dot, at the curve's end
+ expect(extent(layers(scene)[1], 0)).toEqual([expect.closeTo(55, 1), expect.closeTo(65, 1)]);
+ });
+
+ it('draws its outline from its start with `draw`', async () => {
+ const { scene } = await renderLines({
+ mark: 'path',
+ path: { pathData: 'M0,0L200,0', draw: { duration: 400 } },
+ });
+ const reach = () =>
+ Math.max(
+ ...segments(layers(scene)[0])
+ .flat()
+ .map(([x]) => x),
+ 0
+ );
+ await expect.poll(() => reach() > 10 && reach() < 190).toBe(true);
+ await expect.poll(reach).toBeCloseTo(200);
+ });
+
+ it('gives `startContent` / `endContent` its first and last points', async () => {
+ const seen: Record = {};
+ await renderLines({
+ mark: 'path',
+ chart: { xDomain: [0, 10], yDomain: [0, 10] },
+ path: { pathData: 'M10,20L200,40' },
+ onContent: (at: string, props: { point: DOMPoint; value: any }) => (seen[at] = props),
+ });
+ await expect.poll(() => seen.end?.point.x).toBeCloseTo(200);
+ expect(seen.end.point.y).toBeCloseTo(40);
+ expect([seen.start.point.x, seen.start.point.y]).toEqual([10, 20]);
+ expect(seen.end.value.x).toBeCloseTo((chart!.xScale as any).invert(200));
+ });
+});
+
+describe('Link, as the core `Link`', () => {
+ it('draws a `sankey` link from its source’s right edge to its target’s left', async () => {
+ const { scene } = await renderLines({
+ mark: 'link',
+ link: {
+ sankey: true,
+ type: 'straight',
+ data: { source: { x0: 0, x1: 10 }, target: { x0: 100, x1: 110 }, y0: 20, y1: 60 },
+ },
+ });
+ await expect.poll(() => segments(layers(scene)[0]).length).toBe(1);
+ expect(segments(layers(scene)[0])[0]).toEqual([
+ [expect.closeTo(10), expect.closeTo(20)],
+ [expect.closeTo(100), expect.closeTo(60)],
+ ]);
+ });
+
+ it('draws a wide link as a ribbon of its width, not a line (so a translucent one is even)', async () => {
+ const data = { source: { x0: 0, x1: 10 }, target: { x0: 100, x1: 110 }, y0: 20, y1: 20 };
+ const filled = (scene: SceneState) => {
+ let count = 0;
+ scene.root.traverse((o: any) => {
+ if (o.isMesh && !o.isLineSegments2 && o.geometry?.getAttribute('position')?.count)
+ count += o.geometry.getAttribute('position').count;
+ });
+ return count;
+ };
+ const wide = await renderLines({
+ mark: 'link',
+ link: { sankey: true, type: 'straight', data, strokeWidth: 10, stroke: 'black' },
+ });
+ await expect.poll(() => filled(wide.scene)).toBeGreaterThan(0);
+ expect(segments(layers(wide.scene)[0])).toHaveLength(0);
+
+ const thin = await renderLines({
+ mark: 'link',
+ link: { sankey: true, type: 'straight', data, strokeWidth: 1, stroke: 'black' },
+ });
+ await expect.poll(() => segments(layers(thin.scene)[0]).length).toBe(1);
+ expect(filled(thin.scene)).toBe(0);
+ });
+
+ it('lays a `radial` link out by angle and radius about the origin', async () => {
+ const { scene } = await renderLines({
+ mark: 'link',
+ link: {
+ radial: true,
+ type: 'straight',
+ data: { source: { x: 0, y: 0 }, target: { x: Math.PI / 2, y: 50 } },
+ },
+ });
+ await expect.poll(() => segments(layers(scene)[0]).length).toBe(1);
+ // A quarter turn clockwise from up: straight across
+ expect(segments(layers(scene)[0])[0][1]).toEqual([expect.closeTo(50), expect.closeTo(0)]);
+ });
+
+ it('marks each link’s end with `markerEnd`, and a `square` link’s corners with `markerMid`', async () => {
+ const { scene } = await renderLines({
+ mark: 'link',
+ link: {
+ type: 'square',
+ data: [{ source: { x: 0, y: 0 }, target: { x: 100, y: 100 } }],
+ markerMid: 'square',
+ markerEnd: 'triangle',
+ },
+ });
+ await expect.poll(() => layers(scene).length).toBe(3);
+ await expect
+ .poll(() => meshOf(layers(scene)[1])?.geometry.attributes.position?.count ?? 0)
+ .toBeGreaterThan(0);
+ await expect
+ .poll(() => meshOf(layers(scene)[2])?.geometry.attributes.position?.count ?? 0)
+ .toBe(3);
+ // The triangle's tip at the target, a pixel past it
+ expect(extent(layers(scene)[2], 2)[1]).toBeCloseTo(101);
+ });
+});
+
+describe('Polygon and Vector, as the core marks', () => {
+ it('eases a `Polygon` from `initialCx` with `motion`', async () => {
+ const { scene } = await renderLines({
+ mark: 'polygon',
+ polygon: { cx: 200, initialCx: 0, cy: 100, r: 20, motion: tween },
+ });
+ const center = () => {
+ const [a, b] = extent(layers(scene)[0], 0);
+ return (a + b) / 2;
+ };
+ await expect.poll(() => center() > 5 && center() < 195).toBe(true);
+ await expect.poll(center).toBeCloseTo(200);
+ });
+
+ it('eases a `Vector`’s length from `initialLength` with `motion`', async () => {
+ const { scene } = await renderLines({
+ mark: 'vector',
+ vector: { x: 100, y: 100, length: 80, initialLength: 0, rotate: 90, motion: tween },
+ });
+ /** Its stem's length */
+ const length = () => {
+ const [[from, to] = [[0], [0]]] = segments(layers(scene)[0]);
+ return Math.abs(to[0] - from[0]);
+ };
+ await expect.poll(() => length() > 2 && length() < 78).toBe(true);
+ await expect.poll(length).toBeCloseTo(80);
+ });
+});
+
+describe('Graticule, as the core `Graticule`', () => {
+ it('draws its own `geojson` in place of the graticule’s', async () => {
+ const { scene } = await renderLines({
+ mark: 'graticule',
+ chart: { geo: { projection: geoIdentity } },
+ graticule: {
+ geojson: {
+ type: 'LineString',
+ coordinates: [
+ [0, 0],
+ [50, 0],
+ ],
+ },
+ },
+ });
+ await expect.poll(() => segments(layers(scene)[0]).length).toBe(1);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-marks.svelte.test.ts b/packages/webgl/src/lib/components/parity-marks.svelte.test.ts
new file mode 100644
index 0000000000..35713025cb
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-marks.svelte.test.ts
@@ -0,0 +1,392 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { Color, Matrix4, Quaternion, Vector3, type InstancedMesh, type Object3D } from 'three';
+
+import type { ChartState } from 'layerchart';
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Marks from './__fixtures__/Marks.svelte';
+
+let chart: ChartState | undefined;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderMarks(props: Omit>[1], 'onScene'>) {
+ let scene: SceneState | undefined;
+ const result = render(Marks, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return { scene: scene!, rerender: result.rerender };
+}
+
+/** The objects marks put in the scene, looking through each mark's own layer */
+const layered = (scene: SceneState) =>
+ scene.root.children.flatMap((o) => (o.userData.layer ? o.children : [o]));
+
+const instanced = (scene: SceneState) =>
+ layered(scene).filter((o: Object3D) => (o as any).isInstancedMesh) as InstancedMesh[];
+
+/** The merged meshes marks fill (not their outlines, nor instanced marks) */
+const fills = (scene: SceneState) =>
+ layered(scene).filter(
+ (o) => (o as any).isMesh && !(o as any).isInstancedMesh && !(o as any).isLineSegments2
+ ) as any[];
+
+const outlines = (scene: SceneState) =>
+ layered(scene).filter((o) => (o as any).isLineSegments2) as any[];
+
+/** An instance's center (across, down the plot) and radius */
+function placed(mesh: InstancedMesh, i = 0) {
+ const matrix = new Matrix4();
+ mesh.getMatrixAt(i, matrix);
+ const position = new Vector3();
+ const size = new Vector3();
+ matrix.decompose(position, new Quaternion(), size);
+ return { x: position.x, y: position.z, r: size.x };
+}
+
+const tween = { type: 'tween' as const, duration: 400 };
+
+/** Two series, each with rows of its own, side by side (not stacked) */
+const seriesChart = {
+ x: 'x',
+ y: 'v',
+ xDomain: [0, 10],
+ yDomain: [0, 10],
+ seriesLayout: 'overlap' as const,
+ series: [
+ {
+ key: 'a',
+ color: 'rgb(255, 0, 0)',
+ value: 'v',
+ data: [
+ { x: 0, v: 2 },
+ { x: 10, v: 2 },
+ ],
+ },
+ {
+ key: 'b',
+ color: 'rgb(0, 0, 255)',
+ value: 'v',
+ data: [
+ { x: 0, v: 8 },
+ { x: 10, v: 8 },
+ ],
+ },
+ ],
+};
+
+describe('Circle, with the core `Circle`’s props', () => {
+ it('eases in from `initialCx` and `initialR` with `motion`', async () => {
+ const { scene } = await renderMarks({
+ mark: 'circle',
+ chart: {},
+ circle: { cx: 100, cy: 50, r: 20, initialCx: 0, initialR: 0, motion: tween },
+ });
+ const now = () => placed(instanced(scene)[0]);
+ // On its way...
+ await expect.poll(() => now().r > 1 && now().r < 19).toBe(true);
+ expect(now().x).toBeLessThan(99);
+ // ...and there
+ await expect.poll(() => now().r).toBeCloseTo(20);
+ expect(now().x).toBeCloseTo(100);
+ expect(now().y).toBeCloseTo(50);
+ });
+
+ it('eases only the props its `motion` names', async () => {
+ const { scene } = await renderMarks({
+ mark: 'circle',
+ chart: {},
+ circle: { cx: 100, cy: 50, r: 20, initialCx: 0, initialR: 0, motion: { r: tween } },
+ });
+ const now = () => placed(instanced(scene)[0]);
+ await expect.poll(() => now().r > 1 && now().r < 19).toBe(true);
+ // Straight to its place, growing there
+ expect(now().x).toBeCloseTo(100);
+ });
+
+ it('draws its ring at `strokeOpacity`', async () => {
+ const { scene } = await renderMarks({
+ mark: 'circle',
+ chart: {},
+ circle: { cx: 100, cy: 50, r: 10, stroke: 'black', strokeOpacity: 0.25 },
+ });
+ await expect.poll(() => instanced(scene).length).toBe(2);
+ const [fill, ring] = instanced(scene);
+ expect((fill.material as any).opacity).toBe(1);
+ expect((ring.material as any).opacity).toBeCloseTo(0.25);
+ });
+});
+
+describe('Points, with the props the core `Points` takes from `Circle`', () => {
+ const rows = [
+ { x: 2, y: 2 },
+ { x: 7, y: 6 },
+ ];
+ const chartProps = { data: rows, x: 'x', y: 'y', xDomain: [0, 10], yDomain: [0, 10] };
+
+ it('grows each point in from `initialR` with `motion`', async () => {
+ const { scene } = await renderMarks({
+ mark: 'points',
+ chart: chartProps,
+ points: { r: 8, initialR: 0, motion: tween },
+ });
+ const mesh = () => instanced(scene)[0];
+ await expect.poll(() => mesh()?.count).toBe(2);
+ await expect.poll(() => placed(mesh(), 1).r > 0.5 && placed(mesh(), 1).r < 7.5).toBe(true);
+ await expect.poll(() => placed(mesh(), 1).r).toBeCloseTo(8);
+ expect(placed(mesh(), 1).x).toBeCloseTo(chart!.xScale(7));
+ });
+
+ it('eases each point to its new place by its `key`', async () => {
+ const { scene, rerender } = await renderMarks({
+ mark: 'points',
+ chart: chartProps,
+ points: { data: [{ id: 'a', x: 2, y: 5 }], key: (d: any) => d.id, motion: tween },
+ });
+ const across = () => placed(instanced(scene)[0]).x;
+ await expect.poll(across).toBeCloseTo(chart!.xScale(2));
+ await rerender({
+ points: { data: [{ id: 'a', x: 8, y: 5 }], key: (d: any) => d.id, motion: tween },
+ });
+ await expect.poll(() => across() > chart!.xScale(2) + 1).toBe(true);
+ expect(across()).toBeLessThan(chart!.xScale(8) - 1);
+ await expect.poll(across).toBeCloseTo(chart!.xScale(8));
+ });
+
+ it('draws its `seriesKey`’s rows, in its color', async () => {
+ const { scene } = await renderMarks({
+ mark: 'points',
+ chart: seriesChart,
+ points: { seriesKey: 'b' },
+ });
+ const mesh = () => instanced(scene)[0];
+ await expect.poll(() => mesh()?.count).toBe(2);
+ expect(placed(mesh()).y).toBeCloseTo(chart!.yScale(8));
+ const color = new Color();
+ mesh().getColorAt(0, color);
+ expect([color.r, color.b]).toEqual([expect.closeTo(0), expect.closeTo(1)]);
+ });
+});
+
+describe('Spline and Area, with `seriesKey`', () => {
+ it('draws a `Spline` of its series’ rows, in its color, faded while another is highlighted', async () => {
+ const { scene } = await renderMarks({
+ mark: 'spline',
+ chart: seriesChart,
+ spline: { seriesKey: 'b' },
+ });
+ const line = () => layered(scene).find((o) => (o as any).isLine2) as any;
+ await expect.poll(() => line()).toBeTruthy();
+ const geometry = line().geometry;
+ expect(geometry.attributes.instanceStart.getZ(0)).toBeCloseTo(chart!.yScale(8));
+ expect(geometry.attributes.instanceColorStart.getX(0)).toBeCloseTo(0);
+ expect(geometry.attributes.instanceColorStart.getZ(0)).toBeCloseTo(1);
+ expect(line().material.opacity).toBe(1);
+
+ chart!.series.highlightKey = 'a';
+ await expect.poll(() => line().material.opacity).toBeCloseTo(0.1);
+ chart!.series.highlightKey = null;
+ await expect.poll(() => line().material.opacity).toBe(1);
+ });
+
+ it('fills an `Area` from its series’ rows, in its color', async () => {
+ const { scene } = await renderMarks({
+ mark: 'area',
+ chart: seriesChart,
+ area: { seriesKey: 'b' },
+ });
+ const mesh = () => fills(scene).find((m) => m.geometry.attributes.position?.count > 0);
+ await expect.poll(() => mesh()).toBeTruthy();
+ const positions = mesh().geometry.attributes.position.array as Float32Array;
+ const downs = Array.from({ length: positions.length / 3 }, (_, i) => positions[i * 3 + 2]);
+ // From its top (its series' value) down to the plot's bottom
+ expect(Math.min(...downs)).toBeCloseTo(chart!.yScale(8));
+ expect(Math.max(...downs)).toBeCloseTo(Math.max(...chart!.yRange));
+ const colors = mesh().geometry.attributes.color.array as Float32Array;
+ expect([colors[0], colors[2]]).toEqual([expect.closeTo(0), expect.closeTo(1)]);
+ });
+});
+
+describe('Area, with the core `Area`’s `stroke` and `pathData`', () => {
+ const chartProps = {
+ data: [
+ { x: 0, y: 4 },
+ { x: 10, y: 6 },
+ ],
+ x: 'x',
+ y: 'y',
+ xDomain: [0, 10],
+ yDomain: [0, 10],
+ };
+
+ it('outlines each area with `stroke`, around its top, its base, and its ends', async () => {
+ const { scene } = await renderMarks({ mark: 'area', chart: chartProps, area: {} });
+ await expect.poll(() => fills(scene).length).toBeGreaterThan(0);
+ expect(outlines(scene).every((o) => !o.visible)).toBe(true);
+
+ const outlined = await renderMarks({
+ mark: 'area',
+ chart: chartProps,
+ area: { stroke: 'rgb(255, 0, 0)' },
+ });
+ const lines = () => outlines(outlined.scene).find((o) => o.visible);
+ await expect.poll(() => lines()?.geometry.attributes.instanceStart.count).toBe(4);
+ const colors = lines().geometry.attributes.instanceColorStart;
+ expect([colors.getX(0), colors.getY(0)]).toEqual([expect.closeTo(1), expect.closeTo(0)]);
+ });
+
+ it('fills explicit `pathData` in place of its rows', async () => {
+ const { scene } = await renderMarks({
+ mark: 'area',
+ chart: chartProps,
+ area: { pathData: 'M10,10L110,10L110,60L10,60Z', fill: 'rgb(0, 255, 0)' },
+ });
+ const filled = () => fills(scene).filter((m) => m.geometry.attributes.position?.count > 0);
+ await expect.poll(() => filled().length).toBe(1);
+ const positions = filled()[0].geometry.attributes.position.array as Float32Array;
+ const across = Array.from({ length: positions.length / 3 }, (_, i) => positions[i * 3]);
+ expect([Math.min(...across), Math.max(...across)]).toEqual([
+ expect.closeTo(10),
+ expect.closeTo(110),
+ ]);
+ });
+});
+
+describe('Arc, with the core `Arc`’s `fillOpacity` and `strokeOpacity`', () => {
+ it('draws its fill and its outline each at its own opacity, under `opacity`', async () => {
+ const { scene } = await renderMarks({
+ mark: 'arc',
+ chart: {},
+ arc: {
+ value: 50,
+ stroke: 'black',
+ opacity: 0.5,
+ fillOpacity: 0.5,
+ strokeOpacity: 0.4,
+ },
+ });
+ const mesh = () => fills(scene).find((m) => m.geometry.attributes.position?.count > 0);
+ await expect.poll(() => mesh()?.material.opacity).toBeCloseTo(0.25);
+ const outline = outlines(scene).find((o) => o.visible);
+ expect(outline.material.opacity).toBeCloseTo(0.2);
+ });
+});
+
+describe('Rule, with `seriesKey`', () => {
+ it('fades while another series is highlighted, and hides with its series', async () => {
+ const { scene } = await renderMarks({
+ mark: 'rule',
+ chart: seriesChart,
+ rule: { y: 5, seriesKey: 'b' },
+ });
+ const line = () => outlines(scene)[0];
+ await expect.poll(() => line()?.visible).toBe(true);
+ expect(line().material.opacity).toBe(1);
+
+ chart!.series.highlightKey = 'a';
+ await expect.poll(() => line().material.opacity).toBeCloseTo(0.1);
+ chart!.series.highlightKey = null;
+
+ chart!.series.selectedKeys.current = ['a'];
+ await expect.poll(() => line().visible).toBe(false);
+ });
+});
+
+describe('Text, with the core `Text`’s props', () => {
+ /** The planes labels lying on the surface are painted on, in the order they're drawn */
+ const planes = (scene: SceneState) => {
+ const found: any[] = [];
+ scene.root.traverse((o: any) => {
+ if (o.isMesh && o.material?.map) found.push(o);
+ });
+ return found;
+ };
+
+ it('eases in from `initialX` with `motion`', async () => {
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, initialX: 0, value: 'hi', viewport: true, motion: tween },
+ });
+ const label = () => scene.labelSets.flat()[0];
+ await expect.poll(() => label()?.x > 1 && label()?.x < 99).toBe(true);
+ await expect.poll(() => label().x).toBeCloseTo(100);
+ expect(label().y).toBeCloseTo(50);
+ });
+
+ it('tweens a numeric `value` with a motion `{ type }`', async () => {
+ const { scene, rerender } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 0, format: 'integer', viewport: true, motion: tween },
+ });
+ const text = () => Number(scene.labelSets.flat()[0]?.text.replace(/,/g, ''));
+ await expect.poll(text).toBe(0);
+ await rerender({
+ text: { x: 100, y: 50, value: 1000, format: 'integer', viewport: true, motion: tween },
+ });
+ await expect.poll(() => text() > 0 && text() < 1000).toBe(true);
+ await expect.poll(text).toBe(1000);
+ });
+
+ it('draws `segments` facing the viewer side by side, each in its own classes', async () => {
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: {
+ x: 100,
+ y: 50,
+ segments: [{ value: 'Hello ' }, { value: 'world', class: 'font-bold' }],
+ textAnchor: 'start',
+ viewport: true,
+ },
+ });
+ await expect.poll(() => scene.labelSets.flat().length).toBe(2);
+ const [hello, world] = scene.labelSets.flat();
+ expect([hello.text, world.text]).toEqual(['Hello', 'world']);
+ expect(world.class).toContain('font-bold');
+ expect(hello.dx).toBe(0);
+ // Past `Hello ` (its space too)
+ expect(world.dx!).toBeGreaterThan(20);
+ expect([hello.textAnchor, world.textAnchor]).toEqual(['start', 'start']);
+ });
+
+ it('lays `segments` on the surface along one baseline', async () => {
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: {
+ x: 100,
+ y: 50,
+ segments: [{ value: 'Hello ' }, { value: 'world' }],
+ fontSize: 12,
+ textAnchor: 'middle',
+ },
+ });
+ await expect.poll(() => planes(scene).length).toBe(2);
+ const [hello, world] = planes(scene);
+ // Centered on the point as a whole (`textAnchor` `middle`), one after the other
+ expect(hello.position.x).toBeLessThan(100);
+ expect(world.position.x).toBeGreaterThan(100);
+ expect(world.position.z).toBeCloseTo(hello.position.z);
+ });
+
+ it('places a label lying on the surface by its `capHeight`', async () => {
+ const at = async (capHeight?: string) => {
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 'cap', fontSize: 12, verticalAnchor: 'start', capHeight },
+ });
+ await expect.poll(() => planes(scene).length).toBe(1);
+ return planes(scene)[0].position.z as number;
+ };
+ const natural = await at();
+ // Its cap height's top at its point: a taller cap height puts it further down
+ expect(await at('20px')).toBeCloseTo(natural + 20 - 0.71 * 12);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-paths.svelte.test.ts b/packages/webgl/src/lib/components/parity-paths.svelte.test.ts
new file mode 100644
index 0000000000..e1e8dd676b
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-paths.svelte.test.ts
@@ -0,0 +1,382 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { geoIdentity } from 'd3-geo';
+import { curveMonotoneX } from 'd3-shape';
+import type { Object3D } from 'three';
+import type { ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Paths from './__fixtures__/Paths.svelte';
+
+type Props = Omit>[1], 'onScene'>;
+
+let chart: ChartState | undefined;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderPaths(props: Props) {
+ let scene: SceneState | undefined;
+ render(Paths, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+/** Each mark's own group of objects, in the order they're declared */
+const layers = (scene: SceneState) => scene.root.children.filter((o) => o.userData.layer);
+/** A layer's outlines, and its filled mesh */
+const linesOf = (layer: Object3D | undefined) =>
+ layer?.children.find((o) => (o as any).isLineSegments2) as any;
+const meshOf = (layer: Object3D | undefined) =>
+ layer?.children.find((o) => (o as any).isMesh && !(o as any).isLineSegments2) as any;
+/** A `Spline`'s lines (shown ones) */
+const splines = (scene: SceneState) =>
+ layers(scene)
+ .flatMap((layer) => layer.children)
+ .filter((o) => (o as any).isLine2 && o.visible) as any[];
+
+/** Line segments' ends, as `[x, y]` pairs across and down the plot (with their height) */
+const segmentsOf = (lines: any): [number, number, number][][] => {
+ if (!lines?.visible) return [];
+ const start = lines.geometry.attributes.instanceStart;
+ const end = lines.geometry.attributes.instanceEnd;
+ return Array.from({ length: start?.count ?? 0 }, (_, i) => [
+ [start.getX(i), start.getZ(i), start.getY(i)],
+ [end.getX(i), end.getZ(i), end.getY(i)],
+ ]);
+};
+const segments = (layer: Object3D | undefined) => segmentsOf(linesOf(layer));
+/** The farthest across a set of segments reaches */
+const reach = (segs: [number, number, number][][]) => Math.max(...segs.flat().map(([x]) => x), 0);
+
+/** The extent of a layer's filled mesh along an axis (`0` across, `2` down the plot) */
+const extent = (layer: Object3D | undefined, axis: number): [number, number] => {
+ const array = meshOf(layer)?.geometry.attributes.position?.array as Float32Array | undefined;
+ const values = Array.from(array ?? []).filter((_, i) => i % 3 === axis);
+ return values.length ? [Math.min(...values), Math.max(...values)] : [NaN, NaN];
+};
+const meshCount = (layer: Object3D | undefined) =>
+ meshOf(layer)?.geometry.attributes.position?.count ?? 0;
+
+/** What a `startContent` / `endContent` is given */
+type Content = { point: DOMPoint; value: any };
+
+const domain = { xDomain: [0, 10], yDomain: [0, 10] };
+/** Five rows across the plot, the middle one missing its `y` */
+const gapped = [0, 1, 2, 3, 4].map((x) => ({ x, y: x === 2 ? null : 5 }));
+
+describe('Spline, as the core `Spline`', () => {
+ const flat = {
+ ...domain,
+ data: [
+ { x: 0, y: 5 },
+ { x: 10, y: 5 },
+ ],
+ x: 'x',
+ y: 'y',
+ };
+
+ it('draws its own `pathData` in place of its rows’ line', async () => {
+ const scene = await renderPaths({
+ mark: 'spline',
+ chart: flat,
+ spline: { pathData: 'M10,20L200,20', stroke: 'red' },
+ });
+ await expect
+ .poll(() => layers(scene).flatMap((layer) => segments(layer)))
+ .toEqual([
+ [
+ [expect.closeTo(10), expect.closeTo(20), expect.anything()],
+ [expect.closeTo(200), expect.closeTo(20), expect.anything()],
+ ],
+ ]);
+ expect(splines(scene)).toHaveLength(0);
+ });
+
+ it('draws its line from its start with `draw`', async () => {
+ const scene = await renderPaths({
+ mark: 'spline',
+ chart: flat,
+ spline: { draw: { duration: 1000 } },
+ });
+ const end = chart!.xScale(10);
+ const drawn = () => reach(splines(scene).flatMap(segmentsOf));
+ await expect.poll(() => drawn() > 10 && drawn() < end - 10).toBe(true);
+ await expect.poll(drawn).toBeCloseTo(end);
+ });
+
+ it('dims its line by `strokeOpacity`', async () => {
+ const scene = await renderPaths({
+ mark: 'spline',
+ chart: flat,
+ spline: { strokeOpacity: 0.5, opacity: 0.5 },
+ });
+ await expect.poll(() => splines(scene)[0]?.material.opacity).toBeCloseTo(0.25);
+ });
+
+ it('adds nothing without a marker or content', async () => {
+ const scene = await renderPaths({ mark: 'spline', chart: flat });
+ await expect.poll(() => splines(scene).length).toBe(1);
+ expect(layers(scene)).toHaveLength(1);
+ });
+
+ it('draws a `markerEnd` triangle with its tip at the line’s end', async () => {
+ const scene = await renderPaths({
+ mark: 'spline',
+ chart: flat,
+ spline: { markerEnd: 'triangle' },
+ });
+ await expect.poll(() => meshCount(layers(scene)[1])).toBe(3);
+ // A pixel past the end, along the line (`refX` 9 of 10)
+ expect(extent(layers(scene)[1], 0)[1]).toBeCloseTo(chart!.xScale(10) + 1);
+ expect(extent(layers(scene)[1], 2)[0]).toBeCloseTo(chart!.yScale(5) - 5);
+ });
+
+ it('draws a `markerMid` at each row between its ends, a gap’s ends too', async () => {
+ const scene = await renderPaths({
+ mark: 'spline',
+ chart: { xDomain: [0, 4], yDomain: [0, 10], data: gapped, x: 'x', y: 'y' },
+ spline: { markerMid: 'dot' },
+ });
+ await expect.poll(() => meshCount(layers(scene)[1])).toBeGreaterThan(0);
+ // Dots at rows 1 and 3, not the line's ends (rows 0 and 4)
+ expect(extent(layers(scene)[1], 0)).toEqual([
+ expect.closeTo(chart!.xScale(1) - 5),
+ expect.closeTo(chart!.xScale(3) + 5),
+ ]);
+ });
+
+ it('draws a `markerMid` only where a `curve`’s commands end', async () => {
+ const scene = await renderPaths({
+ mark: 'spline',
+ chart: {
+ ...domain,
+ data: [
+ { x: 0, y: 2 },
+ { x: 5, y: 8 },
+ { x: 10, y: 2 },
+ ],
+ x: 'x',
+ y: 'y',
+ },
+ spline: { curve: curveMonotoneX, markerMid: 'dot' },
+ });
+ await expect.poll(() => meshCount(layers(scene)[1])).toBeGreaterThan(0);
+ // One dot, at the middle row
+ expect(extent(layers(scene)[1], 0)).toEqual([
+ expect.closeTo(chart!.xScale(5) - 5),
+ expect.closeTo(chart!.xScale(5) + 5),
+ ]);
+ });
+
+ it('gives each line’s `startContent` / `endContent` its first and last points', async () => {
+ const seen: { at: string; point: DOMPoint; value: any }[] = [];
+ await renderPaths({
+ mark: 'spline',
+ chart: {
+ ...domain,
+ data: [
+ { k: 'a', x: 1, y: 2 },
+ { k: 'a', x: 9, y: 2 },
+ { k: 'b', x: 1, y: 6 },
+ { k: 'b', x: 9, y: 6 },
+ ],
+ x: 'x',
+ y: 'y',
+ },
+ spline: { g: 'k' },
+ onContent: (at: string, props: Content) => seen.push({ at, ...props }),
+ });
+ await expect.poll(() => seen.filter((s) => s.at === 'end').length).toBeGreaterThanOrEqual(2);
+ const ends = seen.filter((s) => s.at === 'end').map((s) => s.value.y);
+ expect(ends).toEqual(expect.arrayContaining([expect.closeTo(2), expect.closeTo(6)]));
+ const start = seen.find((s) => s.at === 'start')!;
+ expect(start.point.x).toBeCloseTo(chart!.xScale(1));
+ expect(start.value.x).toBeCloseTo(1);
+ });
+});
+
+describe('Area, as the core `Area`', () => {
+ const band = {
+ ...domain,
+ data: [
+ { x: 0, y: 5 },
+ { x: 10, y: 5 },
+ ],
+ x: 'x',
+ y: 'y',
+ };
+
+ it('dims its outline by `strokeOpacity`, not its fill or its line', async () => {
+ const scene = await renderPaths({
+ mark: 'area',
+ chart: band,
+ area: { stroke: 'black', strokeOpacity: 0.5, line: true },
+ });
+ await expect.poll(() => linesOf(layers(scene)[1])?.material.opacity).toBeCloseTo(0.5);
+ expect(meshOf(layers(scene)[0]).material.opacity).toBeCloseTo(1);
+ expect(linesOf(layers(scene)[0]).material.opacity).toBeCloseTo(1);
+ });
+
+ it('draws its outline from its start with `draw`', async () => {
+ const scene = await renderPaths({
+ mark: 'area',
+ chart: band,
+ area: { stroke: 'black', draw: { duration: 1000 } },
+ });
+ const outline = () => segments(layers(scene)[1]);
+ // Along its top first...
+ await expect
+ .poll(() => outline().length > 0 && reach(outline()) < chart!.xScale(10) - 1)
+ .toBe(true);
+ // ...then around it, closed
+ await expect.poll(() => outline().length).toBe(4);
+ });
+
+ it('marks its outline’s start with `markerStart`, and puts `endContent` where it closes', async () => {
+ const seen: Record = {};
+ const scene = await renderPaths({
+ mark: 'area',
+ chart: band,
+ area: { stroke: 'black', markerStart: 'dot' },
+ onContent: (at: string, props: Content) => (seen[at] = props),
+ });
+ await expect.poll(() => meshCount(layers(scene)[2])).toBeGreaterThan(0);
+ const [x0, y5] = [chart!.xScale(0), chart!.yScale(5)];
+ expect(extent(layers(scene)[2], 0)).toEqual([expect.closeTo(x0 - 5), expect.closeTo(x0 + 5)]);
+ expect(extent(layers(scene)[2], 2)).toEqual([expect.closeTo(y5 - 5), expect.closeTo(y5 + 5)]);
+ await expect.poll(() => seen.end?.point.x).toBeCloseTo(x0);
+ expect(seen.end.point.y).toBeCloseTo(y5);
+ });
+});
+
+describe('Link, as the core `Link`', () => {
+ const one = { source: { x: 0, y: 0 }, target: { x: 100, y: 100 } };
+
+ it('draws its own `pathData` in place of the path between its ends', async () => {
+ const scene = await renderPaths({
+ mark: 'link',
+ link: { data: one, pathData: 'M10,20L200,20' },
+ });
+ await expect.poll(() => segments(layers(scene)[0]).length).toBeGreaterThan(0);
+ const xs = segments(layers(scene)[0])
+ .flat()
+ .map(([x]) => x);
+ expect([Math.min(...xs), Math.max(...xs)]).toEqual([expect.closeTo(10), expect.closeTo(200)]);
+ });
+
+ it('draws each link from its start with `draw`', async () => {
+ const scene = await renderPaths({
+ mark: 'link',
+ link: { data: one, type: 'straight', draw: { duration: 1000 } },
+ });
+ const drawn = () => reach(segments(layers(scene)[0]));
+ await expect.poll(() => drawn() > 5 && drawn() < 95).toBe(true);
+ await expect.poll(drawn).toBeCloseTo(100);
+ });
+
+ it('raises each link by `z`', async () => {
+ const scene = await renderPaths({
+ mark: 'link',
+ link: { data: one, type: 'straight', z: 30 },
+ });
+ await expect.poll(() => segments(layers(scene)[0]).length).toBe(1);
+ // A little over it, as a link on the floor is
+ expect(segments(layers(scene)[0])[0][0][2]).toBeCloseTo(30);
+ });
+
+ it('fills a flat link with `fill`, and nothing without one', async () => {
+ const plain = await renderPaths({ mark: 'link', link: { data: one } });
+ await expect.poll(() => segments(layers(plain)[0]).length).toBeGreaterThan(0);
+ expect(meshCount(layers(plain)[0])).toBe(0);
+
+ const scene = await renderPaths({
+ mark: 'link',
+ link: { data: one, type: 'square', fill: 'red', fillOpacity: 0.5 },
+ });
+ await expect.poll(() => meshCount(layers(scene)[0])).toBeGreaterThan(0);
+ expect(meshOf(layers(scene)[0]).material.opacity).toBeCloseTo(0.5);
+ });
+
+ it('gives each link’s `startContent` / `endContent` its ends', async () => {
+ const seen: { at: string; point: DOMPoint }[] = [];
+ await renderPaths({
+ mark: 'link',
+ link: { data: [one, { source: { x: 0, y: 50 }, target: { x: 200, y: 50 } }] },
+ onContent: (at: string, props: Content) => seen.push({ at, ...props }),
+ });
+ await expect.poll(() => seen.filter((s) => s.at === 'end').length).toBeGreaterThanOrEqual(2);
+ const ends = seen.filter((s) => s.at === 'end').map((s) => s.point.x);
+ expect(ends).toEqual(expect.arrayContaining([expect.closeTo(100), expect.closeTo(200)]));
+ });
+});
+
+describe('GeoPath and Graticule, as the core marks', () => {
+ const geo = { geo: { projection: geoIdentity } };
+ /** Where the chart's projection puts a point */
+ const at = (point: [number, number]) => (chart as any).geo.projection(point) as [number, number];
+ const across = {
+ type: 'LineString' as const,
+ coordinates: [
+ [0, 0],
+ [50, 0],
+ [50, 50],
+ ],
+ };
+
+ it('draws its outlines from their start with `draw`', async () => {
+ const scene = await renderPaths({
+ mark: 'geoPath',
+ chart: geo,
+ geoPath: { geojson: across, draw: { duration: 1000 } },
+ });
+ const drawn = () => segments(layers(scene)[0]).length;
+ // Along its first side before it turns...
+ await expect
+ .poll(() => {
+ const segs = segments(layers(scene)[0]);
+ const [[x0], [x1]] = [at([0, 0]), at([50, 0])];
+ return segs.length === 1 && reach(segs) > x0 + 2 && reach(segs) < x1 - 2;
+ })
+ .toBe(true);
+ // ...then all of it
+ await expect.poll(drawn).toBe(2);
+ });
+
+ it('marks its line with `markerEnd` and `markerMid`, and gives `endContent` its end', async () => {
+ const seen: Record = {};
+ const scene = await renderPaths({
+ mark: 'geoPath',
+ chart: geo,
+ geoPath: { geojson: across, markerMid: 'dot', markerEnd: 'triangle' },
+ onContent: (at: string, props: Content) => (seen[at] = props),
+ });
+ await expect.poll(() => meshCount(layers(scene)[2])).toBe(3);
+ const [corner, end, start] = [at([50, 0]), at([50, 50]), at([0, 0])];
+ // The corner's dot, and the triangle's tip a pixel past the end, along the last side
+ expect(extent(layers(scene)[1], 0)).toEqual([
+ expect.closeTo(corner[0] - 5),
+ expect.closeTo(corner[0] + 5),
+ ]);
+ const tip = extent(layers(scene)[2], 2);
+ expect(end[1] > corner[1] ? tip[1] : tip[0]).toBeCloseTo(
+ end[1] + Math.sign(end[1] - corner[1])
+ );
+ await expect.poll(() => seen.end?.point.y).toBeCloseTo(end[1]);
+ expect(seen.start.point.x).toBeCloseTo(start[0]);
+ expect(seen.start.point.y).toBeCloseTo(start[1]);
+ });
+
+ it('passes `markerEnd` to a `Graticule`’s lines', async () => {
+ const scene = await renderPaths({
+ mark: 'graticule',
+ chart: geo,
+ graticule: { geojson: across, markerEnd: 'triangle' },
+ });
+ await expect.poll(() => meshCount(layers(scene)[1])).toBe(3);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-rects.svelte.test.ts b/packages/webgl/src/lib/components/parity-rects.svelte.test.ts
new file mode 100644
index 0000000000..90576fb8cb
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-rects.svelte.test.ts
@@ -0,0 +1,366 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { createRawSnippet } from 'svelte';
+import { scaleBand } from 'd3-scale';
+import { Color, Matrix4, Quaternion, Vector3, type InstancedMesh, type Object3D } from 'three';
+
+import type { ChartState } from 'layerchart';
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Marks from './__fixtures__/Marks.svelte';
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderMarks(props: Omit>[1], 'onScene'>) {
+ let scene: SceneState | undefined;
+ render(Marks, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+let chart: ChartState | undefined;
+
+/** The objects marks put in the scene, looking through each mark's own layer */
+const layered = (scene: SceneState) =>
+ scene.root.children.flatMap((o) => (o.userData.layer ? o.children : [o]));
+const instanced = (scene: SceneState) =>
+ layered(scene).filter((o: Object3D) => (o as any).isInstancedMesh) as InstancedMesh[];
+/** The first mesh with instances drawn */
+const drawn = (scene: SceneState) => instanced(scene).find((mesh) => mesh.count > 0);
+/** The visible line segments' objects */
+const lineSets = (scene: SceneState) =>
+ layered(scene).filter((o: any) => o.isLineSegments2 && o.visible !== false) as any[];
+
+/** Instance `i`'s corner and size, in the scene's axes */
+function box(mesh: InstancedMesh, i: number) {
+ const matrix = new Matrix4();
+ mesh.getMatrixAt(i, matrix);
+ const position = new Vector3();
+ const size = new Vector3();
+ matrix.decompose(position, new Quaternion(), size);
+ return { position, size };
+}
+
+/**
+ * Click the canvas over a point of the plot (in chart pixels) until `done`, as the scene takes a
+ * frame or two to place its camera
+ */
+async function clickAt(scene: SceneState, x: number, y: number, done: () => boolean) {
+ const canvas = document.querySelector('.lc-layout-webgl canvas') as HTMLCanvasElement;
+ await expect
+ .poll(() => {
+ const at = scene.project(x, y, 0);
+ if (at) {
+ const rect = canvas.getBoundingClientRect();
+ canvas.dispatchEvent(
+ new MouseEvent('click', {
+ clientX: rect.left + at.x,
+ clientY: rect.top + at.y,
+ bubbles: true,
+ })
+ );
+ }
+ return done();
+ })
+ .toBe(true);
+}
+
+const columns = {
+ data: [
+ { x: 'a', y: 4 },
+ { x: 'b', y: 8 },
+ ],
+ x: 'x',
+ xScale: scaleBand().padding(0.2),
+ xDomain: ['a', 'b'],
+ y: 'y',
+ yDomain: [0, 10],
+};
+
+/** The middle of column `x`'s bar, from the baseline to `value`, in chart pixels */
+const middleOf = (x: string, value: number) => {
+ const xScale = chart!.xScale as any;
+ return [xScale(x) + xScale.bandwidth() / 2, (chart!.yScale(0) + chart!.yScale(value)) / 2];
+};
+
+describe('Bars, as the core `Bars`', () => {
+ it('calls `onclick` with the row of the bar clicked', async () => {
+ const clicked: any[] = [];
+ const scene = await renderMarks({
+ mark: 'bars',
+ chart: columns,
+ bars: { onclick: (_e: MouseEvent, { data }: { data: any }) => clicked.push(data) } as any,
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ const [x, y] = middleOf('b', 8);
+ await clickAt(scene, x, y, () => clicked.length > 0);
+ expect(clicked[0]).toBe(columns.data[1]);
+ });
+
+ it('calls `onBarClick` with the row of the bar clicked', async () => {
+ const clicked: any[] = [];
+ const scene = await renderMarks({
+ mark: 'bars',
+ chart: columns,
+ bars: { onBarClick: (_e: MouseEvent, { data }: { data: any }) => clicked.push(data) },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ const [x, y] = middleOf('a', 4);
+ await clickAt(scene, x, y, () => clicked.length > 0);
+ expect(clicked[0]).toBe(columns.data[0]);
+ });
+
+ it('makes nothing pickable without a handler (or `tooltip`)', async () => {
+ const scene = await renderMarks({ mark: 'bars', chart: columns });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ expect(scene.pickables.size).toBe(0);
+ });
+
+ it('draws `fillOpacity` and `strokeOpacity` into the fill and outline', async () => {
+ const scene = await renderMarks({
+ mark: 'bars',
+ chart: columns,
+ bars: { fillOpacity: 0.4, strokeWidth: 1, strokeOpacity: 0.5, opacity: 0.5 },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ expect((drawn(scene)!.material as any).opacity).toBeCloseTo(0.2);
+ await expect.poll(() => lineSets(scene)[0]?.material.opacity).toBeCloseTo(0.25);
+ });
+
+ it('eases a new bar in from `initialY` and `initialHeight` with `motion`', async () => {
+ const scene = await renderMarks({
+ mark: 'bars',
+ chart: columns,
+ // Slow enough to see where it starts
+ bars: { motion: { type: 'tween', duration: 60_000 }, initialY: 10, initialHeight: 20 },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ const { position, size } = box(drawn(scene)!, 1);
+ expect(position.z).toBeCloseTo(10, 0);
+ expect(size.z).toBeCloseTo(20, 0);
+ });
+
+ it('takes a fixed `width`, centered in its band', async () => {
+ const scene = await renderMarks({ mark: 'bars', chart: columns, bars: { width: 10 } });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ const xScale = chart!.xScale as any;
+ const { position, size } = box(drawn(scene)!, 1);
+ expect(size.x).toBeCloseTo(10);
+ expect(position.x).toBeCloseTo(xScale('b') + xScale.bandwidth() / 2 - 5);
+ });
+
+ const fruit = {
+ data: [
+ { x: 'a', apples: 2, bananas: 3 },
+ { x: 'b', apples: 4, bananas: 1 },
+ ],
+ x: 'x',
+ xScale: scaleBand().padding(0.2),
+ xDomain: ['a', 'b'],
+ yDomain: [0, 10],
+ series: [
+ { key: 'apples', color: 'rgb(255, 0, 0)' },
+ { key: 'bananas', color: 'rgb(0, 0, 255)' },
+ ],
+ seriesLayout: 'stack' as const,
+ };
+
+ it("reads a series' stacked values with `seriesKey`, spaced by `stackPadding`", async () => {
+ const scene = await renderMarks({
+ mark: 'bars',
+ chart: fruit,
+ bars: { seriesKey: 'bananas', stackPadding: 4 },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ const { position, size } = box(drawn(scene)!, 0);
+ // On top of the apples, less half the padding beneath (the top of the stack keeps its edge)
+ expect(position.z).toBeCloseTo(chart!.yScale(5));
+ expect(size.z).toBeCloseTo(chart!.yScale(2) - chart!.yScale(5) - 2);
+ // In the series' color
+ const color = new Color();
+ drawn(scene)!.getColorAt(0, color);
+ expect(color.b).toBeGreaterThan(0.9);
+ expect(color.r).toBeLessThan(0.1);
+ });
+});
+
+describe('Bar, as the core `Bar`', () => {
+ it('is pickable with an `onpointerenter`, as `Bars` with one', async () => {
+ const scene = await renderMarks({
+ mark: 'bars',
+ chart: columns,
+ bars: { onpointerenter: () => {} } as any,
+ });
+ await expect.poll(() => scene.pickables.size).toBe(1);
+ });
+});
+
+describe('Rect, as the core `Rect`', () => {
+ const rows = [
+ { x0: 10, x1: 30, y0: 10, y1: 40 },
+ { x0: 50, x1: 90, y0: 20, y1: 60 },
+ ];
+ const chartProps = { data: rows, xDomain: [0, 100], yDomain: [0, 100] };
+
+ it('calls `onclick` with the row of the box clicked', async () => {
+ const clicked: any[] = [];
+ const scene = await renderMarks({
+ mark: 'rect',
+ chart: chartProps,
+ rect: {
+ x0: 'x0',
+ x1: 'x1',
+ y0: 'y0',
+ y1: 'y1',
+ onclick: (_e: MouseEvent, { data }: { data: any }) => clicked.push(data),
+ },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ const x = (chart!.xScale(50) + chart!.xScale(90)) / 2;
+ const y = (chart!.yScale(20) + chart!.yScale(60)) / 2;
+ await clickAt(scene, x, y, () => clicked.length > 0);
+ expect(clicked[0]).toBe(rows[1]);
+ });
+
+ it('calls a pixel-mode rect’s `onclick` without a row', async () => {
+ const clicked: any[] = [];
+ const scene = await renderMarks({
+ mark: 'rect',
+ chart: chartProps,
+ rect: {
+ x: 20,
+ y: 20,
+ width: 60,
+ height: 40,
+ onclick: (_e: MouseEvent, detail: { data: any }) => clicked.push(detail),
+ },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(1);
+ await clickAt(scene, 50, 40, () => clicked.length > 0);
+ expect(clicked[0].data).toBeUndefined();
+ });
+
+ it('shrinks each box by its `insets`', async () => {
+ const scene = await renderMarks({
+ mark: 'rect',
+ chart: chartProps,
+ rect: { x: 20, y: 20, width: 60, height: 40, insets: { x: 5, top: 2 } },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(1);
+ const { position, size } = box(drawn(scene)!, 0);
+ expect(position.x).toBeCloseTo(25);
+ expect(size.x).toBeCloseTo(50);
+ expect(position.z).toBeCloseTo(22);
+ expect(size.z).toBeCloseTo(38);
+ });
+
+ it('dashes its outline with `dashArray`, at `strokeOpacity`', async () => {
+ const scene = await renderMarks({
+ mark: 'rect',
+ chart: chartProps,
+ rect: {
+ x: 20,
+ y: 20,
+ width: 60,
+ height: 40,
+ stroke: 'black',
+ dashArray: '4 2',
+ strokeOpacity: 0.5,
+ },
+ });
+ await expect.poll(() => lineSets(scene)[0]?.material.dashed).toBe(true);
+ expect(lineSets(scene)[0].material.opacity).toBeCloseTo(0.5);
+ });
+
+ it('draws its sides unlit with `shade={false}`', async () => {
+ const scene = await renderMarks({
+ mark: 'rect',
+ chart: chartProps,
+ rect: { x: 20, y: 20, width: 60, height: 40, z: 20, shade: false },
+ });
+ await expect.poll(() => (drawn(scene)?.material as any)?.isMeshBasicMaterial).toBe(true);
+ });
+
+ it('eases in from `initialWidth` and `initialHeight` with `motion` (pixel mode)', async () => {
+ const scene = await renderMarks({
+ mark: 'rect',
+ chart: chartProps,
+ rect: {
+ x: 20,
+ y: 20,
+ width: 60,
+ height: 40,
+ initialWidth: 4,
+ initialHeight: 6,
+ motion: { type: 'tween', duration: 60_000 },
+ },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(1);
+ const { size } = box(drawn(scene)!, 0);
+ expect(size.x).toBeCloseTo(4, 0);
+ expect(size.z).toBeCloseTo(6, 0);
+ });
+});
+
+describe('Bin, as the core `Bin`', () => {
+ const rows = [...Array.from({ length: 5 }, () => ({ x: 1, y: 1 })), { x: 9, y: 9 }];
+ const chartProps = { data: rows, x: 'x', y: 'y', xDomain: [0, 10], yDomain: [0, 10] };
+
+ it('calls `onclick` with the cell clicked', async () => {
+ const clicked: any[] = [];
+ const scene = await renderMarks({
+ mark: 'bin',
+ chart: chartProps,
+ bin: { size: 40, onclick: (_e: MouseEvent, cell: any) => clicked.push(cell) },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ const x = chart!.xScale(1);
+ const y = chart!.yScale(1);
+ await clickAt(scene, x, y, () => clicked.length > 0);
+ expect(clicked[0].count).toBe(5);
+ });
+
+ it('draws `fillOpacity` into its cells', async () => {
+ const scene = await renderMarks({
+ mark: 'bin',
+ chart: chartProps,
+ bin: { size: 40, fillOpacity: 0.5, opacity: 0.8 },
+ });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ expect((drawn(scene)!.material as any).opacity).toBeCloseTo(0.4);
+ });
+
+ it('outlines every cell of the plot with `grid`', async () => {
+ const scene = await renderMarks({ mark: 'bin', chart: chartProps, bin: { size: 40 } });
+ await expect.poll(() => drawn(scene)?.count).toBe(2);
+ expect(lineSets(scene)).toHaveLength(0);
+
+ const gridded = await renderMarks({
+ mark: 'bin',
+ chart: chartProps,
+ bin: { size: 40, grid: { strokeOpacity: 0.5 } },
+ });
+ await expect
+ .poll(() => lineSets(gridded)[0]?.geometry.attributes.instanceStart?.count ?? 0)
+ .toBeGreaterThan(20);
+ });
+
+ it('hands `children` the cells to draw in their place', async () => {
+ const children = createRawSnippet((props: () => { cells: any[] }) => ({
+ render: () => ` `,
+ }));
+ const scene = await renderMarks({
+ mark: 'bin',
+ chart: chartProps,
+ bin: { size: 40, children },
+ });
+ await expect
+ .poll(() => document.querySelector('[data-cells]')?.getAttribute('data-cells'))
+ .toBe('2');
+ expect(instanced(scene).every((mesh) => mesh.count === 0)).toBe(true);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-scales.svelte.test.ts b/packages/webgl/src/lib/components/parity-scales.svelte.test.ts
new file mode 100644
index 0000000000..03fd765949
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-scales.svelte.test.ts
@@ -0,0 +1,593 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import { createRawSnippet } from 'svelte';
+import { scaleBand } from 'd3-scale';
+import { curveCatmullRomClosed, stack } from 'd3-shape';
+import { geoIdentity, geoMercator } from 'd3-geo';
+import { Color, type Object3D } from 'three';
+import { isometric, type BinCell, type ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Marks from './__fixtures__/Marks.svelte';
+import ParityScales from './__fixtures__/ParityScales.svelte';
+
+let chart: ChartState | undefined;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderMarks(props: Omit>[1], 'onScene'>) {
+ let scene: SceneState | undefined;
+ render(Marks, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+/** As `renderMarks`, for the marks `Marks.svelte` has no case for (`Grid`, `Raster`, ...) */
+async function renderOthers(
+ props: Omit>[1], 'onScene'>
+) {
+ let scene: SceneState | undefined;
+ render(ParityScales, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+/** The objects marks put in the scene, looking through each mark's own layer */
+const layered = (scene: SceneState) =>
+ scene.root.children.flatMap((o) => (o.userData.layer ? o.children : [o]));
+
+/** Everything in the scene that `is` */
+function all(scene: SceneState, is: (o: any) => boolean) {
+ const found: any[] = [];
+ scene.root.traverse((o: Object3D) => {
+ if (is(o)) found.push(o);
+ });
+ return found;
+}
+const visibleLines = (scene: SceneState) =>
+ all(scene, (o) => o.isLineSegments2 && o.visible && o.geometry.attributes.instanceStart);
+
+const square = {
+ type: 'Feature' as const,
+ properties: {},
+ // Clockwise, as d3-geo reads an outside ring
+ geometry: {
+ type: 'Polygon' as const,
+ coordinates: [
+ [
+ [10, 10],
+ [10, 100],
+ [100, 100],
+ [100, 10],
+ [10, 10],
+ ],
+ ],
+ },
+};
+
+describe('Contour', () => {
+ it('fades raised lines by `strokeOpacity` and `opacity`, and blurs the grid by `blur`', async () => {
+ const segmentsOf = async (blur: number) => {
+ const scene = await renderMarks({
+ mark: 'contour',
+ chart: { xDomain: [0, 1], yDomain: [0, 1] },
+ contour: {
+ // A ridge, which a blur spreads (and so moves its lines)
+ value: (x: number, _y: number) => (Math.abs(x - 0.5) < 0.05 ? 1 : 0),
+ thresholds: [0.5],
+ z: 2,
+ fill: 'none',
+ stroke: 'black',
+ strokeOpacity: 0.5,
+ opacity: 0.5,
+ blur,
+ },
+ });
+ await expect.poll(() => visibleLines(scene).length).toBeGreaterThan(0);
+ const [lines] = visibleLines(scene);
+ expect(lines.material.opacity).toBeCloseTo(0.25);
+ return Array.from(lines.geometry.attributes.instanceStart.data.array as Float32Array);
+ };
+ const sharp = await segmentsOf(0);
+ const blurred = await segmentsOf(4);
+ expect(blurred).not.toEqual(sharp);
+ });
+
+ it('raises lines by a function of the band, through the `z` scale', async () => {
+ const scene = await renderMarks({
+ mark: 'contour',
+ chart: { xDomain: [0, 1], yDomain: [0, 1], zDomain: [0, 10], zRange: [0, 100] },
+ contour: {
+ value: (x: number, _y: number) => x,
+ thresholds: [0.5],
+ z: (band: { value: number }) => band.value * 10,
+ fill: 'none',
+ stroke: 'black',
+ },
+ });
+ await expect.poll(() => visibleLines(scene).length).toBeGreaterThan(0);
+ const [lines] = visibleLines(scene);
+ const start = lines.geometry.attributes.instanceStart.data.array as Float32Array;
+ // `[x, height, y]`: 0.5 × 10 through the `z` scale, a pixel off the floor
+ expect(start[1]).toBeCloseTo(51);
+ });
+});
+
+describe('GeoPath', () => {
+ const meshOf = (scene: SceneState) => layered(scene).find((o: any) => o.isMesh) as any;
+ const linesOf = (scene: SceneState) => layered(scene).find((o: any) => o.isLineSegments2) as any;
+
+ it('fades its fill by `fillOpacity` and its outlines by `strokeOpacity`', async () => {
+ const scene = await renderMarks({
+ mark: 'geopath',
+ chart: { geo: { projection: geoIdentity } },
+ geopath: {
+ geojson: square,
+ fill: 'gray',
+ stroke: 'black',
+ fillOpacity: 0.5,
+ strokeOpacity: 0.25,
+ opacity: 0.8,
+ },
+ });
+ await expect.poll(() => meshOf(scene)?.material.opacity).toBeCloseTo(0.4);
+ expect(linesOf(scene).material.opacity).toBeCloseTo(0.2);
+ });
+
+ it('draws through `geoTransform` and `curve`, as the core `GeoPath`', async () => {
+ const extent = async (props: Record) => {
+ const scene = await renderMarks({
+ mark: 'geopath',
+ chart: { geo: { projection: geoIdentity } },
+ geopath: { geojson: square, stroke: 'black', ...props },
+ });
+ await expect.poll(() => linesOf(scene)?.visible).toBe(true);
+ const positions = linesOf(scene).geometry.attributes.instanceStart.data.array;
+ const xs = Array.from(positions as Float32Array).filter((_, i) => i % 3 === 0);
+ return { min: Math.min(...xs), count: xs.length };
+ };
+ const plain = await extent({});
+ const moved = await extent({
+ // The methods of a `geoTransform`, as the core `GeoPath` takes them
+ geoTransform: (projection: any) => ({
+ point(this: any, x: number, y: number) {
+ const [px, py] = projection([x, y]);
+ this.stream.point(px + 50, py);
+ },
+ }),
+ });
+ expect(moved.min - plain.min).toBeCloseTo(50);
+ // A curve's outline follows it in many short lines, rather than the square's four
+ const curved = await extent({ curve: curveCatmullRomClosed });
+ expect(curved.count).toBeGreaterThan(plain.count * 4);
+ });
+
+ it('calls `onclick` with the path generator and the feature', async () => {
+ const calls: any[] = [];
+ const scene = await renderMarks({
+ mark: 'geopath',
+ chart: { geo: { projection: geoIdentity } },
+ geopath: {
+ geojson: square,
+ fill: 'gray',
+ onclick: (_e: MouseEvent, geoPath: any, feature: any) => calls.push([geoPath, feature]),
+ },
+ });
+ await expect.poll(() => scene.pickables.size).toBeGreaterThan(0);
+ // The handler the mark registers, as the pointer calls it with the feature it's over
+ const [pickable] = [...scene.pickables];
+ pickable.events?.()?.onclick?.(new MouseEvent('click'), { data: square });
+ expect(calls).toHaveLength(1);
+ expect(typeof calls[0][0]).toBe('function');
+ expect(calls[0][0](square)).toMatch(/^M/);
+ expect(calls[0][1]).toBe(square);
+ });
+
+ it('draws `children` in its place, given the path generator', async () => {
+ const children = createRawSnippet((args: () => { geoPath: any }) => ({
+ render: () => ` `,
+ }));
+ const scene = await renderMarks({
+ mark: 'geopath',
+ chart: { geo: { projection: geoIdentity } },
+ geopath: { geojson: square, fill: 'gray', children },
+ });
+ await expect
+ .poll(() =>
+ document.querySelector('[data-parity-geopath]')?.getAttribute('data-parity-geopath')
+ )
+ .toBe('yes');
+ expect(meshOf(scene).geometry.getAttribute('position')?.count ?? 0).toBe(0);
+ });
+});
+
+describe('GeoTile', () => {
+ const solid = () => {
+ const canvas = document.createElement('canvas');
+ canvas.width = canvas.height = 256;
+ const context = canvas.getContext('2d')!;
+ context.fillStyle = 'rgb(10, 200, 30)';
+ context.fillRect(0, 0, 256, 256);
+ return canvas.toDataURL();
+ };
+ const image = solid();
+ const area = {
+ type: 'Feature' as const,
+ properties: {},
+ geometry: {
+ type: 'Polygon' as const,
+ coordinates: [
+ [
+ [-10, -10],
+ [-10, 10],
+ [10, 10],
+ [10, -10],
+ [-10, -10],
+ ],
+ ],
+ },
+ };
+ const meshes = (scene: SceneState) =>
+ all(scene, (o) => o.isMesh && !o.userData.backdrop && o.material?.map);
+
+ it('fades its tiles with its `group`', async () => {
+ const scene = await renderMarks({
+ mark: 'geotile',
+ chart: { geo: { projection: geoMercator, fitGeojson: area } },
+ geotile: { url: () => image, group: { opacity: 0.5 } },
+ });
+ await expect.poll(() => meshes(scene).length).toBeGreaterThan(0);
+ await expect.poll(() => meshes(scene)[0].material.opacity).toBeCloseTo(0.5);
+ });
+
+ it('draws `children` in place of the tiles, given them', async () => {
+ const children = createRawSnippet((args: () => { tiles: any[] }) => ({
+ render: () => ` `,
+ }));
+ const scene = await renderMarks({
+ mark: 'geotile',
+ chart: { geo: { projection: geoMercator, fitGeojson: area } },
+ geotile: { url: () => image, children },
+ });
+ await expect
+ .poll(() =>
+ Number(document.querySelector('[data-parity-tiles]')?.getAttribute('data-parity-tiles'))
+ )
+ .toBeGreaterThan(0);
+ expect(meshes(scene)).toHaveLength(0);
+ });
+});
+
+describe('Highlight', () => {
+ const data = [
+ { x: 'a', y: 3 },
+ { x: 'b', y: 5 },
+ ];
+ const chartProps = { data, x: 'x', y: 'y', xScale: scaleBand(), yDomain: [0, 10] };
+
+ it('draws the row’s `bar`, calling `onBarClick` with it', async () => {
+ const calls: any[] = [];
+ const scene = await renderMarks({
+ mark: 'highlight',
+ chart: chartProps,
+ highlight: {
+ data: data[1],
+ bar: { fill: 'red' },
+ onBarClick: (_e: MouseEvent, detail: { data: any }) => calls.push(detail.data),
+ },
+ });
+ await expect.poll(() => scene.pickables.size).toBeGreaterThan(0);
+ const [pickable] = [...scene.pickables].filter((p) => p.events?.()?.onclick);
+ pickable.events!()!.onclick!(new MouseEvent('click'), { data: data[1] });
+ expect(calls).toEqual([data[1]]);
+ });
+});
+
+describe('Highlight points', () => {
+ it('points each band of a stack (`y={[0, 1]}`) at its top, in its series’ color', async () => {
+ const keys = ['apples', 'bananas', 'oranges'];
+ const rows = [
+ { x: 1, apples: 2, bananas: 3, oranges: 4 },
+ { x: 2, apples: 1, bananas: 2, oranges: 3 },
+ ];
+ const series = stack().keys(keys)(rows);
+ const scene = await renderMarks({
+ mark: 'highlight',
+ chart: {
+ data: series,
+ flatData: series.flat(),
+ x: (d: any) => d.data.x,
+ y: [0, 1],
+ c: 'key',
+ cDomain: keys,
+ cRange: ['red', 'green', 'blue'],
+ xDomain: [0, 3],
+ yDomain: [0, 10],
+ },
+ highlight: { data: series[0][1], points: true },
+ });
+ await expect.poll(() => scene.markerSets.flat().length).toBe(3);
+ const markers = scene.markerSets.flat();
+ // Each band's top (1, then 1 + 2, then 1 + 2 + 3) at the hovered row's x
+ expect(markers.map((m) => Math.round(chart!.yScale.invert!(m.y)))).toEqual([1, 3, 6]);
+ expect(new Set(markers.map((m) => Math.round(m.x)))).toEqual(
+ new Set([Math.round(chart!.xScale(2))])
+ );
+ expect(markers.map((m) => m.fill)).toEqual(['red', 'green', 'blue']);
+ });
+});
+
+describe('Bin on an isometric floor', () => {
+ // A grid of rows, many on cells' edges
+ const data = Array.from({ length: 400 }, (_, i) => ({
+ x: (i % 20) * 5,
+ y: Math.floor(i / 20) * 5,
+ }));
+
+ /** The cells' counts, with the view turned to `rotate` */
+ async function countsAt(rotate: number) {
+ let cells: BinCell[] = [];
+ const children = createRawSnippet((args: () => { cells: BinCell[] }) => {
+ cells = args().cells;
+ return { render: () => ' ' };
+ });
+ await renderMarks({
+ mark: 'bin',
+ chart: {
+ data,
+ x: 'x',
+ y: 'y',
+ xDomain: [0, 100],
+ yDomain: [0, 100],
+ view: isometric({ rotate }),
+ },
+ bin: { size: 24, children } as any,
+ });
+ await expect.poll(() => cells.length).toBeGreaterThan(0);
+ return { counts: cells.map((cell) => cell.count).sort((a, b) => a - b), width: chart!.width };
+ }
+
+ it('holds the same cells as the view turns and the floor is refitted, as the core `Bin`', async () => {
+ const square = await countsAt(0);
+ const turned = await countsAt(45);
+ // The floor's refitted smaller turned, but measured against it laid flat, the cells are the same
+ expect(turned.width).not.toBeCloseTo(square.width, 0);
+ expect(turned.counts).toEqual(square.counts);
+ });
+});
+
+describe('Area by category', () => {
+ it('fades the other categories while the legend highlights one, as core’s', async () => {
+ const data = [
+ { x: 0, y: 1, c: 'a' },
+ { x: 1, y: 2, c: 'a' },
+ { x: 0, y: 2, c: 'b' },
+ { x: 1, y: 3, c: 'b' },
+ ];
+ const scene = await renderMarks({
+ mark: 'area',
+ chart: { data, x: 'x', y: 'y', c: 'c', cDomain: ['a', 'b'], cRange: ['red', 'blue'] },
+ area: { fill: 'c' },
+ });
+ /** The alphas the areas' fills are drawn with, one per category */
+ const alphas = () => {
+ const found = new Set();
+ scene.root.traverse((o: any) => {
+ const color = o.isMesh && o.geometry?.getAttribute('color');
+ if (color?.itemSize === 4)
+ for (let i = 0; i < color.count; i++) found.add(Math.round(color.getW(i) * 10) / 10);
+ });
+ return [...found].sort();
+ };
+ await expect.poll(alphas).toEqual([1]);
+ chart!.series.highlightKey = 'a';
+ await expect.poll(alphas).toEqual([0.1, 1]);
+ chart!.series.highlightKey = null;
+ await expect.poll(alphas).toEqual([1]);
+ });
+});
+
+describe('Points on an isometric floor', () => {
+ const shape = (scene: SceneState) => {
+ let type: string | undefined;
+ scene.root.traverse((o: any) => {
+ if (o.isInstancedMesh && o.count > 0) type ??= o.geometry.type;
+ });
+ return type;
+ };
+ const data = [{ x: 1, y: 1 }];
+ const chart = { data, x: 'x', y: 'y', xDomain: [0, 2], yDomain: [0, 2], view: isometric() };
+
+ it('lie flat on the floor, as core’s, unless `viewport` turns them to the viewer', async () => {
+ const flat = await renderMarks({ mark: 'points', chart, points: {} });
+ await expect.poll(() => shape(flat)).toBe('CircleGeometry');
+ const facing = await renderMarks({ mark: 'points', chart, points: { viewport: true } });
+ await expect.poll(() => shape(facing)).toBe('SphereGeometry');
+ });
+});
+
+describe('Highlight area', () => {
+ const data = [
+ { x: 'a', y: 3 },
+ { x: 'b', y: 5 },
+ ];
+
+ it('calls `onAreaClick` with the highlighted row', async () => {
+ const calls: any[] = [];
+ const scene = await renderMarks({
+ mark: 'highlight',
+ chart: { data, x: 'x', y: 'y', xScale: scaleBand(), yDomain: [0, 10] },
+ highlight: {
+ data: data[0],
+ area: true,
+ onAreaClick: (_e: MouseEvent, detail: { data: any }) => calls.push(detail.data),
+ },
+ });
+ await expect
+ .poll(() => [...scene.pickables].filter((p) => p.events?.()?.onclick).length)
+ .toBeGreaterThan(0);
+ const [pickable] = [...scene.pickables].filter((p) => p.events?.()?.onclick);
+ pickable.events!()!.onclick!(new MouseEvent('click'), { data: undefined });
+ expect(calls).toEqual([data[0]]);
+ });
+});
+
+describe('Axis', () => {
+ const flat = { data: [{ x: 1, y: 1 }], x: 'x', y: 'y', xDomain: [0, 10], yDomain: [0, 10] };
+ const viewportLabels = (scene: SceneState) => scene.labelSets.flat();
+
+ it('places its `label` by `labelPlacement`', async () => {
+ const xOf = async (labelPlacement: 'start' | 'middle' | 'end') => {
+ const scene = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: {
+ placement: 'bottom',
+ ticks: [],
+ label: 'x',
+ labelPlacement,
+ labelProps: { viewport: true },
+ },
+ });
+ await expect.poll(() => viewportLabels(scene).length).toBe(1);
+ return viewportLabels(scene)[0].x;
+ };
+ expect(await xOf('start')).toBeCloseTo(0);
+ expect(await xOf('middle')).toBeCloseTo(chart!.width / 2);
+ expect(await xOf('end')).toBeCloseTo(chart!.width);
+ });
+
+ it('ticks its own `domain`, and moves with `x` / `y` as a `Group`', async () => {
+ const scene = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: {
+ placement: 'left',
+ domain: [0, 100],
+ ticks: 2,
+ tickLabelProps: { viewport: true },
+ x: 20,
+ },
+ });
+ await expect.poll(() => viewportLabels(scene).map((l) => l.text)).toContain('100');
+ // On the left edge, moved 20 pixels across
+ expect(Math.round(viewportLabels(scene)[0].x)).toBe(20);
+ });
+
+ it('draws its tick marks in `stroke`, and tick labels through `tickLabel`', async () => {
+ const tickLabel = createRawSnippet((args: () => { props: any; index: number }) => ({
+ render: () => ` `,
+ }));
+ const scene = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'bottom', ticks: [0, 5, 10], stroke: 'rgb(255, 0, 0)', tickLabel },
+ });
+ await expect
+ .poll(() =>
+ [...document.querySelectorAll('[data-parity-tick]')].map((e) =>
+ e.getAttribute('data-parity-tick')
+ )
+ )
+ .toEqual(['0', '5', '10']);
+ const red = new Color('rgb(255, 0, 0)');
+ await expect
+ .poll(() => visibleLines(scene).some((l) => l.material.color.equals(red)))
+ .toBe(true);
+ });
+
+ it('dashes its `grid` lines by their `dashArray`', async () => {
+ const scene = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'left', ticks: [0, 5, 10], grid: { dashArray: 4 } },
+ });
+ await expect.poll(() => visibleLines(scene).some((l) => l.material.dashed)).toBe(true);
+ });
+});
+
+describe('Grid', () => {
+ const band = {
+ data: [{ x: 'a' }, { x: 'b' }, { x: 'c' }],
+ x: 'x',
+ xScale: scaleBand().padding(0.2),
+ yDomain: [0, 10],
+ };
+ /** Each visible line set's segment count */
+ const xLineCount = (scene: SceneState) =>
+ visibleLines(scene).map((l) => l.geometry.attributes.instanceStart.count);
+
+ it('lines up with bands by `bandAlign`, one past the last between them', async () => {
+ const center = await renderOthers({ mark: 'grid', chart: band, grid: { y: false, z: false } });
+ await expect.poll(() => xLineCount(center)).toEqual([3]);
+ const between = await renderOthers({
+ mark: 'grid',
+ chart: band,
+ grid: { y: false, z: false, bandAlign: 'between' },
+ });
+ await expect.poll(() => xLineCount(between)).toEqual([4]);
+ });
+
+ it('styles each axis’ lines by its own props', async () => {
+ const scene = await renderOthers({
+ mark: 'grid',
+ chart: { xDomain: [0, 10], yDomain: [0, 10] },
+ grid: { x: { stroke: 'rgb(0, 0, 255)', strokeWidth: 3 }, y: true, z: false },
+ });
+ const blue = new Color('rgb(0, 0, 255)');
+ await expect.poll(() => visibleLines(scene).length).toBe(2);
+ const own = visibleLines(scene).find((l) => l.material.color.equals(blue));
+ expect(own?.material.linewidth).toBe(3);
+ });
+});
+
+describe('Raster', () => {
+ it('blurs the image over `blur` cells', async () => {
+ const pixelsOf = async (blur: number) => {
+ const scene = await renderOthers({
+ mark: 'raster',
+ chart: { xDomain: [0, 1], yDomain: [0, 1] },
+ raster: { data: [0, 0, 10, 0, 0], width: 5, height: 1, blur },
+ });
+ const mesh = () => all(scene, (o) => o.isMesh && o.material?.map)[0];
+ await expect.poll(() => mesh()).toBeTruthy();
+ return Array.from(mesh().material.map.image.data as Uint8Array);
+ };
+ const sharp = await pixelsOf(0);
+ const blurred = await pixelsOf(1);
+ expect(blurred).not.toEqual(sharp);
+ });
+});
+
+describe('GeoRaster', () => {
+ it('lays its image over `resolution` times as many points', async () => {
+ const canvas = document.createElement('canvas');
+ canvas.width = canvas.height = 16;
+ const countOf = async (resolution: number) => {
+ const scene = await renderOthers({
+ mark: 'georaster',
+ chart: { geo: { projection: geoIdentity, fitGeojson: square } },
+ georaster: { image: canvas, resolution },
+ });
+ const mesh = () => all(scene, (o) => o.isMesh)[0];
+ await expect
+ .poll(() => mesh()?.geometry.getAttribute('position')?.count ?? 0)
+ .toBeGreaterThan(0);
+ return mesh().geometry.getAttribute('position').count;
+ };
+ const one = await countOf(1);
+ const two = await countOf(2);
+ expect(two / one).toBeGreaterThan(3);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-shared.svelte.test.ts b/packages/webgl/src/lib/components/parity-shared.svelte.test.ts
new file mode 100644
index 0000000000..a3d1d3c3ce
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-shared.svelte.test.ts
@@ -0,0 +1,444 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import {
+ Matrix4,
+ OrthographicCamera,
+ Quaternion,
+ Scene,
+ Vector3,
+ WebGLRenderer,
+ WebGLRenderTarget,
+ type InstancedMesh,
+ type Mesh,
+ type Object3D,
+} from 'three';
+
+import type { ChartState } from 'layerchart';
+import type { SceneState } from '../contexts/scene.svelte.js';
+import { contourSegments } from '../utils/contours.js';
+import { perspective } from '../index.js';
+import Marks from './__fixtures__/Marks.svelte';
+
+let chart: ChartState | undefined;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderMarks(props: Omit>[1], 'onScene'>) {
+ let scene: SceneState | undefined;
+ const result = render(Marks, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return { scene: scene!, rerender: result.rerender };
+}
+
+/** The objects marks put in the scene, looking through each mark's own layer */
+const layered = (scene: SceneState) =>
+ scene.root.children.flatMap((o) => (o.userData.layer ? o.children : [o]));
+
+const instanced = (scene: SceneState) =>
+ layered(scene).filter((o: Object3D) => (o as any).isInstancedMesh) as InstancedMesh[];
+
+/** The planes labels lying on the surface are painted on */
+const planes = (scene: SceneState) => {
+ const found: Mesh[] = [];
+ scene.root.traverse((o: any) => {
+ if (o.isMesh && o.material?.map) found.push(o);
+ });
+ return found;
+};
+
+/** The most opaque pixel painted on a label's plane (0 to 255) */
+function peakAlpha(plane: Mesh) {
+ const canvas = (plane.material as any).map.image as HTMLCanvasElement;
+ const pixels = canvas.getContext('2d')!.getImageData(0, 0, canvas.width, canvas.height).data;
+ let peak = 0;
+ for (let i = 3; i < pixels.length; i += 4) peak = Math.max(peak, pixels[i]);
+ return peak;
+}
+
+describe('Text, with the core `Text`’s opacities', () => {
+ it('fades a `viewport` label’s letters, halo, and the whole of it', async () => {
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: {
+ x: 100,
+ y: 50,
+ value: 'faded',
+ viewport: true,
+ stroke: 'white',
+ fillOpacity: 0.4,
+ strokeOpacity: 0.25,
+ opacity: 0.8,
+ },
+ });
+ await expect.poll(() => scene.labelSets.flat().length).toBe(1);
+ const [label] = scene.labelSets.flat();
+ expect([label.fillOpacity, label.strokeOpacity, label.opacity]).toEqual([0.4, 0.25, 0.8]);
+
+ const element = () =>
+ [...document.querySelectorAll('.lc-webgl-label')].find(
+ (e) => e.textContent?.trim() === 'faded'
+ );
+ await expect.poll(() => element()).toBeTruthy();
+ const style = element()!.style;
+ expect(style.opacity).toBe('0.8');
+ expect(style.getPropertyValue('-webkit-text-fill-color')).toContain('40%');
+ expect(style.getPropertyValue('-webkit-text-stroke')).toContain('25%');
+ });
+
+ it('takes them per row, as functions of it', async () => {
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: { xDomain: [0, 100], yDomain: [0, 100] },
+ text: {
+ data: [
+ { x: 10, y: 10, o: 0.2 },
+ { x: 50, y: 50, o: 0.6 },
+ ],
+ x: (d: any) => d.x,
+ y: (d: any) => d.y,
+ value: (d: any) => String(d.o),
+ viewport: true,
+ opacity: (d: any) => d.o,
+ },
+ });
+ await expect.poll(() => scene.labelSets.flat().length).toBe(2);
+ expect(scene.labelSets.flat().map((l) => l.opacity)).toEqual([0.2, 0.6]);
+ });
+
+ it('leaves a label without them as it was', async () => {
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 'plain', viewport: true },
+ });
+ await expect.poll(() => scene.labelSets.flat().length).toBe(1);
+ const [label] = scene.labelSets.flat();
+ expect([label.fillOpacity, label.strokeOpacity, label.opacity]).toEqual([
+ undefined,
+ undefined,
+ undefined,
+ ]);
+ });
+
+ it('paints a label lying on the surface at `fillOpacity`, and fades its plane by `opacity`', async () => {
+ const solid = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 'solid', fill: 'black' },
+ });
+ await expect.poll(() => planes(solid.scene).length).toBe(1);
+ const [plain] = planes(solid.scene);
+ expect(peakAlpha(plain)).toBeGreaterThan(250);
+ expect((plain.material as any).opacity).toBe(1);
+
+ const { scene } = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 'faded', fill: 'black', fillOpacity: 0.5, opacity: 0.4 },
+ });
+ await expect.poll(() => planes(scene).length).toBe(1);
+ const [plane] = planes(scene);
+ // Its letters painted half opaque, and the plane drawn at 0.4
+ expect(peakAlpha(plane)).toBeGreaterThan(110);
+ expect(peakAlpha(plane)).toBeLessThan(145);
+ expect((plane.material as any).opacity).toBeCloseTo(0.4);
+ });
+});
+
+/** An instance's center (across, down the plot) and radius */
+function placed(mesh: InstancedMesh, i = 0) {
+ const matrix = new Matrix4();
+ mesh.getMatrixAt(i, matrix);
+ const position = new Vector3();
+ const size = new Vector3();
+ matrix.decompose(position, new Quaternion(), size);
+ return { x: position.x, y: position.z, r: size.x };
+}
+
+/**
+ * Which of `samples` points round a ring (at its radius, clockwise as the plot is seen from its
+ * rightmost point) are drawn, rendered from above on its own
+ */
+function ringCoverage(ring: InstancedMesh, samples: number) {
+ const { x, y, r } = placed(ring);
+ const scene = new Scene();
+ scene.add(ring);
+ ring.updateMatrixWorld();
+ const size = 128;
+ const half = r * 1.25;
+ const camera = new OrthographicCamera(-half, half, half, -half, 0.1, 1000);
+ // Looking straight down, the plot's `y` (the scene's `z`) running down the screen
+ camera.position.set(x, 100, y);
+ camera.up.set(0, 0, -1);
+ camera.lookAt(x, 0, y);
+ const renderer = new WebGLRenderer();
+ const target = new WebGLRenderTarget(size, size);
+ renderer.setRenderTarget(target);
+ renderer.setClearColor(0x000000, 0);
+ renderer.render(scene, camera);
+ const pixels = new Uint8Array(size * size * 4);
+ renderer.readRenderTargetPixels(target, 0, 0, size, size, pixels);
+ renderer.setRenderTarget(null);
+ renderer.dispose();
+ target.dispose();
+ return Array.from({ length: samples }, (_, k) => {
+ const angle = ((k + 0.5) / samples) * Math.PI * 2;
+ // Down the screen is up the rows read back
+ const px = Math.round(size / 2 + ((Math.cos(angle) * r) / half) * (size / 2));
+ const py = Math.round(size / 2 - ((Math.sin(angle) * r) / half) * (size / 2));
+ return { angle, drawn: pixels[(py * size + px) * 4 + 3] > 0 };
+ });
+}
+
+describe('dashed rings, as the core `Circle`’s `dashArray`', () => {
+ it('dashes a `Circle`’s ring from its rightmost point, clockwise', async () => {
+ const { scene } = await renderMarks({
+ mark: 'circle',
+ chart: {},
+ circle: {
+ cx: 100,
+ cy: 80,
+ r: 40,
+ fill: 'none',
+ stroke: 'black',
+ strokeWidth: 4,
+ dashArray: '10 30',
+ },
+ });
+ await expect.poll(() => instanced(scene)[0]?.count ?? 0).toBe(1);
+ const [ring] = instanced(scene);
+ const material = ring.material as any;
+ await expect.poll(() => material.defines.LC_RING_DASH).toBe('');
+ const [dash, gap] = material.userData.ringDash.value.toArray();
+ expect(gap / dash).toBeCloseTo(3);
+
+ const { r } = placed(ring);
+ const samples = ringCoverage(ring, 180);
+ const expected = (around: number) => around % (dash + gap) <= dash;
+ // Where its dashes fall, going clockwise from the rightmost point, and not the other way
+ const clockwise = samples.filter((s) => s.drawn === expected(s.angle * r)).length;
+ const counter = samples.filter((s) => s.drawn === expected((Math.PI * 2 - s.angle) * r)).length;
+ expect(clockwise / samples.length).toBeGreaterThan(0.9);
+ expect(counter).toBeLessThan(clockwise);
+ // About a quarter of it drawn
+ const share = samples.filter((s) => s.drawn).length / samples.length;
+ expect(share).toBeGreaterThan(0.15);
+ expect(share).toBeLessThan(0.35);
+ });
+
+ it('draws a ring without one whole, compiled without dashes', async () => {
+ const { scene } = await renderMarks({
+ mark: 'circle',
+ chart: {},
+ circle: { cx: 100, cy: 80, r: 40, fill: 'none', stroke: 'black', strokeWidth: 4 },
+ });
+ await expect.poll(() => instanced(scene)[0]?.count ?? 0).toBe(1);
+ const [ring] = instanced(scene);
+ expect((ring.material as any).defines.LC_RING_DASH).toBeUndefined();
+ const samples = ringCoverage(ring, 90);
+ expect(samples.every((s) => s.drawn)).toBe(true);
+ });
+
+ it('dashes `Points`’ rings, and stops when it’s taken away', async () => {
+ const rows = [
+ { x: 2, y: 2 },
+ { x: 7, y: 6 },
+ ];
+ const chartProps = { data: rows, x: 'x', y: 'y', xDomain: [0, 10], yDomain: [0, 10] };
+ const { scene, rerender } = await renderMarks({
+ mark: 'points',
+ chart: chartProps,
+ points: { r: 8, stroke: 'black', dashArray: [4, 2] },
+ });
+ await expect.poll(() => instanced(scene).length).toBe(2);
+ const ring = instanced(scene)[1];
+ const material = ring.material as any;
+ await expect.poll(() => material.defines.LC_RING_DASH).toBe('');
+ const [dash, gap] = material.userData.ringDash.value.toArray();
+ expect(dash / gap).toBeCloseTo(2);
+ // The points' discs aren't dashed
+ expect((instanced(scene)[0].material as any).defines?.LC_RING_DASH).toBeUndefined();
+
+ await rerender({ points: { r: 8, stroke: 'black' } });
+ await expect.poll(() => material.defines.LC_RING_DASH).toBeUndefined();
+ });
+});
+
+describe('Highlight, with the core `Highlight`’s point events', () => {
+ const row = { x: 4, y: 6 };
+ const chartProps = { data: [row], x: 'x', y: 'y', xDomain: [0, 10], yDomain: [0, 10] };
+ const marker = () => document.querySelector('.lc-webgl-markers circle');
+
+ it('calls `onPointClick`, `onPointEnter`, and `onPointLeave` with its point and row', async () => {
+ const calls: [string, any][] = [];
+ await renderMarks({
+ mark: 'highlight',
+ chart: chartProps,
+ highlight: {
+ data: row,
+ points: true,
+ motion: 'none',
+ onPointClick: (_e: MouseEvent, detail: any) => calls.push(['click', detail]),
+ onPointEnter: (_e: MouseEvent, detail: any) => calls.push(['enter', detail]),
+ onPointLeave: (_e: MouseEvent, detail: any) => calls.push(['leave', detail]),
+ },
+ });
+ await expect.poll(() => marker()).toBeTruthy();
+ // Taking the pointer, as a clickable point
+ expect(marker()!.style.pointerEvents).toBe('auto');
+ expect(marker()!.style.cursor).toBe('pointer');
+
+ marker()!.dispatchEvent(new PointerEvent('pointerenter'));
+ marker()!.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ marker()!.dispatchEvent(new PointerEvent('pointerleave'));
+ expect(calls.map(([type]) => type)).toEqual(['enter', 'click', 'leave']);
+ const [, { point, data }] = calls[1];
+ expect(data).toBe(row);
+ expect(point.x).toBeCloseTo(chart!.xScale(4));
+ expect(point.y).toBeCloseTo(chart!.yScale(6));
+ expect(point.data).toEqual({ x: 4, y: 6 });
+ });
+
+ it('lets the pointer through to the scene without them', async () => {
+ await renderMarks({
+ mark: 'highlight',
+ chart: chartProps,
+ highlight: { data: row, points: true, motion: 'none' },
+ });
+ await expect.poll(() => marker()).toBeTruthy();
+ expect(marker()!.style.pointerEvents).toBe('');
+ expect(getComputedStyle(marker()!).pointerEvents).toBe('none');
+ });
+});
+
+describe('Axis, with the core `Axis`’ `tickOcclusion`', () => {
+ const flat = { x: 'x', y: 'y', xDomain: [0, 10], yDomain: [0, 10] };
+ const ticks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
+ const format = (d: number) => `Wednesday ${d}`;
+ const texts = (scene: SceneState) => scene.labelSets.flat().map((l) => l.text);
+
+ it('keeps every tick without it', async () => {
+ const { scene } = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'bottom', ticks, format, tickLabelProps: { viewport: true } },
+ });
+ await expect.poll(() => texts(scene).length).toBe(11);
+ });
+
+ it('drops tick labels that would overlap, keeping the last (`end`) by default', async () => {
+ const { scene } = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: {
+ placement: 'bottom',
+ ticks,
+ format,
+ tickOcclusion: true,
+ tickLabelProps: { viewport: true },
+ },
+ });
+ await expect.poll(() => texts(scene).length).toBeGreaterThan(1);
+ const kept = texts(scene);
+ expect(kept.length).toBeLessThan(11);
+ expect(kept.at(-1)).toBe('Wednesday 10');
+ });
+
+ it('keeps the first with `priority: start`, and both ends with `start-end`', async () => {
+ const start = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: {
+ placement: 'bottom',
+ ticks,
+ format,
+ tickOcclusion: { priority: 'start' },
+ tickLabelProps: { viewport: true },
+ },
+ });
+ await expect.poll(() => texts(start.scene).length).toBeGreaterThan(1);
+ expect(texts(start.scene)[0]).toBe('Wednesday 0');
+ expect(texts(start.scene).length).toBeLessThan(11);
+
+ const ends = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: {
+ placement: 'bottom',
+ ticks,
+ format,
+ tickOcclusion: { priority: 'start-end' },
+ tickLabelProps: { viewport: true },
+ },
+ });
+ await expect.poll(() => texts(ends.scene).length).toBeGreaterThan(1);
+ expect(texts(ends.scene)[0]).toBe('Wednesday 0');
+ expect(texts(ends.scene).at(-1)).toBe('Wednesday 10');
+ });
+
+ it('drops the tick marks and labels lying on the floor with them', async () => {
+ const { scene } = await renderMarks({
+ mark: 'axis',
+ chart: flat,
+ axis: { placement: 'bottom', ticks, format, tickOcclusion: true },
+ });
+ await expect.poll(() => planes(scene).length).toBeGreaterThan(1);
+ const labels = planes(scene).length;
+ expect(labels).toBeLessThan(11);
+ const marks = () => {
+ const lines = layered(scene).filter((o) => (o as any).isLineSegments2) as any[];
+ return Math.max(
+ ...lines.map((l) => (l.visible ? l.geometry.attributes.instanceStart.count : 0))
+ );
+ };
+ await expect.poll(marks).toBe(labels);
+ });
+
+ it('keeps every tick in a 3D view, whose labels turn with it', async () => {
+ const { scene } = await renderMarks({
+ mark: 'axis',
+ chart: { ...flat, view: perspective },
+ axis: {
+ placement: 'bottom',
+ ticks,
+ format,
+ tickOcclusion: true,
+ tickLabelProps: { viewport: true },
+ },
+ });
+ await expect.poll(() => texts(scene).length).toBe(11);
+ });
+});
+
+describe('contourSegments, with `smooth`', () => {
+ // A peak in the middle of a 4 × 4 grid
+ const grid = {
+ values: Float64Array.from([0, 0, 0, 0, 0, 3, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0]),
+ columns: 4,
+ rows: 4,
+ left: 0,
+ top: 0,
+ right: 4,
+ bottom: 4,
+ };
+ /** Each segment end across and down, in cells */
+ const ends = (segments: number[]) =>
+ segments.flatMap((_, i) => (i % 3 === 0 ? [segments[i], segments[i + 2]] : []));
+
+ it('interpolates where lines cross between cells by default', () => {
+ const smooth = ends(contourSegments(grid, [0, 3], [0.25], () => 0));
+ expect(smooth.some((v) => !Number.isInteger(v * 2))).toBe(true);
+ });
+
+ it('runs them halfway between cells with `smooth: false`', () => {
+ const crisp = ends(contourSegments(grid, [0, 3], [0.25], () => 0, { smooth: false }));
+ expect(crisp.length).toBeGreaterThan(0);
+ expect(crisp.every((v) => Number.isInteger(v * 2))).toBe(true);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-spline-2.svelte.test.ts b/packages/webgl/src/lib/components/parity-spline-2.svelte.test.ts
new file mode 100644
index 0000000000..32817bd3e7
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-spline-2.svelte.test.ts
@@ -0,0 +1,129 @@
+import { describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import type { Object3D } from 'three';
+import type { ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import SplineArea from './__fixtures__/SplineArea.svelte';
+
+type Props = Omit>[1], 'onScene'>;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderMarks(props: Props) {
+ let scene: SceneState | undefined;
+ let chart: ChartState | undefined;
+ render(SplineArea, {
+ ...(props as any),
+ onScene: (s: SceneState, c: ChartState) => {
+ scene = s;
+ chart = c;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return { scene: scene!, chart: chart! };
+}
+
+/** Every object in the scene */
+const all = (scene: SceneState) => {
+ const out: Object3D[] = [];
+ scene.root.traverse((o) => out.push(o));
+ return out;
+};
+/** The scene's lines (a `Spline`'s, each a `Line2`) */
+const lines = (scene: SceneState) => all(scene).filter((o) => (o as any).isLine2) as any[];
+/** A line's points, as `[x, y]` across and down the plot */
+const pointsOf = (line: any): [number, number][] => {
+ const start = line.geometry.attributes.instanceStart;
+ const end = line.geometry.attributes.instanceEnd;
+ const out: [number, number][] = [];
+ for (let i = 0; i < start.count; i++) out.push([start.getX(i), start.getZ(i)]);
+ if (start.count) out.push([end.getX(start.count - 1), end.getZ(start.count - 1)]);
+ return out;
+};
+
+const radial = {
+ radial: true,
+ x: 'x',
+ y: 'y',
+ xDomain: [0, 4],
+ xRange: [0, 2 * Math.PI],
+ yDomain: [0, 10],
+ yRange: [0, 100],
+};
+
+describe('Spline and Area, as the core marks', () => {
+ it("lays a `radial` chart's line out by angle and radius about the center", async () => {
+ const data = [
+ { x: 0, y: 10 },
+ { x: 1, y: 5 },
+ { x: 2, y: 10 },
+ ];
+ const { scene } = await renderMarks({ chart: { ...radial, data }, spline: {} });
+ await expect.poll(() => lines(scene).length).toBe(1);
+ const points = pointsOf(lines(scene)[0]);
+ // Up at 12 o'clock, right at 3, and down at 6, as `lineRadial` puts them
+ expect(points[0][0]).toBeCloseTo(0);
+ expect(points[0][1]).toBeCloseTo(-100);
+ expect(points[1][0]).toBeCloseTo(50);
+ expect(points[1][1]).toBeCloseTo(0);
+ expect(points[2][0]).toBeCloseTo(0);
+ expect(points[2][1]).toBeCloseTo(100);
+ });
+
+ it("fills a `radial` chart's area between its radii", async () => {
+ const data = [0, 1, 2, 3].map((x) => ({ x, lo: 4, hi: 8 }));
+ const { scene } = await renderMarks({
+ chart: { ...radial, data },
+ area: { y0: 'lo', y1: 'hi' },
+ });
+ const mesh = () => all(scene).find((o) => (o as any).isMesh && !(o as any).isLine2) as any;
+ await expect.poll(() => mesh()?.geometry.attributes.position?.count ?? 0).toBeGreaterThan(0);
+ const array = mesh().geometry.attributes.position.array as Float32Array;
+ const radii: number[] = [];
+ for (let i = 0; i < array.length; i += 3) radii.push(Math.hypot(array[i], array[i + 2]));
+ expect(Math.min(...radii)).toBeCloseTo(40);
+ expect(Math.max(...radii)).toBeCloseTo(80);
+ });
+
+ it('splits a line into runs by a `class` function, dashing the dashed ones', async () => {
+ const data = [0, 1, 2, 3, 4].map((x) => ({ x, y: x, gap: x === 2 }));
+ const { scene } = await renderMarks({
+ chart: { data, x: 'x', y: 'y' },
+ spline: {
+ class: (d: any) => (d.gap ? 'test-wide test-dashed' : 'test-wide'),
+ },
+ });
+ // Solid to the gap's row, dashed across to the next, then solid again
+ await expect.poll(() => lines(scene).length).toBe(3);
+ const runs = lines(scene);
+ expect(runs.map((l) => l.material.dashed)).toEqual([false, true, false]);
+ expect(runs.map((l) => pointsOf(l).length)).toEqual([3, 2, 2]);
+ expect(runs.every((l) => l.material.linewidth === 2)).toBe(true);
+ });
+
+ it("draws a line all the way with `draw`, past its first frame's length", async () => {
+ const data = Array.from({ length: 20 }, (_, x) => ({ x, y: x % 3 }));
+ const { scene } = await renderMarks({
+ chart: { data, x: 'x', y: 'y' },
+ spline: { draw: { duration: 300 } },
+ });
+ await expect.poll(() => lines(scene).length).toBe(1);
+ const line = lines(scene)[0];
+ await expect.poll(() => pointsOf(line).length).toBe(20);
+ // three draws no more of a line's segments than it first drew, unless told it may
+ await new Promise((resolve) => requestAnimationFrame(resolve));
+ expect(line.geometry._maxInstanceCount ?? Infinity).toBeGreaterThanOrEqual(19);
+ });
+
+ it('stacks an `Area` with no edges of its own, as the core `Area` registers', async () => {
+ const data = ['a', 'b'].flatMap((name, k) =>
+ [0, 1, 2].map((x) => ({ x, value: 10 + k, name }))
+ );
+ const { chart } = await renderMarks({
+ chart: { data, x: 'x', y: 'value', c: 'name', seriesLayout: 'stack' },
+ area: {},
+ });
+ await expect.poll(() => chart.isStacked).toBe(true);
+ await expect.poll(() => Math.max(...(chart.yDomain as number[]))).toBe(21);
+ });
+});
diff --git a/packages/webgl/src/lib/components/parity-text-2.svelte.test.ts b/packages/webgl/src/lib/components/parity-text-2.svelte.test.ts
new file mode 100644
index 0000000000..2b5fe31ce4
--- /dev/null
+++ b/packages/webgl/src/lib/components/parity-text-2.svelte.test.ts
@@ -0,0 +1,215 @@
+import { afterAll, beforeAll, describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+import type { Object3D } from 'three';
+import { isometric, type ChartState } from 'layerchart';
+
+import type { SceneState } from '../contexts/scene.svelte.js';
+import Marks from './__fixtures__/Marks.svelte';
+
+type Props = Omit>[1], 'onScene'>;
+
+/** Render, and wait for the marks to add their objects to the scene */
+async function renderMarks(props: Props) {
+ let scene: SceneState | undefined;
+ render(Marks, {
+ ...(props as any),
+ onScene: (s: SceneState, _c: ChartState) => {
+ scene = s;
+ },
+ });
+ await expect.poll(() => scene?.root.children.length ?? 0).toBeGreaterThan(0);
+ return scene!;
+}
+
+/** Classes for these tests, as Tailwind's would set them */
+let style: HTMLStyleElement;
+beforeAll(() => {
+ style = document.createElement('style');
+ style.textContent = `
+ .t-red { color: rgb(255, 0, 0); }
+ .t-none { fill: none; }
+ .t-stroke-none { stroke: none; }
+ `;
+ document.head.append(style);
+});
+afterAll(() => style.remove());
+
+/** The planes labels lying on the surface are painted on, in the order they're drawn */
+const planes = (scene: SceneState) => {
+ const found: any[] = [];
+ scene.root.traverse((o: any) => {
+ if (o.isMesh && o.material?.map) found.push(o);
+ });
+ return found;
+};
+
+/** Whether a label's painted canvas has a pixel mostly of `channel` (`0` red, `2` blue, ...) */
+function painted(plane: any, test: (r: number, g: number, b: number, a: number) => boolean) {
+ const image = plane.material.map.image as HTMLCanvasElement;
+ const pixels = image.getContext('2d')!.getImageData(0, 0, image.width, image.height).data;
+ for (let i = 0; i < pixels.length; i += 4) {
+ if (test(pixels[i], pixels[i + 1], pixels[i + 2], pixels[i + 3])) return true;
+ }
+ return false;
+}
+
+/** The objects marks put in the scene, looking through each mark's own layer */
+const layered = (scene: SceneState) =>
+ scene.root.children.flatMap((o) => (o.userData.layer ? o.children : [o]));
+
+describe('Text, as the core `Text`', () => {
+ it('starts at its point by default (`textAnchor` `start`)', async () => {
+ const scene = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 'hello', fontSize: 12 },
+ });
+ await expect.poll(() => planes(scene).length).toBe(1);
+ // Its plane's middle to the right of its point, not centered on it
+ expect(planes(scene)[0].position.x).toBeGreaterThan(110);
+ });
+
+ it('draws no halo with a `stroke-none` class, over its `stroke` prop (as CSS does)', async () => {
+ const blue = (r: number, g: number, b: number, a: number) => b > 200 && r < 60 && a > 100;
+ const haloed = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 'hello', fontSize: 12, stroke: 'blue', strokeWidth: 4 },
+ });
+ await expect.poll(() => planes(haloed).length).toBe(1);
+ expect(painted(planes(haloed)[0], blue)).toBe(true);
+
+ const plain = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: {
+ x: 100,
+ y: 50,
+ value: 'hello',
+ fontSize: 12,
+ stroke: 'blue',
+ strokeWidth: 4,
+ class: 't-stroke-none',
+ },
+ });
+ await expect.poll(() => planes(plain).length).toBe(1);
+ expect(painted(planes(plain)[0], blue)).toBe(false);
+ });
+
+ it('shares one painting between labels a little apart in size, each shrunk to its own', async () => {
+ const label = async (fontSize: number) => {
+ const scene = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 100, y: 50, value: 'shared', fontSize },
+ });
+ await expect.poll(() => planes(scene).length).toBe(1);
+ return planes(scene)[0];
+ };
+ const a = await label(12);
+ // A size changing a little (ex. fitted to a box as the view turns) paints nothing anew
+ const b = await label(12.4);
+ expect(b.material.map.image).toBe(a.material.map.image);
+ expect(b.scale.x / a.scale.x).toBeCloseTo(12.4 / 12);
+ // One a step apart is painted at its own size
+ const c = await label(24);
+ expect(c.material.map.image).not.toBe(a.material.map.image);
+ });
+
+ it('lays `segments` from its point, each in its own class’s text color', async () => {
+ const scene = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: {
+ x: 100,
+ y: 50,
+ fontSize: 12,
+ segments: [{ value: 'Hello', class: 't-red' }, { value: ' world' }],
+ },
+ });
+ await expect.poll(() => planes(scene).length).toBe(2);
+ const [hello, world] = planes(scene);
+ expect(hello.position.x).toBeGreaterThan(100);
+ expect(world.position.x).toBeGreaterThan(hello.position.x);
+ const red = (r: number, g: number, b: number, a: number) => a > 200 && r > 200 && g < 60;
+ expect(painted(hello, red)).toBe(true);
+ expect(painted(world, red)).toBe(false);
+ });
+
+ it('wraps on an explicit newline, starting at its point', async () => {
+ const scene = await renderMarks({
+ mark: 'text',
+ chart: {},
+ text: { x: 0, y: 0, value: 'March\n2025', verticalAnchor: 'start', fontSize: 12 },
+ });
+ await expect.poll(() => planes(scene).length).toBe(1);
+ const plane = planes(scene)[0];
+ const image = plane.material.map.image as HTMLCanvasElement;
+ // Two lines tall, and all of it right of `x` (not cut off at the plot's left edge)
+ expect(image.height).toBeGreaterThan(image.width / 3);
+ expect(plane.position.x).toBeGreaterThan(0);
+ });
+});
+
+describe('Arc, as the core `Arc`', () => {
+ it('leaves a `fill-none` track unfilled', async () => {
+ const meshes = (scene: SceneState) =>
+ layered(scene).filter((o: Object3D) => (o as any).isMesh && (o as any).visible !== false);
+ const filled = await renderMarks({
+ mark: 'arc',
+ chart: {},
+ arc: { value: 0, outerRadius: 80, innerRadius: 70, track: { class: 't-none' } },
+ });
+ // Only drawn where there's something to draw
+ await expect.poll(() => filled.root.children.length).toBeGreaterThan(0);
+ const triangles = meshes(filled).reduce(
+ (sum, mesh: any) => sum + (mesh.geometry?.attributes?.position?.count ?? 0),
+ 0
+ );
+ expect(triangles).toBe(0);
+ });
+});
+
+describe('Contour, as the core `Contour`', () => {
+ // A cone: a ring of each threshold, closing along the grid's edges at the lowest
+ const size = 20;
+ const values = Array.from({ length: size * size }, (_, k) => {
+ const [i, j] = [k % size, Math.floor(k / size)];
+ return 100 - Math.hypot(i - size / 2, j - size / 2) * 5;
+ });
+ const lines = (scene: SceneState) =>
+ layered(scene).find((o: any) => o.isLineSegments2 && o.visible) as any;
+
+ it('draws raised unfilled bands as lines in their colors, through the grid’s edges', async () => {
+ const scene = await renderMarks({
+ mark: 'contour',
+ chart: { zDomain: [0, 100], zRange: [0, 50], view: isometric() },
+ contour: { data: values, width: size, height: size, z: 'value', fill: 'none' },
+ });
+ await expect.poll(() => !!lines(scene)).toBe(true);
+ const segments = lines(scene);
+ expect(segments.material.vertexColors).toBe(true);
+ expect(segments.geometry.attributes.instanceColorStart).toBeTruthy();
+ // Its lowest ring runs along the plot's left edge (`x` 0)
+ const start = segments.geometry.attributes.instanceStart;
+ const xs = Array.from({ length: start.count }, (_, i) => start.getX(i));
+ expect(Math.min(...xs)).toBeCloseTo(0, 0);
+ });
+
+ it('keeps a `stroke` it is given, in one color', async () => {
+ const scene = await renderMarks({
+ mark: 'contour',
+ chart: { zDomain: [0, 100], zRange: [0, 50], view: isometric() },
+ contour: {
+ data: values,
+ width: size,
+ height: size,
+ z: 'value',
+ fill: 'none',
+ stroke: 'red',
+ },
+ });
+ await expect.poll(() => !!lines(scene)).toBe(true);
+ expect(lines(scene).material.vertexColors).toBe(false);
+ });
+});
diff --git a/packages/webgl/src/lib/contexts/scene.svelte.ts b/packages/webgl/src/lib/contexts/scene.svelte.ts
index b9490f8575..7859056b0c 100644
--- a/packages/webgl/src/lib/contexts/scene.svelte.ts
+++ b/packages/webgl/src/lib/contexts/scene.svelte.ts
@@ -32,6 +32,11 @@ export type SceneLabel = {
/** A halo around the letters, behind them (a CSS color), and its width in pixels */
stroke?: string;
strokeWidth?: number;
+ /** How opaque its letters and its halo are (0 to 1), as SVG text's fill and stroke opacity */
+ fillOpacity?: number;
+ strokeOpacity?: number;
+ /** How opaque it is as a whole (0 to 1), letters and halo together */
+ opacity?: number;
/**
* The way it sits out from its point, in the chart's axes (ex. out from an axis): it's anchored
* by its side nearest the point, whichever way the view turns that on screen, so it keeps the
@@ -58,12 +63,39 @@ export type SceneMarker = {
strokeWidth?: number;
opacity?: number;
class?: string;
+ /**
+ * Pointer handlers, as on the core marks' elements (ex. a `Highlight`'s `onPointClick`). Only a
+ * marker with one takes the pointer; the rest let it through to the scene beneath.
+ */
+ onclick?: (e: MouseEvent) => void;
+ onpointerenter?: (e: PointerEvent) => void;
+ onpointerleave?: (e: PointerEvent) => void;
+};
+
+/** Pointer handlers a mark takes, as the core marks' (called with the row under the pointer) */
+export type MarkEvents = {
+ onclick?: ((e: MouseEvent, detail: { data: any }) => void) | null;
+ ondblclick?: ((e: MouseEvent, detail: { data: any }) => void) | null;
+ onpointerenter?: ((e: PointerEvent, detail: { data: any }) => void) | null;
+ onpointerover?: ((e: PointerEvent, detail: { data: any }) => void) | null;
+ onpointermove?: ((e: PointerEvent, detail: { data: any }) => void) | null;
+ onpointerleave?: ((e: PointerEvent, detail: { data: any }) => void) | null;
+ onpointerout?: ((e: PointerEvent, detail: { data: any }) => void) | null;
};
+/** Whether any of `events` is set */
+export function hasEvents(events: MarkEvents | undefined) {
+ return !!events && Object.values(events).some((handler) => typeof handler === 'function');
+}
+
/** A mark's object the pointer can hit, and the data row each hit is on */
export type Pickable = {
object: Object3D;
datum: (hit: Intersection) => unknown;
+ /** Whether hovering it shows the tooltip (else it's picked only for `events`) @default true */
+ tooltip?: () => boolean;
+ /** Its pointer handlers, called with the row under the pointer */
+ events?: () => MarkEvents | undefined;
};
const KEY = Symbol('LayerChart3DScene');
@@ -101,12 +133,16 @@ export class SceneState {
layer() {
const group = new Group();
group.userData.layer = true;
+ // Past the plot box's sides where asked (ex. a line's markers at its edge, as SVG's overflow)
+ if (isUnclipped()) group.userData.unclipped = true;
this.#layers.push(group);
- this.root.add(group);
+ // Inside a `Group`, under its own (moved by it, as an SVG `` moves what's in it)
+ const parent = getParent()?.object ?? this.root;
+ parent.add(group);
this.#place();
$effect(() => () => {
this.#layers.splice(this.#layers.indexOf(group), 1);
- this.root.remove(group);
+ parent.remove(group);
this.#place();
});
return group;
@@ -121,9 +157,16 @@ export class SceneState {
#place() {
this.#layers.forEach((group, i) => group.position.setY(this.#stacked ? i * LAYER_STEP : 0));
+ this.stackHeight = this.#stacked ? this.#layers.length * LAYER_STEP : 0;
this.invalidate();
}
+ /**
+ * How high the flat mode's stacked layers reach, for the camera to look down from above them
+ * all (ex. a `Calendar`'s `Rect` per day is hundreds of layers)
+ */
+ stackHeight = $state(0);
+
colors: ColorResolver | null = null;
camera: Camera | null = null;
@@ -222,10 +265,25 @@ export class SceneState {
* What a mark's CSS `class` sets (its fill, stroke, and opacity, as the core `Canvas` layer
* reads them), re-read when the theme changes. `null` without one, or before the layer mounts.
*/
- style(classes: string | null | undefined): ClassStyle | null {
+ style(
+ classes: string | null | undefined,
+ /** Attributes LayerChart's styles read (ex. a label's `data-placement`) */
+ attributes?: Record
+ ): ClassStyle | null {
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
+ this.themeVersion;
+ return classes || attributes ? (this.colors?.style(classes ?? '', attributes) ?? null) : null;
+ }
+
+ /**
+ * The font size (pixels) and weight text has here: its `class`'s (ex. `text-xs font-semibold`),
+ * else the chart's, as an SVG or Canvas label inherits them. `null` before the layer mounts.
+ */
+ font(classes: string | null | undefined): { size: number; weight: string } | null {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.themeVersion;
- return classes ? (this.colors?.style(classes) ?? null) : null;
+ const style = this.colors?.style(classes ?? '');
+ return style && style.fontSize > 0 ? { size: style.fontSize, weight: style.fontWeight } : null;
}
/** A point in the scene (ex. where the pointer hit a mark) in chart coordinates */
@@ -269,6 +327,37 @@ export class SceneState {
}
}
+const PARENT = Symbol('LayerChartWebGLParent');
+
+/**
+ * A `Group`'s object, which the marks inside add theirs to, and where it is on the plot (its
+ * pixels across and down, with every `Group` it's in): for what's placed outside the scene
+ * (labels over it) to move with it
+ */
+export type SceneParent = {
+ object: Object3D;
+ readonly x: number;
+ readonly y: number;
+ /** How opaque what's inside is drawn, its `Group`s' opacities multiplied (ex. `opacity={0.2}`) */
+ readonly opacity?: number;
+};
+
+/** The opacity the `Group`s a mark is in draw it at (1 outside any) */
+export function groupOpacity(): () => number {
+ const parent = getParent();
+ return () => parent?.opacity ?? 1;
+}
+
+/** Put the marks inside under `parent` (see `SceneParent`) */
+export function setParent(parent: SceneParent) {
+ setContext(PARENT, parent);
+}
+
+/** The `Group` marks here are in, if any (see `SceneParent`) */
+export function getParent(): SceneParent | undefined {
+ return getContext(PARENT);
+}
+
const UNCLIPPED = Symbol('LayerChartWebGLUnclipped');
/** Keep what marks inside draw from being clipped to the plot box (ex. an axis' labels beside it) */
@@ -285,6 +374,11 @@ export function setSceneContext(state: SceneState) {
return setContext(KEY, state);
}
+/** Whether this is inside a `` scene (a layer-agnostic mark draws its WebGL version there) */
+export function hasSceneContext(): boolean {
+ return getContext(KEY) !== undefined;
+}
+
export function getSceneContext(): SceneState {
const state = getContext(KEY);
if (!state) {
diff --git a/packages/webgl/src/lib/index.ts b/packages/webgl/src/lib/index.ts
index 6405e0a24a..2cc7c91bad 100644
--- a/packages/webgl/src/lib/index.ts
+++ b/packages/webgl/src/lib/index.ts
@@ -1,6 +1,44 @@
// Everything a 3D chart needs from one import: the chart itself and the pieces that draw outside
// the scene come from `layerchart`, and the marks drawn in it from here.
-export { Chart, Legend, Tooltip, orthographic, perspective } from 'layerchart';
+//
+// Layer-agnostic, as `layerchart` is: `Layer` draws a `` scene with `type="webgl"` (or
+// `settings.layer`), and LayerChart's `Svg`, `Canvas`, or `Html` layer otherwise, and each mark
+// draws its WebGL version in a scene and LayerChart's elsewhere. For WebGL only, without bundling
+// LayerChart's versions of the marks, import from `@layerchart/webgl/webgl`.
+export { Legend, Tooltip, orthographic, perspective } from 'layerchart';
+// LayerChart's contexts and layouts, which draw nothing themselves but hand their children data
+// (for the marks here to draw), and its legends drawn beside the layer
+export { Bounds, ChartGroup, CircleLegend, Dodge, Point } from 'layerchart';
+export type {
+ BoundsProps,
+ ChartGroupProps,
+ CircleLegendProps,
+ DodgeProps,
+ PointProps,
+} from 'layerchart';
+export { Chord, Dagre, Sankey } from 'layerchart/graph';
+export type { ChordProps, DagreProps, SankeyProps } from 'layerchart/graph';
+export { Pack, Partition, Tree, Treemap } from 'layerchart/hierarchy';
+export type { PackProps, PartitionProps, TreeProps, TreemapProps } from 'layerchart/hierarchy';
+export { GeoLegend, GeoProjection, GeoVisible } from 'layerchart/geo';
+export type { GeoLegendProps, GeoProjectionProps, GeoVisibleProps } from 'layerchart/geo';
+export { ForceSimulation } from 'layerchart/force';
+export type { ForceSimulationProps } from 'layerchart/force';
+// LayerChart's `Chart`, its axes, grid, and highlight (`axis`, `grid`, ...) drawn with the marks here
+export { default as Chart } from './components/Chart/Chart.svelte';
+export type { ChartProps } from './components/Chart/Chart.svelte';
+export { default as ChartClipPath } from './components/ChartClipPath/ChartClipPath.svelte';
+export type { ChartClipPathProps } from './components/ChartClipPath/ChartClipPath.svelte';
+// The facet grid's headers, drawn with the `Axis` here
+export { default as FacetAxis } from './components/FacetAxis/FacetAxis.svelte';
+export { default as ClipPath } from './components/ClipPath/ClipPath.svelte';
+export type { ClipPathProps } from './components/ClipPath/ClipPath.svelte';
+export { default as RectClipPath } from './components/RectClipPath/RectClipPath.svelte';
+export type { RectClipPathProps } from './components/RectClipPath/RectClipPath.svelte';
+export { default as CircleClipPath } from './components/CircleClipPath/CircleClipPath.svelte';
+export type { CircleClipPathPropsWithoutHTML } from './components/CircleClipPath/CircleClipPath.svelte';
+export { default as GeoClipPath } from './components/GeoClipPath/GeoClipPath.svelte';
+export type { GeoClipPathProps } from './components/GeoClipPath/GeoClipPath.svelte';
export type {
OrthographicOptions,
OrthographicView,
@@ -8,10 +46,20 @@ export type {
PerspectiveView,
} from 'layerchart';
-export { default as WebGL } from './components/WebGL/WebGL.svelte';
-export type { WebGLProps, WebGLPropsWithoutHTML } from './components/WebGL/WebGL.svelte';
+export { default as WebGL } from './components/layers/WebGL.svelte';
+export type { WebGLProps, WebGLPropsWithoutHTML } from './components/layers/WebGL.svelte';
+export { default as Layer } from './components/layers/Layer.svelte';
+export type { LayerProps } from './components/layers/Layer.svelte';
export { default as Axis } from './components/Axis/Axis.svelte';
export type { AxisProps, AxisLabelProps } from './components/Axis/Axis.svelte';
+export { default as Bar } from './components/Bar/Bar.svelte';
+export type { BarProps } from './components/Bar/Bar.svelte';
+export { default as Circle } from './components/Circle/Circle.svelte';
+export type { CircleProps } from './components/Circle/Circle.svelte';
+export { default as Group } from './components/Group/Group.svelte';
+export type { GroupProps } from './components/Group/Group.svelte';
+export { default as Graticule } from './components/Graticule/Graticule.svelte';
+export type { GraticuleProps } from './components/Graticule/Graticule.svelte';
export { default as Bars } from './components/Bars/Bars.svelte';
export { default as Bin } from './components/Bin/Bin.svelte';
export type { BinProps } from './components/Bin/Bin.svelte';
@@ -40,8 +88,16 @@ export { default as Rect } from './components/Rect/Rect.svelte';
export type { RectProps } from './components/Rect/Rect.svelte';
export { default as Text } from './components/Text/Text.svelte';
export type { TextProps } from './components/Text/Text.svelte';
+export { default as Image } from './components/Image/Image.svelte';
+export type { ImageProps } from './components/Image/Image.svelte';
+export { default as Ellipse } from './components/Ellipse/Ellipse.svelte';
+export type { EllipseProps } from './components/Ellipse/Ellipse.svelte';
export { default as Area } from './components/Area/Area.svelte';
export type { AreaProps } from './components/Area/Area.svelte';
+export { default as Line } from './components/Line/Line.svelte';
+export type { LineProps } from './components/Line/Line.svelte';
+export { default as Path } from './components/Path/Path.svelte';
+export type { PathProps } from './components/Path/Path.svelte';
export { default as Link } from './components/Link/Link.svelte';
export type { LinkProps } from './components/Link/Link.svelte';
export { default as Highlight } from './components/Highlight/Highlight.svelte';
@@ -66,3 +122,74 @@ export { globe } from './utils/globe.js';
export type { Sphere } from './utils/globe.js';
export type { ImageSource } from './utils/texture.js';
export type { GridDataProps } from './utils/grid.js';
+
+// LayerChart's compound marks, built of the marks here
+export { default as AnnotationLine } from './components/AnnotationLine/AnnotationLine.svelte';
+export type { AnnotationLineProps } from './components/AnnotationLine/AnnotationLine.svelte';
+export { default as AnnotationPoint } from './components/AnnotationPoint/AnnotationPoint.svelte';
+export type { AnnotationPointProps } from './components/AnnotationPoint/AnnotationPoint.svelte';
+export { default as AnnotationRange } from './components/AnnotationRange/AnnotationRange.svelte';
+export type { AnnotationRangeProps } from './components/AnnotationRange/AnnotationRange.svelte';
+export { default as BoxPlot } from './components/BoxPlot/BoxPlot.svelte';
+export type { BoxPlotProps } from './components/BoxPlot/BoxPlot.svelte';
+export { default as Calendar } from './components/Calendar/Calendar.svelte';
+export type { CalendarProps } from './components/Calendar/Calendar.svelte';
+export { default as Cell } from './components/Cell/Cell.svelte';
+export type { CellProps } from './components/Cell/Cell.svelte';
+export { default as Frame } from './components/Frame/Frame.svelte';
+export type { FrameProps } from './components/Frame/Frame.svelte';
+export { default as GeoPoint } from './components/GeoPoint/GeoPoint.svelte';
+export type { GeoPointProps } from './components/GeoPoint/GeoPoint.svelte';
+export { default as Hull } from './components/Hull/Hull.svelte';
+export type { HullProps } from './components/Hull/Hull.svelte';
+export { default as Labels } from './components/Labels/Labels.svelte';
+export type { LabelsProps } from './components/Labels/Labels.svelte';
+export { default as LinearGradient } from './components/LinearGradient/LinearGradient.svelte';
+export type { LinearGradientProps } from './components/LinearGradient/LinearGradient.svelte';
+export { default as Pattern } from './components/Pattern/Pattern.svelte';
+export type { PatternProps } from './components/Pattern/Pattern.svelte';
+export { default as Month } from './components/Month/Month.svelte';
+export type { MonthProps } from './components/Month/Month.svelte';
+export { default as Pie } from './components/Pie/Pie.svelte';
+export type { PieProps } from './components/Pie/Pie.svelte';
+export { default as Waffle } from './components/Waffle/Waffle.svelte';
+export type { WaffleProps } from './components/Waffle/Waffle.svelte';
+export { default as Voronoi } from './components/Voronoi/Voronoi.svelte';
+export type { VoronoiProps } from './components/Voronoi/Voronoi.svelte';
+export { default as GeoBin } from './components/GeoBin/GeoBin.svelte';
+export type { GeoBinProps } from './components/GeoBin/GeoBin.svelte';
+export { default as GeoCircle } from './components/GeoCircle/GeoCircle.svelte';
+export type { GeoCircleProps } from './components/GeoCircle/GeoCircle.svelte';
+export { default as GeoSpline } from './components/GeoSpline/GeoSpline.svelte';
+export type { GeoSplineProps } from './components/GeoSpline/GeoSpline.svelte';
+export { default as GeoEdgeFade } from './components/GeoEdgeFade/GeoEdgeFade.svelte';
+export type { GeoEdgeFadeProps } from './components/GeoEdgeFade/GeoEdgeFade.svelte';
+export { default as Brush } from './components/Brush/Brush.svelte';
+export type { BrushProps } from './components/Brush/Brush.svelte';
+
+export { default as ArcLabel } from './components/ArcLabel/ArcLabel.svelte';
+export type { ArcLabelProps } from './components/ArcLabel/ArcLabel.svelte';
+
+// LayerChart's simplified charts, drawn with the marks here in whichever layer they're in
+export { default as ArcChart } from './components/charts/ArcChart.svelte';
+export type { ArcChartProps } from './components/charts/ArcChart.svelte';
+export { default as AreaChart } from './components/charts/AreaChart.svelte';
+export type { AreaChartProps } from './components/charts/AreaChart.svelte';
+export { default as BarChart } from './components/charts/BarChart.svelte';
+export type { BarChartProps } from './components/charts/BarChart.svelte';
+export { default as LineChart } from './components/charts/LineChart.svelte';
+export type { LineChartProps } from './components/charts/LineChart.svelte';
+export { default as PieChart } from './components/charts/PieChart.svelte';
+export type { PieChartProps } from './components/charts/PieChart.svelte';
+export { default as ScatterChart } from './components/charts/ScatterChart.svelte';
+export type { ScatterChartProps } from './components/charts/ScatterChart.svelte';
+
+// LayerChart's marks drawn with `Path`
+export { default as Violin } from './components/Violin/Violin.svelte';
+export type { ViolinProps } from './components/Violin/Violin.svelte';
+export { default as Trail } from './components/Trail/Trail.svelte';
+export type { TrailProps } from './components/Trail/Trail.svelte';
+export { default as Density } from './components/Density/Density.svelte';
+export type { DensityProps } from './components/Density/Density.svelte';
+export { default as Ribbon } from './components/Ribbon/Ribbon.svelte';
+export type { RibbonProps } from './components/Ribbon/Ribbon.svelte';
diff --git a/packages/webgl/src/lib/utils/clip.ts b/packages/webgl/src/lib/utils/clip.ts
new file mode 100644
index 0000000000..edd801ed9d
--- /dev/null
+++ b/packages/webgl/src/lib/utils/clip.ts
@@ -0,0 +1,191 @@
+import { Plane, Vector3, type Camera, type Material, type Object3D } from 'three';
+
+/**
+ * A clip shape drawn as a mask the marks inside sample (see `clipMask.ts`, loaded only when a
+ * clip isn't a plain rectangle)
+ */
+export interface SceneClipMask {
+ /** Fit the mask to `object`'s frame as `camera` sees it, for this frame */
+ update(object: Object3D, camera: Camera): void;
+ /** Clip `material` to the mask (it's recompiled to sample it) */
+ attach(material: Material): void;
+ /** Stop clipping `material` to the mask */
+ detach(material: Material): void;
+ /** Whether a point of its frame (`x` across, `y` down) is inside the shape */
+ contains(x: number, y: number): boolean;
+ dispose(): void;
+}
+
+/** A rectangle of a clip's frame, `x` across and `y` down, in the chart's pixels */
+export type ClipRect = { x: number; y: number; width: number; height: number };
+
+/** What clips a mark: the planes of its clips' rectangles, and the nearest one's mask */
+export type ClipChain = {
+ /** Its clips' rectangles' sides, in the scene's (world) space */
+ planes: Plane[];
+ /** And the plot box's */
+ withPlot: Plane[];
+ mask: SceneClipMask | null;
+};
+
+/** A plane every point is behind: a clip waiting for its mask draws nothing */
+const NOTHING = new Plane(new Vector3(1, 0, 0), -1e12);
+
+/**
+ * A clip a `ClipPath` puts on its group (its `userData.clip`): what's in the group is drawn only
+ * inside its rectangle (as clipping planes, exact and cheap) or its mask (any shape), and inside
+ * any clip it's in
+ */
+export class SceneClip {
+ disabled = false;
+ rect: ClipRect | null = null;
+ mask: SceneClipMask | null = null;
+ /** Its mask is loading: nothing inside is drawn until it's ready */
+ pending = false;
+ /** Called each frame before it clips (ex. to repaint its mask from shapes that have changed) */
+ refresh: (() => void) | null = null;
+
+ readonly #chain: ClipChain = { planes: [], withPlot: [], mask: null };
+ readonly #own = [new Plane(), new Plane(), new Plane(), new Plane()];
+
+ /** What clips the marks inside, in `outer` (the clips it's in), this frame */
+ chain(object: Object3D, outer: ClipChain | null, plot: Plane[], camera: Camera) {
+ if (this.disabled) return outer;
+ this.refresh?.();
+ const chain = this.#chain;
+ chain.planes.length = 0;
+ if (outer) chain.planes.push(...outer.planes);
+ if (this.pending) {
+ chain.planes.push(NOTHING);
+ } else if (this.rect) {
+ // Its sides in its group's frame (chart `x` along the scene's `x`, `y` along its `z`),
+ // then where that frame is in the scene
+ const { x, y, width, height } = this.rect;
+ const [left, right, top, bottom] = this.#own;
+ left.set(left.normal.set(1, 0, 0), -Math.min(x, x + width));
+ right.set(right.normal.set(-1, 0, 0), Math.max(x, x + width));
+ top.set(top.normal.set(0, 0, 1), -Math.min(y, y + height));
+ bottom.set(bottom.normal.set(0, 0, -1), Math.max(y, y + height));
+ for (const plane of this.#own) chain.planes.push(plane.applyMatrix4(object.matrixWorld));
+ }
+ chain.withPlot.length = 0;
+ chain.withPlot.push(...plot, ...chain.planes);
+ if (this.mask && !this.pending) this.mask.update(object, camera);
+ chain.mask = (this.pending ? null : this.mask) ?? outer?.mask ?? null;
+ return chain;
+ }
+
+ /** Whether a point of its group's frame is drawn (inside its rectangle or mask) */
+ contains(x: number, y: number) {
+ if (this.disabled) return true;
+ if (this.pending) return false;
+ if (this.rect) {
+ const { x: rx, y: ry, width, height } = this.rect;
+ const inside =
+ x >= Math.min(rx, rx + width) &&
+ x <= Math.max(rx, rx + width) &&
+ y >= Math.min(ry, ry + height) &&
+ y <= Math.max(ry, ry + height);
+ if (!inside) return false;
+ }
+ return this.mask ? this.mask.contains(x, y) : true;
+ }
+}
+
+const NUMBER = String.raw`([-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)`;
+const RECT = new RegExp(
+ String.raw`^\s*M\s*${NUMBER}[\s,]+${NUMBER}\s*h\s*${NUMBER}\s*v\s*${NUMBER}\s*h\s*${NUMBER}\s*z\s*$`,
+ 'i'
+);
+
+/**
+ * The rectangle path data draws, if it's a plain one as `RectClipPath` draws (`M x,y h w v h h -w
+ * Z`), to clip to with planes rather than a mask
+ */
+export function rectOf(path: string): ClipRect | null {
+ const match = RECT.exec(path);
+ if (!match) return null;
+ const [x, y, width, height, back] = match.slice(1).map(Number);
+ return back === -width ? { x, y, width, height } : null;
+}
+
+const own = (o: object, key: string) => Object.prototype.hasOwnProperty.call(o, key);
+
+/**
+ * The material to draw `object` with, clipped by `planes` and `chain`'s mask: its own, unless it
+ * shares it with an object clipped otherwise this frame (ex. a label's painting, shared by the
+ * planes showing the same text), when it's given a copy of its own. Without `object` (one of a
+ * mesh's several materials) it's always its own.
+ */
+export function clipMaterial(
+ object: (Object3D & { material: Material | Material[] }) | null,
+ material: Material,
+ planes: Plane[] | null,
+ chain: ClipChain | null,
+ frame: number
+) {
+ let m = material;
+ const data = m.userData;
+ if (
+ object &&
+ data.lcClipFrame === frame &&
+ (data.lcClipPlanes !== planes || data.lcClipChain !== chain)
+ ) {
+ const copy = m.clone();
+ // What `clone` leaves behind: its own shader changes (before any mask's), and its `userData`
+ // as it is (not copied through JSON)
+ const source = (data.lcMaskOwn as Record | undefined) ?? m;
+ for (const key of ['onBeforeCompile', 'customProgramCacheKey'] as const) {
+ if (own(source, key)) (copy as any)[key] = (source as any)[key];
+ }
+ copy.userData = { ...data, lcMask: undefined, lcMaskOwn: undefined, lcClipFrame: undefined };
+ m.addEventListener('dispose', () => copy.dispose());
+ object.material = copy;
+ m = copy;
+ }
+ m.userData.lcClipFrame = frame;
+ m.userData.lcClipPlanes = planes;
+ m.userData.lcClipChain = chain;
+ m.clippingPlanes = planes;
+ const mask = chain?.mask ?? null;
+ const current = (m.userData.lcMask as SceneClipMask | undefined) ?? null;
+ if (current !== mask) {
+ current?.detach(m);
+ mask?.attach(m);
+ }
+ return m;
+}
+
+/**
+ * Save a material's own shader changes (see `clipMaterial`), before a mask replaces them with its
+ * own that call them
+ */
+export function saveOwnShader(material: Material) {
+ const saved: Record = {};
+ for (const key of ['onBeforeCompile', 'customProgramCacheKey']) {
+ if (own(material, key)) saved[key] = (material as any)[key];
+ }
+ material.userData.lcMaskOwn = saved;
+ return saved;
+}
+
+/** Put back a material's own shader changes, as `saveOwnShader` saved them */
+export function restoreOwnShader(material: Material) {
+ const saved = (material.userData.lcMaskOwn ?? {}) as Record;
+ for (const key of ['onBeforeCompile', 'customProgramCacheKey']) {
+ if (key in saved) (material as any)[key] = saved[key];
+ else delete (material as any)[key];
+ }
+ delete material.userData.lcMaskOwn;
+}
+
+/** Whether a point in the scene on `object` is drawn, inside every clip it's in */
+export function clipKeeps(object: Object3D, point: Vector3) {
+ for (let o: Object3D | null = object; o; o = o.parent) {
+ const clip = o.userData.clip as SceneClip | undefined;
+ if (!clip) continue;
+ const local = o.worldToLocal(point.clone());
+ if (!clip.contains(local.x, local.z)) return false;
+ }
+ return true;
+}
diff --git a/packages/webgl/src/lib/utils/clipMask.ts b/packages/webgl/src/lib/utils/clipMask.ts
new file mode 100644
index 0000000000..c2a9d8e136
--- /dev/null
+++ b/packages/webgl/src/lib/utils/clipMask.ts
@@ -0,0 +1,319 @@
+import {
+ CanvasTexture,
+ LinearFilter,
+ Matrix4,
+ Vector3,
+ type BufferAttribute,
+ type Camera,
+ type InstancedMesh,
+ type InterleavedBufferAttribute,
+ type Mesh,
+ type Material,
+ type Object3D,
+ type WebGLProgramParametersWithUniforms,
+} from 'three';
+
+import { restoreOwnShader, saveOwnShader, type SceneClipMask } from './clip.js';
+import { parsePath } from './path.js';
+
+/** The least and most `x` and `y` of points, skipping any that aren't finite */
+class Bounds {
+ x0 = Infinity;
+ y0 = Infinity;
+ x1 = -Infinity;
+ y1 = -Infinity;
+ add(x: number, y: number) {
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return;
+ this.x0 = Math.min(this.x0, x);
+ this.y0 = Math.min(this.y0, y);
+ this.x1 = Math.max(this.x1, x);
+ this.y1 = Math.max(this.y1, y);
+ }
+}
+
+/**
+ * Whether a mesh is a shape's fill: not its outline (fat lines are meshes too) nor a label's
+ * plane (a painting)
+ */
+function isFill(mesh: Mesh) {
+ const line = mesh as Mesh & { isLineSegments2?: boolean; isLine2?: boolean };
+ if (line.isLineSegments2 || line.isLine2) return false;
+ const material = mesh.material as Material & { map?: unknown };
+ return !(material && !Array.isArray(material) && material.map);
+}
+
+/** The most pixels a mask's canvas is across or down */
+const MAX_SIZE = 4096;
+
+/**
+ * A clip shape (SVG path data, in its `ClipPath`'s frame) painted onto a canvas, which the marks
+ * inside sample: each fragment is drawn only where the canvas is painted under it, looked up by
+ * where it is on the plot (its `x` across and `y` down), so the shape clips the same seen from any
+ * angle, as a stencil would from above. Loaded only when a clip isn't a plain rectangle.
+ */
+export class ClipMask implements SceneClipMask {
+ readonly #canvas = document.createElement('canvas');
+ readonly #context = this.#canvas.getContext('2d')!;
+ #texture = this.#makeTexture();
+ /** The mask's lookup: a point in the camera's space to the mask's texture (`x` and `z`) */
+ readonly #lookup = new Matrix4();
+ /** Its frame to the texture */
+ readonly #fit = new Matrix4();
+ readonly uniforms = { lcMask: { value: this.#texture }, lcMaskLookup: { value: this.#lookup } };
+ /** Its shapes, each filled on its own, so where they overlap they add up (as SVG's do) */
+ #shapes: Path2D[] = [];
+ #rule: CanvasFillRule = 'nonzero';
+ /** The materials clipped to it */
+ readonly #materials = new Set();
+
+ #makeTexture() {
+ const texture = new CanvasTexture(this.#canvas);
+ // The canvas' top row is the frame's least `y`, where the texture's `v` is 0
+ texture.flipY = false;
+ texture.generateMipmaps = false;
+ texture.minFilter = LinearFilter;
+ texture.magFilter = LinearFilter;
+ return texture;
+ }
+
+ /**
+ * Paint `path` (`evenodd` for an inverted clip, as the core `ClipPath` fills it), at `scale`
+ * canvas pixels per chart pixel
+ */
+ draw(path: string, rule: CanvasFillRule, scale: number) {
+ const bounds = new Bounds();
+ for (const { points } of parsePath(path)) {
+ for (const [x, y] of points) bounds.add(x, y);
+ }
+ this.#paint([new Path2D(path)], rule, bounds, scale);
+ }
+
+ /**
+ * Paint the fills of the meshes in `source` (a `ClipPath`'s `clip` snippet's marks, drawn there
+ * rather than in the scene), as seen from above, and `paths` (its SVG elements' shapes, see
+ * `elementPaths`), as an SVG `` takes the shapes in it: their fills' outlines,
+ * whatever their colors
+ */
+ drawShapes(source: Object3D, paths: string[], scale: number) {
+ source.updateMatrixWorld(true);
+ const shape = new Path2D();
+ const shapes = [shape];
+ const bounds = new Bounds();
+ for (const path of paths) {
+ shapes.push(new Path2D(path));
+ for (const { points } of parsePath(path)) {
+ for (const [x, y] of points) bounds.add(x, y);
+ }
+ }
+ const point = new Vector3();
+ const corners: number[] = [];
+ const matrix = new Matrix4();
+ source.traverseVisible((object) => {
+ const mesh = object as Mesh;
+ if (!mesh.isMesh || !isFill(mesh)) return;
+ const position = mesh.geometry.getAttribute('position');
+ if (!position) return;
+ const index = mesh.geometry.getIndex();
+ const count = index ? index.count : position.count;
+ const instanced = mesh as InstancedMesh;
+ // Each instance where it's placed (ex. a `Circle`'s), else the mesh where it is
+ const placements = instanced.isInstancedMesh ? instanced.count : 1;
+ for (let n = 0; n < placements; n++) {
+ if (instanced.isInstancedMesh) {
+ instanced.getMatrixAt(n, matrix);
+ matrix.premultiply(mesh.matrixWorld);
+ } else {
+ matrix.copy(mesh.matrixWorld);
+ }
+ triangles(position, index, count, matrix);
+ }
+ });
+ this.#paint(shapes, 'nonzero', bounds, scale);
+
+ function triangles(
+ position: BufferAttribute | InterleavedBufferAttribute,
+ index: BufferAttribute | null,
+ count: number,
+ matrix: Matrix4
+ ) {
+ for (let i = 0; i + 2 < count; i += 3) {
+ corners.length = 0;
+ for (let j = 0; j < 3; j++) {
+ const vertex = index ? index.getX(i + j) : i + j;
+ point.fromBufferAttribute(position, vertex).applyMatrix4(matrix);
+ // Across and down the plot (the scene's `x` and `z`)
+ corners.push(point.x, point.z);
+ }
+ const [ax, ay, bx, by, cx, cy] = corners;
+ const area = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
+ // Edge on from above (ex. an extruded shape's sides): nothing to fill
+ if (!(Math.abs(area) > 1e-9)) continue;
+ // Each the same way round, so where they overlap (ex. an extruded shape's top and bottom)
+ // they add up rather than cancel out under the `nonzero` rule
+ shape.moveTo(ax, ay);
+ if (area > 0) {
+ shape.lineTo(bx, by);
+ shape.lineTo(cx, cy);
+ } else {
+ shape.lineTo(cx, cy);
+ shape.lineTo(bx, by);
+ }
+ shape.closePath();
+ bounds.add(ax, ay);
+ bounds.add(bx, by);
+ bounds.add(cx, cy);
+ }
+ }
+ }
+
+ #paint(shapes: Path2D[], rule: CanvasFillRule, bounds: Bounds, scale: number) {
+ let { x0, y0, x1, y1 } = bounds;
+ if (!(x1 >= x0 && y1 >= y0)) x0 = y0 = x1 = y1 = 0;
+ // A pixel around it, for its edges' antialiasing
+ x0 = Math.floor(x0) - 1;
+ y0 = Math.floor(y0) - 1;
+ const width = Math.ceil(x1) + 1 - x0;
+ const height = Math.ceil(y1) + 1 - y0;
+ const k = Math.min(scale, MAX_SIZE / Math.max(width, height, 1));
+ const canvasWidth = Math.max(1, Math.ceil(width * k));
+ const canvasHeight = Math.max(1, Math.ceil(height * k));
+
+ // A texture keeps the size it's first given: a new one for a new size
+ if (canvasWidth !== this.#canvas.width || canvasHeight !== this.#canvas.height) {
+ this.#canvas.width = canvasWidth;
+ this.#canvas.height = canvasHeight;
+ this.#texture.dispose();
+ this.#texture = this.#makeTexture();
+ this.uniforms.lcMask.value = this.#texture;
+ }
+ const context = this.#context;
+ context.setTransform(1, 0, 0, 1, 0, 0);
+ context.clearRect(0, 0, canvasWidth, canvasHeight);
+ context.setTransform(k, 0, 0, k, -x0 * k, -y0 * k);
+ this.#shapes = shapes;
+ this.#rule = rule;
+ context.fillStyle = '#fff';
+ for (const shape of shapes) context.fill(shape, rule);
+ this.#texture.needsUpdate = true;
+ // Across and down its frame (the scene's `x` and `z`) to the texture's `u` and `v`
+ const sx = canvasWidth / k;
+ const sy = canvasHeight / k;
+ this.#fit.set(1 / sx, 0, 0, -x0 / sx, 0, 1, 0, 0, 0, 0, 1 / sy, -y0 / sy, 0, 0, 0, 1);
+ }
+
+ /**
+ * The shapes of the SVG elements in `host` (ex. a `clip` snippet's `` and ``), as
+ * path data, by their attributes (they're never laid out)
+ */
+ elementPaths(host: Element) {
+ const paths: string[] = [];
+ const number = (element: Element, name: string) => Number(element.getAttribute(name)) || 0;
+ for (const element of host.querySelectorAll('path, rect, circle, ellipse, polygon')) {
+ switch (element.localName) {
+ case 'path': {
+ const d = element.getAttribute('d');
+ if (d) paths.push(d);
+ break;
+ }
+ case 'rect': {
+ const [x, y] = [number(element, 'x'), number(element, 'y')];
+ const [width, height] = [number(element, 'width'), number(element, 'height')];
+ if (width > 0 && height > 0) paths.push(`M${x},${y}h${width}v${height}h${-width}Z`);
+ break;
+ }
+ case 'circle':
+ case 'ellipse': {
+ const [cx, cy] = [number(element, 'cx'), number(element, 'cy')];
+ const rx = number(element, element.localName === 'circle' ? 'r' : 'rx');
+ const ry = element.localName === 'circle' ? rx : number(element, 'ry');
+ if (rx > 0 && ry > 0) {
+ paths.push(
+ `M${cx - rx},${cy}a${rx},${ry} 0 1,0 ${2 * rx},0a${rx},${ry} 0 1,0 ${-2 * rx},0Z`
+ );
+ }
+ break;
+ }
+ case 'polygon': {
+ const points = element.getAttribute('points')?.trim();
+ if (points) paths.push(`M${points.split(/[\s,]+/).join(' ')}Z`);
+ break;
+ }
+ }
+ }
+ return paths;
+ }
+
+ update(object: Object3D, camera: Camera) {
+ this.#lookup
+ .copy(object.matrixWorld)
+ .invert()
+ .multiply(camera.matrixWorld)
+ .premultiply(this.#fit);
+ }
+
+ contains(x: number, y: number) {
+ if (!this.#shapes.length) return false;
+ this.#context.save();
+ this.#context.setTransform(1, 0, 0, 1, 0, 0);
+ const inside = this.#shapes.some((shape) =>
+ this.#context.isPointInPath(shape, x, y, this.#rule)
+ );
+ this.#context.restore();
+ return inside;
+ }
+
+ attach(material: Material) {
+ const saved = saveOwnShader(material);
+ const before = (saved.onBeforeCompile as Material['onBeforeCompile']) ?? null;
+ const key = material.customProgramCacheKey();
+ const uniforms = this.uniforms;
+ material.onBeforeCompile = function (shader, renderer) {
+ before?.call(this, shader, renderer);
+ maskShader(shader, uniforms);
+ };
+ material.customProgramCacheKey = () => `${key}|lc-clip-mask`;
+ material.userData.lcMask = this;
+ material.needsUpdate = true;
+ this.#materials.add(material);
+ }
+
+ detach(material: Material) {
+ restoreOwnShader(material);
+ delete material.userData.lcMask;
+ material.needsUpdate = true;
+ this.#materials.delete(material);
+ }
+
+ dispose() {
+ for (const material of [...this.#materials]) this.detach(material);
+ this.#texture.dispose();
+ this.#shapes = [];
+ }
+}
+
+/**
+ * A material's shaders, dropping fragments outside the mask: where a fragment is on the plot,
+ * from its position in the camera's space (as its clipping planes take it, so every material that
+ * can be clipped can be masked), looked up in the mask's texture
+ */
+function maskShader(shader: WebGLProgramParametersWithUniforms, uniforms: ClipMask['uniforms']) {
+ shader.uniforms.lcMask = uniforms.lcMask;
+ shader.uniforms.lcMaskLookup = uniforms.lcMaskLookup;
+ shader.vertexShader = shader.vertexShader
+ .replace('#include ', '$&\nvarying vec3 vLcClipView;')
+ .replace('#include ', '$&\nvLcClipView = mvPosition.xyz;');
+ shader.fragmentShader = shader.fragmentShader
+ .replace(
+ '#include ',
+ '$&\nvarying vec3 vLcClipView;\nuniform sampler2D lcMask;\nuniform mat4 lcMaskLookup;'
+ )
+ .replace(
+ '#include ',
+ `$&
+{
+ vec2 lcMaskUv = ( lcMaskLookup * vec4( vLcClipView, 1.0 ) ).xz;
+ if ( any( lessThan( lcMaskUv, vec2( 0.0 ) ) ) || any( greaterThan( lcMaskUv, vec2( 1.0 ) ) ) ||
+ texture2D( lcMask, lcMaskUv ).a < 0.5 ) discard;
+}`
+ );
+}
diff --git a/packages/webgl/src/lib/utils/color.ts b/packages/webgl/src/lib/utils/color.ts
index 420fd8514d..5dc45b2ea1 100644
--- a/packages/webgl/src/lib/utils/color.ts
+++ b/packages/webgl/src/lib/utils/color.ts
@@ -7,12 +7,30 @@ export type ResolvedColor = { color: Color; opacity: number };
* reads them: `null` for what they leave alone
*/
export type ClassStyle = {
+ /** The fill its classes set, or the `--fill-color` LayerChart's styles give its marks */
fill: string | null;
stroke: string | null;
+ /**
+ * Whether its classes set the fill itself (ex. `fill-primary/20`), which wins over a mark's
+ * `fill` prop as CSS wins over an SVG attribute in core's layers, rather than a
+ * `--fill-color` default, which doesn't
+ */
+ fillSet: boolean;
+ strokeSet: boolean;
+ /** Whether its classes take its stroke away (`stroke-none`) */
+ strokeNone?: boolean;
strokeWidth: number | null;
opacity: number;
/** Its `mix-blend-mode`, when not `normal` (ex. `plus-lighter`) */
blend: string | null;
+ /** Its font size in pixels: its class's (ex. `text-xs`), else what it inherits there */
+ fontSize: number;
+ /** Its font weight: its class's (ex. `font-semibold`), else what it inherits there */
+ fontWeight: string;
+ /** The `stroke-dasharray` its classes set, in pixels (ex. `4, 4`), else `null` */
+ strokeDasharray?: string | null;
+ /** The text color its classes set (ex. `text-primary`), which a label's fill follows */
+ color?: string | null;
};
/**
@@ -24,7 +42,11 @@ export class ColorResolver {
#probe: HTMLElement;
#context: CanvasRenderingContext2D | null = null;
#cache = new Map();
- #styles = new Map();
+ /** Each class and attribute set read, by its key, with what it read */
+ #styles = new Map<
+ string,
+ { classes: string; attributes?: Record; style: ClassStyle }
+ >();
/** An SVG path to give classes to and read back, and one without, to tell what they set */
#classed: SVGPathElement | null = null;
#plain: SVGPathElement | null = null;
@@ -45,46 +67,93 @@ export class ColorResolver {
this.#cache.set(value, next);
changed = true;
}
- for (const [classes, previous] of this.#styles) {
- const next = this.#read(classes);
- if (JSON.stringify(next) === JSON.stringify(previous)) continue;
- this.#styles.set(classes, next);
+ for (const entry of this.#styles.values()) {
+ const next = this.#read(entry.classes, entry.attributes);
+ if (JSON.stringify(next) === JSON.stringify(entry.style)) continue;
+ entry.style = next;
changed = true;
}
return changed;
}
- /** What `classes` set on an SVG shape here (see `ClassStyle`) */
- style(classes: string): ClassStyle {
- let style = this.#styles.get(classes);
- if (!style) {
- style = this.#read(classes);
- this.#styles.set(classes, style);
+ /**
+ * What `classes` set on an SVG shape here (see `ClassStyle`), with its `attributes` (ex. a
+ * label's `data-placement`, which LayerChart's styles read)
+ */
+ style(classes: string, attributes?: Record): ClassStyle {
+ const key = attributes ? `${classes}\u0000${JSON.stringify(attributes)}` : classes;
+ let entry = this.#styles.get(key);
+ if (!entry) {
+ entry = { classes, attributes, style: this.#read(classes, attributes) };
+ this.#styles.set(key, entry);
}
- return style;
+ return entry.style;
}
- #read(classes: string): ClassStyle {
+ #read(classes: string, attributes?: Record): ClassStyle {
if (!this.#classed || !this.#plain) {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.style.display = 'none';
+ // Defaults no class sets (ex. not black, SVG's own fill, which `fill-black` sets), so a
+ // class setting one is told from none
+ svg.style.fill = 'rgb(1, 2, 3)';
+ svg.style.stroke = 'rgb(3, 2, 1)';
+ // Not 1px, SVG's own, which `stroke-1` sets
+ svg.style.strokeWidth = '1.0625px';
+ // A text color of its own, not the probe's (which `resolve` sets), so a class's (ex.
+ // `text-primary`) is told from none
+ svg.style.color = 'rgb(1, 2, 4)';
this.#classed = document.createElementNS('http://www.w3.org/2000/svg', 'path');
this.#plain = document.createElementNS('http://www.w3.org/2000/svg', 'path');
svg.append(this.#classed, this.#plain);
this.#probe.append(svg);
}
this.#classed.setAttribute('class', classes);
+ for (const name of [...this.#classed.getAttributeNames()]) {
+ if (name !== 'class') this.#classed.removeAttribute(name);
+ }
+ for (const [name, value] of Object.entries(attributes ?? {})) {
+ this.#classed.setAttribute(name, value);
+ }
const style = getComputedStyle(this.#classed);
const plain = getComputedStyle(this.#plain);
- const set = (key: 'fill' | 'stroke' | 'strokeWidth') =>
- style[key] !== plain[key] ? style[key] : null;
+ /** The text color its classes set, else `null` (the probe's own, see above) */
+ const color = style.color !== plain.color ? style.color : null;
+ const set = (key: 'fill' | 'stroke' | 'strokeWidth') => {
+ if (style[key] === plain[key]) return null;
+ // `fill-current` with no text color of its own: the color it inherits where it's drawn
+ return key !== 'strokeWidth' && color == null && style[key] === style.color
+ ? 'currentColor'
+ : style[key];
+ };
+ /**
+ * A color the classes set as LayerChart's do for their marks (ex. `.lc-highlight-area`'s
+ * `--fill-color`), which its SVG primitives read
+ */
+ const variable = (name: '--fill-color' | '--stroke-color') => {
+ const value = style.getPropertyValue(name).trim();
+ return value && value !== plain.getPropertyValue(name).trim() ? value : null;
+ };
const strokeWidth = set('strokeWidth');
+ const fill = set('fill');
+ // `stroke-none` as no stroke at all, as before the probe had one to tell it from
+ const stroke = set('stroke') === 'none' ? null : set('stroke');
return {
- fill: set('fill'),
- stroke: set('stroke'),
+ fill: fill ?? variable('--fill-color'),
+ stroke: stroke ?? variable('--stroke-color'),
+ fillSet: fill != null,
+ strokeSet: stroke != null,
+ strokeNone: set('stroke') === 'none',
strokeWidth: strokeWidth == null ? null : parseFloat(strokeWidth),
opacity: Number(style.opacity) * Number(style.fillOpacity || 1),
blend: style.mixBlendMode && style.mixBlendMode !== 'normal' ? style.mixBlendMode : null,
+ fontSize: parseFloat(style.fontSize),
+ fontWeight: style.fontWeight,
+ strokeDasharray:
+ style.strokeDasharray !== plain.strokeDasharray && style.strokeDasharray !== 'none'
+ ? style.strokeDasharray.replace(/px/g, '')
+ : null,
+ color,
};
}
diff --git a/packages/webgl/src/lib/utils/contours.ts b/packages/webgl/src/lib/utils/contours.ts
index 02bf2c25ac..73ef811240 100644
--- a/packages/webgl/src/lib/utils/contours.ts
+++ b/packages/webgl/src/lib/utils/contours.ts
@@ -19,25 +19,56 @@ export function contourSegments(
grid: Grid,
extent: [number, number],
thresholds: number | number[],
- height: (value: number) => number
+ height: (value: number) => number,
+ options: ContourLevelOptions = {}
): number[] {
+ return contourLevels(grid, extent, thresholds, height, options).flatMap(
+ (level) => level.segments
+ );
+}
+
+export type ContourLevelOptions = {
+ /** Interpolate where lines cross each cell, else run them along the cells' corners */
+ smooth?: boolean;
+ /**
+ * Keep where the rings close along the grid's edges, and count `thresholds` from the values'
+ * nice extent, as the core `Contour` draws its bands' outlines
+ */
+ edges?: boolean;
+};
+
+/**
+ * Each threshold's contour lines through a grid (see `contourSegments`), with its value: ex. to
+ * color each level's lines by it
+ */
+export function contourLevels(
+ grid: Grid,
+ extent: [number, number],
+ thresholds: number | number[],
+ height: (value: number) => number,
+ { smooth = true, edges = false }: ContourLevelOptions = {}
+): { value: number; segments: number[] }[] {
const { values, columns, rows } = grid;
- const levels = Array.isArray(thresholds) ? thresholds : ticks(extent[0], extent[1], thresholds);
+ // A count as the core `Contour`'s (d3's, from a nice extent), else evenly spaced over `extent`
+ const levels =
+ Array.isArray(thresholds) || edges ? thresholds : ticks(extent[0], extent[1], thresholds);
// Holes close around themselves rather than leaving lines open
const field = Array.from(values, (v) => (Number.isFinite(v) ? v : -Infinity));
- const generator = d3Contours().size([columns, rows]).thresholds(levels);
+ const generator = d3Contours().size([columns, rows]).smooth(smooth);
+ if (typeof levels === 'number') generator.thresholds(levels);
+ else generator.thresholds(levels);
const onEdge = (x: number, y: number) => x <= 0 || y <= 0 || x >= columns || y >= rows;
- const segments: number[] = [];
- for (const contour of generator(field)) {
+ return generator(field).map((contour) => {
const z = height(contour.value);
+ const segments: number[] = [];
for (const polygon of contour.coordinates) {
for (const ring of polygon) {
for (let k = 0; k < ring.length - 1; k++) {
const [x0, y0] = ring[k];
const [x1, y1] = ring[k + 1];
// The rings close along the grid's edges, which aren't contour lines
- if (onEdge(x0, y0) && onEdge(x1, y1)) continue;
+ if (!edges && onEdge(x0, y0) && onEdge(x1, y1)) continue;
// A contour's `(x, y)` is in cells, value `(i, j)` sitting at `(i + 0.5, j + 0.5)`
const [ax, ay] = cellCenter(grid, x0 - 0.5, y0 - 0.5);
const [bx, by] = cellCenter(grid, x1 - 0.5, y1 - 0.5);
@@ -45,6 +76,6 @@ export function contourSegments(
}
}
}
- }
- return segments;
+ return { value: contour.value, segments };
+ });
}
diff --git a/packages/webgl/src/lib/utils/curve.ts b/packages/webgl/src/lib/utils/curve.ts
index 3da6d25fbd..ffff084036 100644
--- a/packages/webgl/src/lib/utils/curve.ts
+++ b/packages/webgl/src/lib/utils/curve.ts
@@ -1,17 +1,24 @@
import { line, type CurveFactory } from 'd3-shape';
-/** Points sampled along each curved segment */
+/** Points sampled along each curved segment, at most */
const STEPS = 12;
+/** Pixels between points sampled along a curved segment, at least, when `adaptive` */
+const STEP_LENGTH = 2;
/**
* A line through `points` (`[x, y]` on the floor) shaped by a d3 `curve`, as the core `Spline`
* draws it: each point sampled along it, with where it falls between the points it was drawn
- * through (`at`: `1.5` is halfway from the second to the third), for its height, color, and row
+ * through (`at`: `1.5` is halfway from the second to the third), for its height, color, and row.
+ * With `adaptive`, a short curved segment takes fewer points (one every couple of pixels), for
+ * long lines of many rows; else each takes the same number (ex. so an area's two edges pair up).
*/
export function curvePoints(
points: [number, number][],
- curve: CurveFactory
+ curve: CurveFactory,
+ { adaptive = false }: { adaptive?: boolean } = {}
): { x: number; y: number; at: number }[] {
+ const stepsFor = (length: number) =>
+ adaptive ? Math.max(1, Math.min(STEPS, Math.ceil(length / STEP_LENGTH))) : STEPS;
const sampled: [number, number][] = [];
let last: [number, number] = [0, 0];
const push = (x: number, y: number) => {
@@ -26,8 +33,13 @@ export function curvePoints(
closePath: () => sampled.length && push(...sampled[0]),
bezierCurveTo(c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number) {
const [x0, y0] = last;
- for (let i = 1; i <= STEPS; i++) {
- const t = i / STEPS;
+ const steps = stepsFor(
+ Math.hypot(c1x - x0, c1y - y0) +
+ Math.hypot(c2x - c1x, c2y - c1y) +
+ Math.hypot(x - c2x, y - c2y)
+ );
+ for (let i = 1; i <= steps; i++) {
+ const t = i / steps;
const u = 1 - t;
push(
u * u * u * x0 + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * x,
@@ -37,8 +49,9 @@ export function curvePoints(
},
quadraticCurveTo(cx: number, cy: number, x: number, y: number) {
const [x0, y0] = last;
- for (let i = 1; i <= STEPS; i++) {
- const t = i / STEPS;
+ const steps = stepsFor(Math.hypot(cx - x0, cy - y0) + Math.hypot(x - cx, y - cy));
+ for (let i = 1; i <= steps; i++) {
+ const t = i / steps;
const u = 1 - t;
push(u * u * x0 + 2 * u * t * cx + t * t * x, u * u * y0 + 2 * u * t * cy + t * t * y);
}
diff --git a/packages/webgl/src/lib/utils/dash.test.ts b/packages/webgl/src/lib/utils/dash.test.ts
new file mode 100644
index 0000000000..4bdbc182ac
--- /dev/null
+++ b/packages/webgl/src/lib/utils/dash.test.ts
@@ -0,0 +1,18 @@
+import { describe, expect, it } from 'vitest';
+import { dashPattern } from './merged.svelte.js';
+
+describe('dashPattern', () => {
+ it('reads a dashArray as the core marks take it: a length, an array, or a string', () => {
+ expect(dashPattern(4)).toEqual([4, 4]);
+ expect(dashPattern([6, 2])).toEqual([6, 2]);
+ expect(dashPattern([6, 2, 1, 2])).toEqual([6, 2]);
+ expect(dashPattern('3 1')).toEqual([3, 1]);
+ expect(dashPattern('3,1')).toEqual([3, 1]);
+ });
+
+ it('is solid without one', () => {
+ for (const none of [undefined, null, '', 'none', 0, [0, 2]]) {
+ expect(dashPattern(none as any)).toBeNull();
+ }
+ });
+});
diff --git a/packages/webgl/src/lib/utils/instances.svelte.ts b/packages/webgl/src/lib/utils/instances.svelte.ts
index 88c7c52865..d186021637 100644
--- a/packages/webgl/src/lib/utils/instances.svelte.ts
+++ b/packages/webgl/src/lib/utils/instances.svelte.ts
@@ -11,13 +11,19 @@ import {
MeshLambertMaterial,
NormalBlending,
Quaternion,
+ Vector2,
Vector3,
Vector4,
type BufferAttribute,
} from 'three';
import { getChartContext } from 'layerchart';
-import { getSceneContext } from '../contexts/scene.svelte.js';
+import {
+ getSceneContext,
+ groupOpacity,
+ hasEvents,
+ type MarkEvents,
+} from '../contexts/scene.svelte.js';
/**
* One shape of an instanced mark, in chart pixels: where it stands (`x` across, `y` down the
@@ -49,6 +55,8 @@ type InstancesOptions = {
emphasize: (color: Color, size: Vector3) => void;
/** Whether hovering shows the tooltip */
tooltip?: () => boolean;
+ /** Pointer handlers, called with the row under the pointer (as the core marks' `onclick`, ...) */
+ events?: () => MarkEvents | undefined;
/** Draw each instance in its own color, unlit (ex. a star) */
glow?: () => boolean;
/**
@@ -73,6 +81,11 @@ type InstancesOptions = {
* a circle's edge
*/
ring?: () => number;
+ /**
+ * Dash `ring`'s rings, `[dash, gap]` in scene units along each ring (from its rightmost point,
+ * clockwise as the plot is seen, as an SVG circle's dashes run), or `null` for none
+ */
+ dash?: () => [dash: number, gap: number] | null;
};
/**
@@ -105,6 +118,14 @@ export function ringGeometry(segments = 32) {
return geometry;
}
+/** A `dashPattern` in pixels on screen as scene units (`scale` of them a pixel), for `dash` */
+export function scaledDash(
+ pattern: [number, number] | null,
+ scale: number
+): [number, number] | null {
+ return pattern && [pattern[0] * scale, pattern[1] * scale];
+}
+
/** The `shift` a material draws with, shared by its compiled program */
const shifts = new WeakMap();
@@ -120,14 +141,18 @@ function createMaterial(lit: boolean, ring = false) {
material.userData.shift = shift.value;
const ringHalf = { value: 0 };
material.userData.ringHalf = ringHalf;
+ // Dashes are only compiled in while a ring has them (`LC_RING_DASH`)
+ const ringDash = { value: new Vector2() };
+ material.userData.ringDash = ringDash;
if (ring) material.defines = { LC_RING: '' };
material.onBeforeCompile = (shader) => {
shader.uniforms.uShift = shift;
shader.uniforms.uRingHalf = ringHalf;
+ shader.uniforms.uRingDash = ringDash;
shader.vertexShader = shader.vertexShader
.replace(
'#include ',
- '#include \nattribute float instanceOpacity;\nvarying float vInstanceOpacity;\nuniform vec4 uShift;\n#ifdef LC_RING\nattribute float ringSide;\nuniform float uRingHalf;\n#endif'
+ '#include \nattribute float instanceOpacity;\nvarying float vInstanceOpacity;\nuniform vec4 uShift;\n#ifdef LC_RING\nattribute float ringSide;\nuniform float uRingHalf;\n#endif\n#ifdef LC_RING_DASH\nvarying vec2 vRingPoint;\nvarying float vRingRadius;\n#endif'
)
.replace(
'#include ',
@@ -136,6 +161,10 @@ function createMaterial(lit: boolean, ring = false) {
vInstanceOpacity = instanceOpacity;
#if defined( LC_RING ) && defined( USE_INSTANCING )
transformed.xz *= 1.0 + ringSide * uRingHalf / max( length( instanceMatrix[0].xyz ), 1e-6 );
+#endif
+#if defined( LC_RING_DASH ) && defined( USE_INSTANCING )
+ vRingPoint = position.xz;
+ vRingRadius = length( instanceMatrix[0].xyz );
#endif`
)
// Each instance's center moved by `shift` (chart `x` is the scene's `x`, chart `y` its `z`)
@@ -151,7 +180,20 @@ mvPosition = modelViewMatrix * mvPosition;
gl_Position = projectionMatrix * mvPosition;`
);
shader.fragmentShader = shader.fragmentShader
- .replace('#include ', '#include \nvarying float vInstanceOpacity;')
+ .replace(
+ '#include ',
+ '#include \nvarying float vInstanceOpacity;\n#ifdef LC_RING_DASH\nuniform vec2 uRingDash;\nvarying vec2 vRingPoint;\nvarying float vRingRadius;\n#endif'
+ )
+ // A dashed ring's gaps: how far round the ring each pixel is, from its rightmost point
+ // (chart `y`, down the plot, is the scene's `z`), against the dash and gap repeating
+ .replace(
+ 'void main() {',
+ `void main() {
+#ifdef LC_RING_DASH
+ float lcAround = mod( atan( vRingPoint.y, vRingPoint.x ), 6.28318530718 ) * vRingRadius;
+ if ( mod( lcAround, uRingDash.x + uRingDash.y ) > uRingDash.x ) discard;
+#endif`
+ )
.replace(
'#include ',
'#include \ngl_FragColor.a *= vInstanceOpacity;'
@@ -159,7 +201,7 @@ gl_Position = projectionMatrix * mvPosition;`
};
// Keep the patched program apart from plain Lambert materials' in three's cache
material.customProgramCacheKey = () =>
- `lc-instance-opacity-${lit ? 'lit' : 'unlit'}${ring ? '-ring' : ''}`;
+ `lc-instance-opacity-${lit ? 'lit' : 'unlit'}${ring ? '-ring' : ''}${material.defines?.LC_RING_DASH != null ? '-dash' : ''}`;
return material;
}
@@ -174,14 +216,18 @@ export function createInstances({
opacity,
emphasize,
tooltip,
+ events,
glow,
additive,
shift,
behind,
ring,
+ dash,
}: InstancesOptions) {
const ctx = getChartContext();
const scene = getSceneContext();
+ /** The `Group`s it's in dim it, as an SVG ``'s opacity does */
+ const inGroup = groupOpacity();
/** Its objects, stacked with other marks' in the order they're declared */
const layer = scene.layer();
const litMaterial = createMaterial(true, !!ring);
@@ -257,10 +303,13 @@ export function createInstances({
$effect(() => {
const instanced = mesh;
- if (!instanced || !tooltip?.()) return;
+ const shows = !!tooltip?.();
+ if (!instanced || (!shows && !hasEvents(events?.()))) return;
return scene.addPickable({
object: instanced,
datum: (hit) => (hit.instanceId != null ? list[hit.instanceId]?.d : undefined),
+ tooltip: () => shows,
+ events,
});
});
@@ -324,9 +373,19 @@ export function createInstances({
};
instanced.computeBoundingSphere();
- const o = opacity();
+ const o = opacity() * inGroup();
material.opacity = o;
if (ring) material.userData.ringHalf.value = ring();
+ if (dash) {
+ const pattern = ring ? dash() : null;
+ // Compiled in (or out) only as it starts or stops being dashed
+ if ((material.defines?.LC_RING_DASH != null) !== !!pattern) {
+ if (pattern) material.defines = { ...material.defines, LC_RING_DASH: '' };
+ else delete material.defines!.LC_RING_DASH;
+ material.needsUpdate = true;
+ }
+ if (pattern) material.userData.ringDash.value.set(pattern[0], pattern[1]);
+ }
// A depth offset needs no new program, so it can follow along
const back = behind?.() ?? false;
material.polygonOffset = back;
diff --git a/packages/webgl/src/lib/utils/labels.ts b/packages/webgl/src/lib/utils/labels.ts
index f998ddf46d..e2d74451c8 100644
--- a/packages/webgl/src/lib/utils/labels.ts
+++ b/packages/webgl/src/lib/utils/labels.ts
@@ -11,6 +11,8 @@ import type { ResolvedColor } from './color.js';
/** Canvas pixels per pixel of the plot, so text stays sharp up close */
const RESOLUTION = 4;
+/** Pixels of the plot each glyph is traced with in its own color, to keep its weight */
+const WEIGHT_STROKE = 0.35;
let measure: CanvasRenderingContext2D | null = null;
@@ -48,7 +50,15 @@ export function labelPlane(
/** How wrapped lines line up with each other */
align?: 'start' | 'middle' | 'end';
}
-): { mesh: Mesh; width: number; height: number } | null {
+): {
+ mesh: Mesh;
+ width: number;
+ height: number;
+ /** Pixels of the plot from its top down to its first line's baseline */
+ baseline: number;
+ /** How many lines it wrapped to */
+ lines: number;
+} | null {
if (typeof document === 'undefined' || !(fontSize > 0)) return null;
const font = `${fontWeight} ${fontSize * RESOLUTION}px ${family}`;
measure ??= document.createElement('canvas').getContext('2d');
@@ -60,7 +70,11 @@ export function labelPlane(
const width =
Math.ceil(Math.max(...lines.map((line) => measure!.measureText(line).width))) + 2 + pad * 2;
const step = fontSize * RESOLUTION * lineHeight;
- const height = Math.ceil(fontSize * RESOLUTION * 1.3 + step * (lines.length - 1)) + pad * 2;
+ // Room above the first baseline and below the last, as the font measures it
+ const metrics = measure.measureText('Hg');
+ const ascent = metrics.fontBoundingBoxAscent || fontSize * RESOLUTION * 0.95;
+ const descent = metrics.fontBoundingBoxDescent || fontSize * RESOLUTION * 0.3;
+ const height = Math.ceil(ascent + descent + step * (lines.length - 1)) + pad * 2;
const label = document.createElement('canvas');
label.width = width;
@@ -68,7 +82,8 @@ export function labelPlane(
const paint = label.getContext('2d')!;
paint.font = font;
paint.textAlign = align === 'start' ? 'left' : align === 'end' ? 'right' : 'center';
- paint.textBaseline = 'middle';
+ // On their baselines, so a label can be placed by its cap height as the core `Text` places it
+ paint.textBaseline = 'alphabetic';
// Painted in the color's linear values, read by the shader as they are (a linear texture), and
// encoded for the screen with the rest of the scene. An sRGB texture of sRGB values should do
// the same, but came out decoded twice over: the text color washed out to grey.
@@ -77,7 +92,7 @@ export function labelPlane(
? `rgb(${Math.round(value.r * 255)} ${Math.round(value.g * 255)} ${Math.round(value.b * 255)})`
: 'black';
const x = align === 'start' ? 1 + pad : align === 'end' ? width - 1 - pad : width / 2;
- const first = (fontSize * RESOLUTION * 1.3) / 2 + pad;
+ const first = ascent + pad;
if (pad) {
// The halo first, so the letters cover its inner half
paint.strokeStyle = css(stroke!.color);
@@ -86,25 +101,61 @@ export function labelPlane(
paint.lineJoin = 'round';
lines.forEach((line, i) => paint.strokeText(line, x, first + step * i));
}
- paint.fillStyle = css(color?.color);
- paint.globalAlpha = color?.opacity ?? 1;
- lines.forEach((line, i) => paint.fillText(line, x, first + step * i));
+ // Translucent letters are painted opaque on a canvas of their own, then laid over at their
+ // alpha, so where their hairline (below) covers their fill they don't come out more opaque
+ const alpha = color?.opacity ?? 1;
+ const letters = alpha < 1 ? document.createElement('canvas') : label;
+ if (letters !== label) {
+ letters.width = width;
+ letters.height = height;
+ }
+ const ink = letters === label ? paint : letters.getContext('2d')!;
+ ink.font = font;
+ ink.textAlign = paint.textAlign;
+ ink.textBaseline = paint.textBaseline;
+ ink.fillStyle = css(color?.color);
+ ink.globalAlpha = 1;
+ lines.forEach((line, i) => ink.fillText(line, x, first + step * i));
+ // Shrunk to size by the GPU and blended in linear light, glyphs come out thinner than the
+ // browser draws them: a hairline of their own color brings back their weight
+ ink.strokeStyle = ink.fillStyle;
+ ink.lineWidth = WEIGHT_STROKE * RESOLUTION;
+ ink.lineJoin = 'round';
+ lines.forEach((line, i) => ink.strokeText(line, x, first + step * i));
+ if (letters !== label) {
+ paint.globalAlpha = alpha;
+ paint.drawImage(letters, 0, 0);
+ }
const texture = new CanvasTexture(label);
texture.colorSpace = LinearSRGBColorSpace;
- // Blended by coverage at the glyphs' edges, rather than against transparent black
+ // Premultiplied as it's sampled, so a glyph's edge blends by coverage rather than with the
+ // transparent black around it; the material takes the alpha back out once sampled (below)
texture.premultiplyAlpha = true;
texture.anisotropy = 8;
- const mesh = new Mesh(
- new PlaneGeometry(width / RESOLUTION, height / RESOLUTION),
- new MeshLambertMaterial({
- map: texture,
- transparent: true,
- premultipliedAlpha: true,
- depthWrite: false,
- })
- );
- return { mesh, width: width / RESOLUTION, height: height / RESOLUTION };
+ const material = new MeshLambertMaterial({
+ map: texture,
+ transparent: true,
+ depthWrite: false,
+ });
+ // Its color back to as painted (the alpha taken out), then lit, faded by `opacity`, encoded,
+ // and blended as any other's. Left premultiplied, three.js multiplies by the alpha again, and
+ // the letters' and halo's edges come out dark: a grey ring around a white halo.
+ material.onBeforeCompile = (shader) => {
+ shader.fragmentShader = shader.fragmentShader.replace(
+ '#include ',
+ '#include \n#ifdef USE_MAP\n\tdiffuseColor.rgb /= max( sampledDiffuseColor.a, 0.0001 );\n#endif'
+ );
+ };
+ material.customProgramCacheKey = () => 'lc-label-unpremultiplied';
+ const mesh = new Mesh(new PlaneGeometry(width / RESOLUTION, height / RESOLUTION), material);
+ return {
+ mesh,
+ width: width / RESOLUTION,
+ height: height / RESOLUTION,
+ baseline: first / RESOLUTION,
+ lines: lines.length,
+ };
}
/** `text`'s words wrapped onto lines `maxWidth` wide (as measured by `context`), as SVG text wraps */
@@ -140,3 +191,63 @@ export function disposeLabel(mesh: Mesh) {
material.map?.dispose();
material.dispose();
}
+
+/** A label painted once, shared by every plane showing it */
+type SharedLabel = {
+ mesh: Mesh;
+ width: number;
+ height: number;
+ baseline: number;
+ lines: number;
+ /** How many planes show it */
+ refs: number;
+};
+
+/** Painted labels by how they're painted (see `acquireLabel`) */
+const shared = new Map();
+
+/** A label's plane, showing a painting shared with others painted the same */
+export type AcquiredLabel = Omit & { key: string };
+
+/**
+ * A plane showing the label `key` names, painting it (`paint`) only when no plane shows it already:
+ * labels that pass between marks (ex. a treemap's, its rows drawn in a new order as the view
+ * turns) keep their paintings rather than measuring and painting their text again. `key` must
+ * name everything the painting depends on. `release` it when it's no longer shown.
+ */
+export function acquireLabel(
+ key: string,
+ paint: () => Omit | null
+): AcquiredLabel | null {
+ let label = shared.get(key);
+ if (!label) {
+ const made = paint();
+ if (!made) return null;
+ label = { ...made, refs: 0 };
+ shared.set(key, label);
+ }
+ label.refs++;
+ // Its own plane (a mesh has one parent), drawing the shared geometry and painting
+ const mesh = new Mesh(label.mesh.geometry, label.mesh.material);
+ return { ...label, mesh, key };
+}
+
+/**
+ * Stop showing an acquired label's plane. Its painting is freed a frame after the last plane
+ * showing it goes, so a label passed to another mark in the same update is kept.
+ */
+export function releaseLabel(label: AcquiredLabel) {
+ const entry = shared.get(label.key);
+ if (!entry) return;
+ entry.refs--;
+ if (entry.refs > 0) return;
+ const later =
+ typeof requestAnimationFrame === 'function'
+ ? requestAnimationFrame
+ : (fn: () => void) => setTimeout(fn, 16);
+ later(() => {
+ if (entry.refs > 0 || shared.get(label.key) !== entry) return;
+ shared.delete(label.key);
+ disposeLabel(entry.mesh);
+ });
+}
diff --git a/packages/webgl/src/lib/utils/lines.ts b/packages/webgl/src/lib/utils/lines.ts
index 887f0ad7fd..e13cccd46b 100644
--- a/packages/webgl/src/lib/utils/lines.ts
+++ b/packages/webgl/src/lib/utils/lines.ts
@@ -14,12 +14,20 @@ export function createSegments() {
object.visible = false;
return {
object,
- /** Draw these segments, each a pair of points, as `[x, y, z, x, y, z, ...]` in the scene */
- set(segments: ArrayLike) {
+ /**
+ * Draw these segments, each a pair of points, as `[x, y, z, x, y, z, ...]` in the scene, in
+ * each point's own color (`[r, g, b, ...]`, linear, under their `style` color) when given
+ */
+ set(segments: ArrayLike, colors?: ArrayLike) {
object.geometry.dispose();
object.geometry = new LineSegmentsGeometry();
object.visible = segments.length >= 6;
if (object.visible) object.geometry.setPositions(segments as number[]);
+ if (object.visible && colors) object.geometry.setColors(colors as number[]);
+ if (material.vertexColors !== !!colors) {
+ material.vertexColors = !!colors;
+ material.needsUpdate = true;
+ }
},
/** Their color (and its alpha) and width in pixels */
style(color: ResolvedColor | null, width: number) {
diff --git a/packages/webgl/src/lib/utils/marks.ts b/packages/webgl/src/lib/utils/marks.ts
index e5041deb22..e557f4287f 100644
--- a/packages/webgl/src/lib/utils/marks.ts
+++ b/packages/webgl/src/lib/utils/marks.ts
@@ -9,11 +9,15 @@ import {
type DataProp,
} from 'layerchart';
import type { ColorProp } from 'layerchart';
+import { pointRadial } from 'd3-shape';
import type { ScenePoint, Sphere } from './globe.js';
/** A chart scale's pixel position for `value`, at the middle of its band on a band scale */
export function scaled(scale: any, value: unknown): number {
+ // A scale with no domain (ex. a chart laid out in pixels by \`Dagre\`) takes values as they are,
+ // as the core \`Spline\` does
+ if (!scale.domain().length) return Number(value);
const position = Number(scale(value));
return isScaleBand(scale) ? position + scale.bandwidth() / 2 : position;
}
@@ -49,10 +53,15 @@ export function place(
* `place`, with the chart's globe, projection, or scales read once: for placing many rows, as
* reading them (reactive state) for every row adds up
*/
+/** Pixels to shift a point along an axis, as the core `Points`' `offsetX` / `offsetY` */
+export type Offset = number | ((value: number, context: any) => number) | undefined;
+
export function placer(
ctx: ChartState,
sphere: Sphere | null,
- scales?: { x: any; y: any }
+ scales?: { x: any; y: any },
+ /** In place of a band's middle (as the core `Points`' `offsetX` / `offsetY`) */
+ offsets?: { x?: Offset; y?: Offset }
): (xValue: unknown, yValue: unknown, height: number) => ScenePoint {
if (sphere) return (x, y, height) => sphere.toScene(Number(x), Number(y), height);
const projection = ctx.geo.projection;
@@ -64,8 +73,23 @@ export function placer(
}
const xScale = scales?.x ?? (ctx.xScale as any);
const yScale = scales?.y ?? (ctx.yScale as any);
+ // About the center on a `radial` chart, `x` an angle and `y` a radius, as the core `Points`
+ if (ctx.radial) {
+ return (x, y, height) => {
+ const [px, py] = pointRadial(Number(xScale(x)), Number(yScale(y)));
+ return [px, height, py];
+ };
+ }
const xBand = isScaleBand(xScale) ? xScale.bandwidth() / 2 : 0;
const yBand = isScaleBand(yScale) ? yScale.bandwidth() / 2 : 0;
+ const shift = (offset: Offset, band: number, at: number) =>
+ offset == null ? band : typeof offset === 'function' ? offset(at, ctx) : offset;
+ if (offsets?.x != null || offsets?.y != null) {
+ return (x, y, height) => {
+ const [px, py] = [Number(xScale(x)), Number(yScale(y))];
+ return [px + shift(offsets.x, xBand, px), height, py + shift(offsets.y, yBand, py)];
+ };
+ }
return (x, y, height) => [Number(xScale(x)) + xBand, height, Number(yScale(y)) + yBand];
}
@@ -149,9 +173,15 @@ export function placeOf(
* The rows a mark draws: its `data`, else the chart's when its props read rows (as the core
* primitives do), else one, for a mark placed by numbers alone
*/
-export function markRows(ctx: ChartState, data: any[] | undefined, ...props: unknown[]) {
+export function markRows(
+ rows: ChartState | ((own?: any) => any[]),
+ data: any[] | undefined,
+ ...props: unknown[]
+) {
if (data) return data;
- return props.some(isDataProp) ? ((ctx.data ?? []) as any[]) : [undefined];
+ if (!props.some(isDataProp)) return [undefined];
+ // A mark's `getMarkData` (its facet panel's rows), else the chart's
+ return typeof rows === 'function' ? rows() : ((rows.data ?? []) as any[]);
}
/**
@@ -188,11 +218,15 @@ export function rowColor(
value: ColorProp | undefined,
d: any,
fallback: string,
- classed?: string | null
+ classed?: string | null,
+ /** Whether the class sets `classed` itself, winning over `value` as CSS wins in core's layers */
+ classSet?: boolean
): string {
+ if (classSet && classed) return classed;
if (value != null) return resolveColorProp(value, d, ctx.cScale) ?? fallback;
if (classed) return classed;
- if (ctx.config.c != null && ctx.cScale) return String(ctx.cGet(d) ?? fallback);
+ // A row's color through the chart's `c` (not for a mark drawn without one, ex. a band)
+ if (d !== undefined && ctx.config.c != null && ctx.cScale) return String(ctx.cGet(d) ?? fallback);
return fallback;
}
diff --git a/packages/webgl/src/lib/utils/merged.svelte.ts b/packages/webgl/src/lib/utils/merged.svelte.ts
index f60e73ab74..c43d098ab7 100644
--- a/packages/webgl/src/lib/utils/merged.svelte.ts
+++ b/packages/webgl/src/lib/utils/merged.svelte.ts
@@ -4,6 +4,7 @@ import {
Color,
DoubleSide,
Float32BufferAttribute,
+ LessDepth,
Mesh,
MeshLambertMaterial,
} from 'three';
@@ -12,7 +13,22 @@ import { LineSegmentsGeometry } from 'three/addons/lines/LineSegmentsGeometry.js
import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
import { getChartContext } from 'layerchart';
-import { getSceneContext } from '../contexts/scene.svelte.js';
+import {
+ getSceneContext,
+ groupOpacity,
+ hasEvents,
+ type MarkEvents,
+} from '../contexts/scene.svelte.js';
+import {
+ boxOf,
+ createPatternFills,
+ gradientShader,
+ paintOf,
+ setLineAlphas,
+ shadeSegments,
+ shadeTriangles,
+ useLineAlphas,
+} from './paint.svelte.js';
/** One shape of a mark drawn as a single merged mesh: its geometry, outlines, and colors */
export type MergedItem = {
@@ -31,10 +47,24 @@ type MergedOptions = {
items: () => MergedItem[];
/** Whether hovering shows the tooltip (only marks that ask are picked) */
tooltip?: () => boolean;
+ /** Pointer handlers, called with the row under the pointer (as the core marks' `onclick`, ...) */
+ events?: () => MarkEvents | undefined;
opacity: () => number;
+ /** Multiplies the outlines' alpha (the fills' is `opacity`) */
+ lineOpacity?: () => number;
strokeWidth: () => number;
/** Lose to other shapes in the same place (ex. an arc's track, beneath the arc) */
behind?: boolean;
+ /**
+ * Dash the outlines, as the core marks' `dashArray` (a dash length, `[dash, gap]`, or an SVG
+ * `stroke-dasharray` string), in pixels
+ */
+ dash?: () => number | number[] | string | undefined;
+ /**
+ * Fill each pixel once, however many of its shapes overlap there, as SVG fills one path (ex. a
+ * trail's overlapping pieces, translucent): for a mark whose shapes are one path's
+ */
+ once?: boolean;
};
const highlight = new Color(0xffffff);
@@ -49,9 +79,21 @@ function append(target: number[], source: ArrayLike