diff --git a/.changeset/canvas-gradient-fill.md b/.changeset/canvas-gradient-fill.md new file mode 100644 index 0000000000..8c11dc9d2c --- /dev/null +++ b/.changeset/canvas-gradient-fill.md @@ -0,0 +1,5 @@ +--- +'layerchart': patch +--- + +fix: Marks in a `Canvas` layer fill and stroke with a `LinearGradient` or `Pattern` again (ex. an `Area`'s gradient fill) diff --git a/.changeset/layerchart-base.md b/.changeset/layerchart-base.md new file mode 100644 index 0000000000..575c7890c3 --- /dev/null +++ b/.changeset/layerchart-base.md @@ -0,0 +1,7 @@ +--- +'layerchart': minor +--- + +feat: `layerchart/base` exports the layer-agnostic bases of the marks and charts (ex. `PieBase`) and their state, for drawing LayerChart's components in a layer of your own +feat: `settings.layer` accepts `webgl`, drawn by `@layerchart/webgl`'s `Layer` +fix: Marks draw nothing outside an `Svg`, `Canvas`, or `Html` layer rather than throw, and `GeoPoint` draws in an `Html` layer diff --git a/.changeset/webgl-core-parity.md b/.changeset/webgl-core-parity.md new file mode 100644 index 0000000000..97ea912eb6 --- /dev/null +++ b/.changeset/webgl-core-parity.md @@ -0,0 +1,57 @@ +--- +'@layerchart/webgl': minor +--- + +feat: Layer-agnostic marks and `Layer` (`type="webgl"`), drawing core's versions in `Svg`, `Canvas`, and `Html` layers so one chart can switch between all four; import WebGL-only marks from `@layerchart/webgl/webgl` +feat: `Bar`, `Circle`, `Graticule`, `Group`, `Line`, and `Path`, and LayerChart's compound marks built from them (`Pie`, `Labels`, `Calendar`, `Month`, `Cell`, `BoxPlot`, `Frame`, `Hull`, `GeoPoint`, `AnnotationPoint`, `AnnotationLine`, `Violin`, `Trail`, `Density`, `Ribbon`) +feat: `BarChart`, `LineChart`, `AreaChart`, `ScatterChart`, `PieChart`, and `ArcChart`, with their axes, grid, highlight, and annotations, drawn in whichever layer they're in +feat: `AnnotationRange`, `ArcLabel`, `Brush`, `Ellipse`, `FacetAxis`, `GeoBin`, `GeoCircle`, `GeoEdgeFade`, `GeoSpline`, `Image`, `Voronoi`, and `Waffle` +feat: Re-export LayerChart's layouts, contexts, and legends (`ChartGroup`, `Dodge`, `Point`, `Bounds`, `ForceSimulation`, `Chord`, `Sankey`, `Dagre`, `Treemap`, `Partition`, `Tree`, `Pack`, `GeoProjection`, `GeoVisible`, `CircleLegend`, `GeoLegend`) +feat: `LinearGradient` and `Pattern` paint WebGL marks' fills and strokes, blended as SVG blends them +feat: `ClipPath`, `RectClipPath`, `CircleClipPath`, `GeoClipPath`, and `ChartClipPath` clip marks in a WebGL scene (to any path, a `clip` snippet's shapes, or their inverse) +feat: Faceted charts (`fx` / `fy`), each panel's marks drawing its own rows, axes on the grid's outer edge (`facetAll` for every panel) +feat: Marks take core's `motion`, `key`, and `initial*` props, easing in as core's do +feat: Lines and paths take core's `draw`, `marker*`, `startContent` / `endContent`, and `dashArray` +feat: Marks take core's `fillOpacity`, `strokeOpacity`, `seriesKey`, pointer handlers, and the `--fill-color` / `--stroke-color` their classes or `style` set +feat(Area): Stack as core's, and take `line`, `stroke`, and `pathData` +feat(Axis): `top` / `right` / `angle` / `radius` placements, `grid`, rule markers, `tickOcclusion`, `tickMultiline`, `labelPlacement`, `label` / `tickLabel` snippets, tick label `rotate` / anchors / `dx` / `dy`, and `padding="auto"` +feat(Bars): Radial bars, and flat 2D bars without a `z`, with core's `insets`, `radius` / `rounded`, `stackPadding`, `x1` / `y1` sub-bands, fixed `width` / `height`, and `children` +feat(Bin): `r`, `grid`, `class`, and `children` +feat(Arc): Track `fillOpacity` and `strokeOpacity` +feat(Contour): Flat filled bands as core's, raised bands as terraces or colored outlines, and `blur`, `smooth`, and a `z` function +feat(GeoPath): `curve`, `geoTransform`, and `children` +feat(Grid): Radial spokes and circles (`radialY`), per-axis line props, `bandAlign`, and `classes` +feat(Highlight): `area`, `bar`, and point, area, and bar click handlers +feat(Link): Core's paths (`type`, `curve`, `orientation`, `sweep`, `radius`, `bend`, `sankey`, `radial`), one link as `data`, and `pathData` +feat(Points): `offsetX` / `offsetY`, `children`, `viewport`, and a point per value of a multi-value `x` / `y` +feat(Raster): `blur` and `imageRendering="crisp-edges"` +feat(GeoRaster): `resolution` +feat(GeoTile): `group` and `children` +feat(Rect): `insets`, `rx` / `corners`, and `shade` +feat(Spline): `fill`, `pathData`, and `class` / `opacity` functions styling each run of rows (ex. dashed across missing data) +feat(Text): Font from its `class`, `segments`, `path` / `startOffset` / `dominantBaseline`, and `capHeight` +feat: `Spline`, `Area`, `Points`, `Axis`, and `Grid` draw `radial` charts +fix(GeoPath): Default to no fill and a `var(--color-surface-content)` outline, as core's +fix(Grid): Draw only the lines turned on (ex. ``), as core's +fix(Text): Default `textAnchor` to `start`, as core's +fix: A class's own fill or stroke (including `fill-none` / `stroke-none`) wins over a mark's `fill` / `stroke` prop, as CSS does in core's layers +fix: `opacity` dims a mark's outlines and lines +fix: `Bars`, `Polygon`, and `Rect` default to `var(--color-surface-content)`, as core's +fix(Axis): Ticks, tick labels, and titles placed, sized, and counted as core's +fix(Highlight): Point each series at the hovered row, as core's (ex. a stack's bands) +fix(Bars): Take `opacity` as a function of the row, as core's +fix(Axis): Format an expanded stack's values as percentages, as core's +fix: `Spline` and `Points` take their series' `props`, as core's +fix: `Area` and `Spline` fade the other `c` categories while the legend highlights one, as core's +fix(Bin): Keep its cells as an isometric view turns +fix(Spline): Follow a stack's top, break at a map's edge, and default to 1px +fix(Area): Fill both sides of the baseline where its line crosses it +fix(Link): Draw a wide link as an even ribbon rather than overlapping round-capped segments +fix(Points): Lie flat on an isometric chart unless `viewport`, as core's +fix: Data-mode `Circle`, `Rect`, `Text`, `Line`, and `Polygon` add their data to the chart's domains, as core's +fix(Spline): Call a `stroke` function with the row's index and the line's rows, as core's +fix(Arc): Outline rounded corners the short way round (ex. a `fill-none` track) +fix: A scale with no domain (ex. `Dagre`'s pixel layout) places values as they are, as core's `Spline` +fix(Text): Clean label halos, and take its class's fill and text color +fix: Draw every mark of a flat chart with very many (ex. a `Calendar`'s day cells) +perf(Text): Reuse label paintings as labels move between marks or change size slightly diff --git a/docs/package.json b/docs/package.json index d33a2e1157..c476add87d 100644 --- a/docs/package.json +++ b/docs/package.json @@ -20,7 +20,7 @@ "test:visual:update": "node scripts/visual-snapshot.mjs capture snapshots/baseline.json --repeat 3", "generate:api": "layerstack-docs generate-api ../packages/layerchart/src/lib/components generated/api && layerstack-docs generate-api ../packages/webgl/src/lib/components generated/api/webgl", "generate:screenshots": "layerstack-docs generate-screenshots src/examples/components static/screenshots", - "generate:catalog": "layerstack-docs generate-catalog ../packages/layerchart/src/lib/components src/examples/components src/examples/catalog && layerstack-docs generate-catalog ../packages/webgl/src/lib/components src/examples/components/webgl src/examples/catalog/webgl", + "generate:catalog": "layerstack-docs generate-catalog ../packages/layerchart/src/lib/components src/examples/components src/examples/catalog && layerstack-docs generate-catalog ../packages/webgl/src/lib/components src/examples/components src/examples/catalog/webgl && node scripts/prune-webgl-catalogs.mjs src/examples/catalog", "generate:stackblitz": "layerstack-docs generate-stackblitz src static/stackblitz-files.json static/remote-sources.json --source src/lib/utils/data.ts=lib/utils/data.ts --source src/lib/utils/sports.ts=lib/utils/sports.ts --remote data.remote.ts=lib/data.remote.ts --remote geo.remote.ts=lib/geo.remote.ts --remote graph.remote.ts=lib/graph.remote.ts", "generate:releases": "layerstack-docs generate-releases techniq/layerchart generated/releases", "generate:all": "pnpm generate:api && pnpm generate:screenshots && pnpm generate:catalog && pnpm generate:stackblitz && pnpm generate:releases" @@ -38,7 +38,7 @@ "@iconify-json/vscode-icons": "^1.2.53", "@jsquash/webp": "^1.5.0", "@layerchart/webgl": "workspace:*", - "@layerstack/docs": "1.0.0-next.7", + "@layerstack/docs": "1.0.0-next.10", "@layerstack/svelte-actions": "1.0.1-next.20", "@layerstack/svelte-state": "0.1.0-next.25", "@layerstack/svelte-table": "1.0.1-next.20", diff --git a/docs/scripts/prune-webgl-catalogs.mjs b/docs/scripts/prune-webgl-catalogs.mjs new file mode 100644 index 0000000000..f437d2c6cf --- /dev/null +++ b/docs/scripts/prune-webgl-catalogs.mjs @@ -0,0 +1,11 @@ +// `@layerchart/webgl`'s catalogs are generated from every example, as LayerChart's are, but used only +// for its own components (ex. `Surface`): LayerChart's list every example of theirs (ex. `Points`), +// whichever package draws it. Removes its catalogs of components LayerChart has. +import fs from 'node:fs'; +import path from 'node:path'; + +const [catalogDir = 'src/examples/catalog'] = process.argv.slice(2); +const webglDir = path.join(catalogDir, 'webgl'); +for (const file of fs.readdirSync(webglDir)) { + if (fs.existsSync(path.join(catalogDir, file))) fs.rmSync(path.join(webglDir, file)); +} diff --git a/docs/src/content/components/Arc.md b/docs/src/content/components/Arc.md index 063725ccec..241606e495 100644 --- a/docs/src/content/components/Arc.md +++ b/docs/src/content/components/Arc.md @@ -3,6 +3,9 @@ description: Primitive component which draws a curved segment on a chart to repr category: primitives layers: [svg, canvas] related: [Pie, ArcChart, PieChart] +components: + - { name: Arc } + - { name: webgl/Arc, label: Arc (WebGL) } --- ::tip @@ -24,3 +27,15 @@ The text will smartly orientate based on the direction (clockwise / counter-cloc ### Playground :example{ name="playground" } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it stands up by its z. See the [WebGL guide](/docs/guides/webgl) to get started. + +An arc with the core [Arc](/docs/components/Arc) props: from `startAngle` to `endAngle` (ex. a slice from `d3.pie()`), or to a `value` through its `domain` and `range`, over a `track`. Radii are pixels, fractions of the chart's radius, or offsets from it, as the core are, and `class` styles it as on any core mark. It's centered in the plot (where the core draws inside a centered `Layer` or `Group`); `x` / `y` move it. `z` stands it up, as on an `isometric` chart; without one it lies flat. + +:example{ name="pie" } + +The core [concentric gauges](/docs/components/Arc/concentric) example, unchanged but for `z`: + +:example{ name="concentric-3d" } diff --git a/docs/src/content/components/Area.md b/docs/src/content/components/Area.md index a51696b6c1..b24d40f3c3 100644 --- a/docs/src/content/components/Area.md +++ b/docs/src/content/components/Area.md @@ -3,6 +3,9 @@ description: Marking component which shades the space under a line on a chart to category: marks layers: [svg, canvas] related: [] +components: + - { name: Area } + - { name: webgl/Area, label: Area (WebGL) } --- ::info @@ -40,3 +43,13 @@ This replaces grouping the data yourself and rendering an `Area` per group — e On an [isometric](/docs/guides/isometric) chart, `z` gives each point a height, and an `Area` stands up as a curtain from the floor to those heights. One curtain per row of a band `y`, drawn back to front, makes a 3D ridgeline. :example{ name="oscilloscope-ridgeline-isometric" } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it lies on the floor, or rises as a curtain with a z. See the [WebGL guide](/docs/guides/webgl) to get started. + +A curtain from the floor (or `z0`) up to `z` along the rows, one per group. + +:example{ name="areas" } + +:example{ name="ridgeline-3d" } diff --git a/docs/src/content/components/Axis.md b/docs/src/content/components/Axis.md index 058e401ab2..b97b350efb 100644 --- a/docs/src/content/components/Axis.md +++ b/docs/src/content/components/Axis.md @@ -3,6 +3,9 @@ description: Commonly used component displays the scale and reference lines on a category: common layers: [svg, canvas, html] related: [Grid, Rule] +components: + - { name: Axis } + - { name: webgl/Axis, label: Axis (WebGL) } --- ## Usage @@ -328,3 +331,29 @@ Specify explicit time intervals such as every day, every 6 months, etc with comp ### Time scale (brush) with multiline ticks :example{ name="time-scale-brush-multiline" } --> + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it runs along the plot box's edges: bottom for x, left for y, and back for z. See the [WebGL guide](/docs/guides/webgl) to get started. + +Tick labels along an edge: `bottom` for `x`, `left` for `y`, and `back` for `z` (up the corner behind the plot). They keep to the edges in front as the view turns. + +Labels are drawn on the plot box, turning with it: the floor's (`bottom`, `left`) lie on it, as on an [isometric](/docs/guides/isometric#text) chart, and the height axis' (`back`) stand on the back wall beside its edge. `tickLabelProps={{ viewport: true }}` and `labelProps={{ viewport: true }}` draw them facing the viewer instead, over the scene, upright and crisp however the view turns. + +```svelte + + + + + + +``` + +:example{ component="Points" name="scatter-3d" } + +:example{ component="Spline" name="temperatures" } diff --git a/docs/src/content/components/Bars.md b/docs/src/content/components/Bars.md index ebbcf44e62..ee1d13780a 100644 --- a/docs/src/content/components/Bars.md +++ b/docs/src/content/components/Bars.md @@ -3,6 +3,9 @@ description: Marking component which applies horizontal bars to represent and vi category: marks layers: [svg, canvas, html] related: [Bar] +components: + - { name: Bars } + - { name: webgl/Bars, label: Bars (WebGL) } --- :::tip @@ -24,3 +27,39 @@ Use `width` or `height` to override the scale-derived size with a fixed pixel va On an [isometric](/docs/guides/isometric) chart with `valueAxis="z"`, bars stand up off the floor as 3D columns, stacked by the chart. :example{ component="Chart" name="isometric-stacked-columns" } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), each bar is a box standing as tall as its z. See the [WebGL guide](/docs/guides/webgl) to get started. + +A box per row, standing on its `x` × `y` band cell, as tall as its `z`. + +```svelte + + + + + +``` + +:example{ name="columns" } + +### Stacked + +With series and `valueAxis="z"`, bars stack up off the floor. + +:example{ name="stacked-columns" } + +### Heatmap and calendar + +:example{ name="heatmap" } + +:example{ name="calendar" } diff --git a/docs/src/content/components/Bin.md b/docs/src/content/components/Bin.md index e184dbdf0c..2cc13f2ac1 100644 --- a/docs/src/content/components/Bin.md +++ b/docs/src/content/components/Bin.md @@ -3,6 +3,9 @@ description: Composite mark grouping two-dimensional points into a grid of hexag category: marks layers: [svg, canvas] related: [GeoBin, Density, Contour, Cell, Points] +components: + - { name: Bin } + - { name: webgl/Bin, label: Bin (WebGL) } --- ::tip @@ -88,3 +91,25 @@ To bin on the sphere instead — for a globe, or gridded data such as population Pointer events receive the cell under the pointer. :example{ name="tooltip" } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), each cell stands as tall as its z. See the [WebGL guide](/docs/guides/webgl) to get started. + +Rows grouped into hexagons (or squares, or triangles) of the plot, or of the map as projected, as the core [Bin](/docs/components/Bin) groups them. Each cell stands up `z` tall (ex. its `count`), colored by its count unless given a `fill`. Every cell is the same shape, so thousands draw as one. + +```svelte + + + +``` + +:example{ name="hexbin" } + +### On a map + +:example{ name="walmart-3d" } + +`weight` counts each row by a value (ex. the people in a cell of gridded population), and `gap` stands the cells apart. + +:example{ name="state-population" } diff --git a/docs/src/content/components/Contour.md b/docs/src/content/components/Contour.md index 5df3806719..389f111462 100644 --- a/docs/src/content/components/Contour.md +++ b/docs/src/content/components/Contour.md @@ -3,6 +3,9 @@ description: Composite mark drawing isolines to delineate regions above and belo category: marks layers: [svg, canvas] related: [Density, Hull, Raster, GeoPath] +components: + - { name: Contour } + - { name: webgl/Contour, label: Contour (WebGL) } --- ::tip @@ -54,3 +57,11 @@ When no data is provided, the contour mark evaluates a continuous function _f_(_ Adjust thresholds and blur on a sampled function. :example{ name="sampled-interactive" showCode } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), its lines lie flat or rise to their heights. See the [WebGL guide](/docs/guides/webgl) to get started. + +Filled, it's LayerChart's own `Contour` (bands through the color scale, outlined with a `stroke`, and stacked into terraces when raised), drawn with WebGL marks. Unfilled (`fill="none"`), its lines lie at `z` pixels (ex. over a `Raster`), or each rises to its threshold's height with `z="value"`, in the bands' colors unless given a `stroke`. It takes values the same ways as [Surface](/docs/components/Surface). + +:example{ name="basic" } diff --git a/docs/src/content/components/GeoPath.md b/docs/src/content/components/GeoPath.md index 8f0c0bf5a2..66e8dc1c5d 100644 --- a/docs/src/content/components/GeoPath.md +++ b/docs/src/content/components/GeoPath.md @@ -3,6 +3,9 @@ description: Geographic component which renders shapes such as countries, states category: geo layers: [svg, canvas] related: [Graticule] +components: + - { name: GeoPath } + - { name: webgl/GeoPath, label: GeoPath (WebGL) } --- :::tip @@ -24,3 +27,31 @@ On an [isometric](/docs/guides/isometric) chart, `z` stands each shape up off th Click a continent (or World Bank region) to zoom to its countries, a country for its states or provinces, then a region or US state for its provinces or counties. Clicking where there is nothing further in zooms back out a level. Each country's shapes load when it is clicked, from Natural Earth's [admin-1 states and provinces](https://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-admin-1-states-provinces/), with [US Atlas](https://github.com/topojson/us-atlas) for US counties. :example{ name="geojson-drilldown" } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), features rise by their z, or follow a globe. See the [WebGL guide](/docs/guides/webgl) to get started. + +Features on the floor through the chart's projection, extruded `z` tall (a property key or function of the feature, through the chart's `z` scale, or pixels). Lines, and outlines with `stroke`, draw on top. A collection draws as one mark, so thousands of features stay quick. `motion` eases each feature's height and fill to new values. + +```svelte + + + d.properties.population} fill="var(--color-primary)" /> + + +``` + +:example{ name="election" } + +### Buildings, with shadows + +d3-geo reads a polygon's outside ring clockwise, and the other way round as the rest of the world, so rewind rings from other sources (ex. OpenStreetMap) before drawing them. + +:example{ component="Light" name="buildings" } + +### On a globe + +With the `globe` projection, features' lines draw over the sphere, and `{ type: 'Sphere' }` fills the globe itself (ex. beneath an image still loading). + +:example{ component="GeoRaster" name="globe-tiles" } diff --git a/docs/src/content/components/GeoRaster.md b/docs/src/content/components/GeoRaster.md index 23664d2190..db7dd85c52 100644 --- a/docs/src/content/components/GeoRaster.md +++ b/docs/src/content/components/GeoRaster.md @@ -3,6 +3,9 @@ description: Geographic component which reprojects a raster image (such as NASA category: geo layers: [canvas] related: [] +components: + - { name: GeoRaster } + - { name: webgl/GeoRaster, label: GeoRaster (WebGL) } --- :::tip @@ -16,3 +19,42 @@ Rendering is pure Canvas 2D (no WebGL). The image must be CORS-readable so its p ## Usage :example{ name="globe" showCode } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), the image can rise into terrain or wrap a globe. See the [WebGL guide](/docs/guides/webgl) to get started. + +An image (`image`: a URL, or an image, canvas, or bitmap) laid over the map through the chart's projection, as the core [GeoRaster](/docs/components/GeoRaster) reprojects one, and with the same props: it's equirectangular unless `sourceProjection` gives the projection it was drawn in, and `interpolate` / `pixelated` choose blended or crisp pixels. Unlike core's, it blends (`'bilinear'`) by default, which costs the GPU nothing. `elevation` (a function of longitude and latitude) raises it into terrain, and `tooltip` shows the longitude and latitude under the pointer. + +:example{ name="projections-3d" } + +### Terrain + +Map tiles stitched into one image (`sourceProjection` maps longitude and latitude onto its Web Mercator pixels) and draped over `elevation`, lit by a `Light`: satellite imagery over a mountain, at true scale times the exaggeration. The tiles load once for the area, so they don't sharpen as you zoom in. + +:example{ name="terrain" } + +### Globe + +The `globe` projection lays the map on a real sphere you can orbit. Fit it as an orthographic map (the sphere is the size and place the disk would be, standing on the floor) and the same marks draw on it: `GeoRaster` wraps it in an image, `GeoPath` follows its curve, `Points` and `Bars` stand out from it, `Spline` runs along great circles, and `Surface` / `Raster` cover it. + +```svelte + + + + + + + + +``` + +:example{ name="globe-3d" } + +:example{ name="planets-3d" } + +:example{ name="globe-textures" } + +:example{ name="globe-tiles" } diff --git a/docs/src/content/components/GeoTile.md b/docs/src/content/components/GeoTile.md index 1f7e01d3f9..8dd08d1acd 100644 --- a/docs/src/content/components/GeoTile.md +++ b/docs/src/content/components/GeoTile.md @@ -3,6 +3,9 @@ description: Geographic component which renders map tiles in a grid supporting e category: geo layers: [svg, canvas] related: [] +components: + - { name: GeoTile } + - { name: webgl/GeoTile, label: GeoTile (WebGL) } --- :::tip @@ -12,3 +15,34 @@ See the [Geo guide](/docs/guides/geo) for a full walkthrough of projections, fit ## Usage :example{ name="basic" } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), tiles can rise into terrain from elevation tiles. See the [WebGL guide](/docs/guides/webgl) to get started. + +Map tiles from an XYZ tile service, with the core [GeoTile](/docs/components/GeoTile) props (`url`, `zoomDelta`, `tileSize`, `disableCache`, `debug`), picked for the chart's Web Mercator projection as it picks them. A `projection` transform zooms the map, and sharper tiles load as it does. + +:example{ name="zoomable-webgl" } + +### Terrain + +`elevation` raises the tiles from a second tile service of elevation tiles (ex. AWS's open terrain tiles, or Mapterhorn): their `url`, `encoding` (`'terrarium'`, or Terrain-RGB as `'mapbox'`), and `maxZoom`, their meters through the chart's `z` scale. `maxZoom` and the elevation's `maxZoom` say how deep each service goes: deeper tiles show part of their ancestor, enlarged. + +```svelte + `https://tiles.versatiles.org/tiles/satellite-raster/${z}/${x}/${y}`} + maxZoom={12} + elevation={{ + url: (x, y, z) => `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`, + maxZoom: 15 + }} +/> +``` + +:example{ name="terrain" } + +### Detail that follows the camera + +In a 3D view, tiles are picked from the camera rather than the projection: each tile is as deep as it needs to be to look about `tileSize` pixels across on screen, so tiles are sharp up close and coarse in the distance, and sharpen as the camera moves in. A new tile draws at once from an ancestor already loaded (blurrier, as the tile it's zoomed in from), then fades to its own as it arrives; tiles leaving the view stay until those taking their place are drawn, the sharpest showing wherever they overlap (so zooming out keeps what was sharp, and fills around it). Beneath them all, a few coarse tiles (the map's own, three zooms up) show through wherever a tile has yet to arrive. So moving never opens a hole, as the core seamless layering of `GeoTile`s does, with one `GeoTile`. The same works on the `globe`, where tiles on its far side are left out. + +:example{ name="globe" } diff --git a/docs/src/content/components/Grid.md b/docs/src/content/components/Grid.md index a504f9e3cf..6b3f01e7b6 100644 --- a/docs/src/content/components/Grid.md +++ b/docs/src/content/components/Grid.md @@ -3,6 +3,9 @@ description: Commonly used component which draws horizontal and vertical lines r category: common layers: [svg, canvas, html] related: [Axis, Rule] +components: + - { name: Grid } + - { name: webgl/Grid, label: Grid (WebGL) } --- ## Usage @@ -68,3 +71,22 @@ Respects padding ### Remove default tick count :example{ name="tick-count-null" } --> + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it lines the plot box's floor and back walls. See the [WebGL guide](/docs/guides/webgl) to get started. + +The floor and the two walls behind the plot, with lines at the scales' ticks. The walls move to the far sides as the view turns. + +```svelte + + + + +``` + +:example{ component="Points" name="scatter-3d" } + +Set `x`, `y`, or `z` to `false` to leave out a direction's lines (ex. ``). + +:example{ component="Bin" name="hexbin" } diff --git a/docs/src/content/components/Highlight.md b/docs/src/content/components/Highlight.md index 12e01b2631..e324def746 100644 --- a/docs/src/content/components/Highlight.md +++ b/docs/src/content/components/Highlight.md @@ -3,6 +3,9 @@ description: Interaction component manages and displays tooltips allowing dynami category: interactions layers: [svg, canvas, html] related: [Tooltip, TooltipContext] +components: + - { name: Highlight } + - { name: webgl/Highlight, label: Highlight (WebGL) } --- ## Usage @@ -86,3 +89,21 @@ By default, Highlight uses `TooltipContext` data. Pass explicit `data` to highli ```svelte ``` + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it marks the hovered row with a point facing the viewer, traced on the floor and back walls. See the [WebGL guide](/docs/guides/webgl) to get started. + +The tooltip's row (or `data`), marked as the core [Highlight](/docs/components/Highlight) marks it on an `isometric` chart, with the same props: `points` rings it with a circle facing the viewer, `lines` trace its position across the floor and, with a `z`, across and up each back wall (`axis` picks which), and `shadows` put a spot beneath it on the floor and level with it on each wall. Pass props to style each, ex. `points={{ r: 8, fill: 'none' }}`. + +```svelte + + + + + +``` + +On a flat `WebGL` chart, core's own `Highlight` in an `Svg` layer over it works as well (ex. [scatter](/docs/components/Points/scatter)). + +:example{ component="Points" name="scatter-3d" } diff --git a/docs/src/content/components/webgl/Light.md b/docs/src/content/components/Light.md similarity index 88% rename from docs/src/content/components/webgl/Light.md rename to docs/src/content/components/Light.md index ce255ce314..48307fb355 100644 --- a/docs/src/content/components/webgl/Light.md +++ b/docs/src/content/components/Light.md @@ -1,7 +1,8 @@ --- description: 'Light for a WebGL layer: directional (like the sun), a point (like a star), or ambient, with optional shadows.' -category: WebGL +category: other related: [guides/webgl] +layers: [webgl] components: - { name: webgl/Light, label: Light } --- @@ -32,8 +33,8 @@ A `point` light shines every way from a place in the plot (`x`, `y`, and `z`, in ``` -:example{ component="webgl/Points" name="solar-system" } +:example{ component="Points" name="solar-system" } ## Shadows on a map -:example{ component="webgl/Bin" name="state-population" } +:example{ component="Bin" name="state-population" } diff --git a/docs/src/content/components/Link.md b/docs/src/content/components/Link.md index 4243ce6184..f83df98fdb 100644 --- a/docs/src/content/components/Link.md +++ b/docs/src/content/components/Link.md @@ -3,6 +3,9 @@ description: Marking component which draws a line or curve between two points to category: primitives layers: [svg, canvas] related: [Spline, Tree, Sankey, ForceSimulation, AnnotationPoint] +components: + - { name: Link } + - { name: webgl/Link, label: Link (WebGL) } --- ### Playground @@ -16,3 +19,17 @@ related: [Spline, Tree, Sankey, ForceSimulation, AnnotationPoint] ### Curves :example{ name="curves" } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), links can rise or arch between their ends. See the [WebGL guide](/docs/guides/webgl) to get started. + +A line per row, straight or arched (`arc`), placed as the core [`Link`](/docs/components/Link) places it. `x1` / `y1` and `x2` / `y2` are its ends, as data properties or functions of the row through the chart's scales (longitude and latitude on a map), or numbers in pixels; the end defaults to the start. `z1` / `z2` raise them, through the chart's `z` scale or in pixels: ex. a pin's stem from the floor up to its head. + +```svelte + +``` + +Without `x1` / `y1`, each row is a link from its `source` node to its `target`, at their `x` / `y` in pixels: ex. a hierarchy's `links()`. + +:example{ name="pin-map" } diff --git a/docs/src/content/components/Points.md b/docs/src/content/components/Points.md index 485257ba1f..3e67293a84 100644 --- a/docs/src/content/components/Points.md +++ b/docs/src/content/components/Points.md @@ -3,6 +3,9 @@ description: Marking component which plots individual data points on a graph to category: marks layers: [svg, canvas, html] related: [ScatterChart] +components: + - { name: Points } + - { name: webgl/Points, label: Points (WebGL) } --- ::tip @@ -38,3 +41,39 @@ For example, to color based on thresholds (e.g. red: <50, yellow: 50-90, green: You can also color points based the comparison of two values in your data. :example{ name="color-via-ordinal-scale" showCode } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), each point is a sphere (a disc when flat), and can glow or wear an image. See the [WebGL guide](/docs/guides/webgl) to get started. + +A sphere per row, at its `x`, `y`, and `z`. `r` sets the radius in pixels, else the chart's `r` scale. + +```svelte + + + + + +``` + +:example{ name="scatter-3d" } + +### Glow and images + +`glow` draws each sphere in its own color whatever the lights (ex. a star), and `image` wraps each in an equirectangular image (ex. a planet), turned by `rotate` and leaning by `tilt`. + +:example{ name="solar-system" } + +Tens of thousands of glowing points, placed along spiral arms and colored from the middle out, turning slowly (drag to look from another angle). + +:example{ name="galaxy" } + +### Flat + +Without a view, points are discs, for many thousands of them. + +:example{ name="scatter" } + +The grid, axes, and highlight can be core's own `Svg` layers instead, with only the points in WebGL: + +:example{ name="scatter-with-svg" } diff --git a/docs/src/content/components/Polygon.md b/docs/src/content/components/Polygon.md index e98ec9a334..f9cb040d76 100644 --- a/docs/src/content/components/Polygon.md +++ b/docs/src/content/components/Polygon.md @@ -3,6 +3,9 @@ description: Primitive component which renders a multi-sided shape on a chart to category: primitives layers: [svg, canvas] related: [] +components: + - { name: Polygon } + - { name: webgl/Polygon, label: Polygon (WebGL) } --- ## Usage @@ -34,3 +37,11 @@ Use a threshold scale to color items based on value ranges. ## Isometric On an [isometric](/docs/guides/isometric) chart, `z` stands a polygon up into a prism. See the [isometric tree](/docs/components/Tree#isometric). + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it stands up by its z. See the [WebGL guide](/docs/guides/webgl) to get started. + +A polygon per row, with the core [Polygon](/docs/components/Polygon) props: a regular polygon (or star, with `inset`) of `points` corners about `cx` / `cy` with radius `r`, or explicit `points` in pixels, `rotate`d, stretched, skewed, and rounded by `cornerRadius`. `z` stands it up, as on an `isometric` chart; without one it lies flat. + +:example{ name="tree" } diff --git a/docs/src/content/components/Raster.md b/docs/src/content/components/Raster.md index cc2afa9858..4e2f651751 100644 --- a/docs/src/content/components/Raster.md +++ b/docs/src/content/components/Raster.md @@ -3,6 +3,9 @@ description: Composite mark rendering a pixel-based heatmap where each pixel is category: marks layers: [svg, canvas, html] related: [Contour, Density] +components: + - { name: Raster } + - { name: webgl/Raster, label: Raster (WebGL) } --- ::tip @@ -46,3 +49,11 @@ The classic fractal rendered pixel-by-pixel via a `value` function. Uses `pixelS Explore various mathematical functions mapped to color scales, demonstrating how different equations produce distinct visual patterns. :example{ name="math-functions" showCode } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it lies on the floor as an image. See the [WebGL guide](/docs/guides/webgl) to get started. + +The values as an image on the floor (or `z` pixels above it), sampled as finely as the image allows rather than at a surface's vertices. It takes values the same ways as [Surface](/docs/components/Surface), and `imageRendering="pixelated"` shows each cell with hard edges. + +:example{ name="basic" } diff --git a/docs/src/content/components/Rect.md b/docs/src/content/components/Rect.md index 781ad89b6c..6c6a0bd7fa 100644 --- a/docs/src/content/components/Rect.md +++ b/docs/src/content/components/Rect.md @@ -3,6 +3,9 @@ description: Primitive component which draws a rectangle to highlight areas, ran category: primitives layers: [svg, canvas, html] related: [Bars, Highlight, RectClipPath] +components: + - { name: Rect } + - { name: webgl/Rect, label: Rect (WebGL) } --- ## Usage @@ -36,3 +39,15 @@ Use `fill` with a data property name to color each rect through the chart's colo Use a threshold scale to color rects based on value ranges. :example{ name="color-via-threshold-scale" showCode } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), it's a box standing as tall as its z. See the [WebGL guide](/docs/guides/webgl) to get started. + +A box per row, `z` tall, placed as the core [`Rect`](/docs/components/Rect) places it: by its sides `x0` / `x1` and `y0` / `y1`, or by `x` / `y` and a `width` / `height` in pixels. Sides and positions are data properties or functions of the row through the chart's scales, or numbers in pixels. A `z` function can return `[start, end]` to float a box between two values (ex. a treemap's tiers). + +```svelte + [d.depth, d.depth + 1]} /> +``` + +:example{ name="treemap" } diff --git a/docs/src/content/components/Rule.md b/docs/src/content/components/Rule.md index 894ec978c4..c99c046d33 100644 --- a/docs/src/content/components/Rule.md +++ b/docs/src/content/components/Rule.md @@ -3,6 +3,9 @@ description: Commonly used component acting as a visual guideline on a chart tha category: common layers: [svg, canvas, html] related: [Axis, Line, AnnotationLine] +components: + - { name: Rule } + - { name: webgl/Rule, label: Rule (WebGL) } --- ## Usage @@ -78,3 +81,11 @@ using `` and either: ### Data driven (y range) :example{ name="data-y-range" } --> + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), rules lie on the floor. See the [WebGL guide](/docs/guides/webgl) to get started. + +Reference lines with the core [Rule](/docs/components/Rule) props, on the floor (or `z` pixels above it): `x` / `y` at a value, at the plot's edges (`true`, `'$left'`, `'$top'`, ...), or as an accessor for a line per row, from zero (or the band) to its value. `class` styles them as on any core mark. + +:example{ name="lollipop-webgl" } diff --git a/docs/src/content/components/Spline.md b/docs/src/content/components/Spline.md index 32eb3e7f82..b412e0b8e1 100644 --- a/docs/src/content/components/Spline.md +++ b/docs/src/content/components/Spline.md @@ -3,6 +3,9 @@ description: Marking component which applies data points connected by smooth, cu category: marks layers: [svg, canvas] related: [Path, Trail, LineChart] +components: + - { name: Spline } + - { name: webgl/Spline, label: Spline (WebGL) } --- ::tip @@ -147,3 +150,23 @@ A line crosses every dimension, so the dimensions can't be panels — but `fy` g :example{ name="end-slot-with-draw-with-value" } - Because the draw transition and tweened store use different timers, there is no guarantee they will start at the same time --> + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), lines run through 3D, colored per point. See the [WebGL guide](/docs/guides/webgl) to get started. + +A line through the rows, one per `g` (or `stroke` key, or `c`) value, at each row's `x`, `y`, and `z`. `stroke` colors it per point, so a line can change color along its length. + +```svelte + + + + + +``` + +:example{ name="series" } + +:example{ name="line3d" } + +:example{ name="temperatures" } diff --git a/docs/src/content/components/webgl/Surface.md b/docs/src/content/components/Surface.md similarity index 98% rename from docs/src/content/components/webgl/Surface.md rename to docs/src/content/components/Surface.md index 13630be3fb..c16a7f98ef 100644 --- a/docs/src/content/components/webgl/Surface.md +++ b/docs/src/content/components/Surface.md @@ -1,7 +1,8 @@ --- description: 'Mark raising a grid of values into a lit surface in a WebGL chart, with optional wireframe and contour lines.' -category: WebGL surfaces +category: marks related: [Raster, Contour, guides/webgl] +layers: [webgl] components: - { name: webgl/Surface, label: Surface } --- diff --git a/docs/src/content/components/Text.md b/docs/src/content/components/Text.md index 1fdf6f70d8..b8306ab40a 100644 --- a/docs/src/content/components/Text.md +++ b/docs/src/content/components/Text.md @@ -3,6 +3,9 @@ description: Primitive component which adds custom text for labeling, annotation category: primitives layers: [svg, canvas, html] related: [] +components: + - { name: Text } + - { name: webgl/Text, label: Text (WebGL) } --- ## Usage @@ -76,3 +79,21 @@ The text will smartly orientate based on the direction (clockwise / counter-cloc :::note Only supported in `Svg` layers. ::: + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), text lies on the surface beneath it, or faces the viewer. See the [WebGL guide](/docs/guides/webgl) to get started. + +A label per row, placed as the core [`Text`](/docs/components/Text) places it: `x`, `y`, and `z` are data properties or functions of the row, through the chart's scales (longitude and latitude on a map), or numbers in pixels. `value` is a property, a function, or the text itself. + +By default a label lies on the surface at its height (ex. the tops of boxes), turning and tipping with the view, in `fontSize` and `fill`. With `viewport` it faces the viewer instead, drawn over the scene upright and crisp however the view turns, styled with `class`. + +```svelte + +``` + +For a layout already in pixels (ex. a tree), place a label per node by numbers. + +:example{ component="Polygon" name="tree" } + +:example{ component="Rect" name="treemap" } diff --git a/docs/src/content/components/Vector.md b/docs/src/content/components/Vector.md index fc2db9dcbf..6999f70dfb 100644 --- a/docs/src/content/components/Vector.md +++ b/docs/src/content/components/Vector.md @@ -3,6 +3,9 @@ description: Primitive component which draws directional arrows or spikes at dat category: primitives layers: [svg, canvas] related: [Line, Circle, GeoPath] +components: + - { name: Vector } + - { name: webgl/Vector, label: Vector (WebGL) } --- ## Usage @@ -42,3 +45,17 @@ A geographic wind map showing wind speed and direction over Western Europe using A geographic wind map showing 2020 US presidential election results by county. Blue spikes lean left for Democratic wins, red spikes lean right for Republican wins, with length proportional to vote margin. :example{ name="election-wind-map" showCode } + +## WebGL + +In a [`WebGL`](/docs/components/WebGL) layer, from [`@layerchart/webgl`](/docs/guides/webgl), they lie on the floor. See the [WebGL guide](/docs/guides/webgl) to get started. + +Arrows (`shape="arrow"`), filled arrows (`'arrow-filled'`), or spikes (`'spike'`) with the core [Vector](/docs/components/Vector) props: placed at `x` / `y`, `length` long (through the chart's `r` scale), and turned `rotate` degrees clockwise from up the plot. + +In a 3D view, each is a solid arrow (or cone) that can point any way: `z` places it in the box (through the chart's `z` scale), and `tilt` points it up out of the floor (`90` straight up). Flat, it lies on the floor as core draws it. + +```svelte + +``` + +:example{ name="field" } diff --git a/docs/src/content/components/webgl/WebGL.md b/docs/src/content/components/WebGL.md similarity index 93% rename from docs/src/content/components/webgl/WebGL.md rename to docs/src/content/components/WebGL.md index a548ba12ff..a1e21130ec 100644 --- a/docs/src/content/components/webgl/WebGL.md +++ b/docs/src/content/components/WebGL.md @@ -2,6 +2,7 @@ description: "Layer drawing its marks with WebGL (three.js), through the chart's perspective or orthographic view in 3D, or flat for many marks in 2D." category: layers related: [Layer, Canvas, guides/webgl, guides/isometric] +layers: [webgl] components: - { name: webgl/WebGL, label: WebGL } --- @@ -36,11 +37,11 @@ A `WebGL` layer draws the `@layerchart/webgl` marks inside it. The chart's `view Without a `view`, the layer is seen from directly above and drawn unshaded, each chart pixel where an `Svg` or `Canvas` layer would draw it, for charts with more marks than those keep up with. -:example{ component="webgl/Points" name="scatter" } +:example{ component="Points" name="scatter" } Only the marks need to be drawn by it. Here `Svg` layers draw the grid, axes, and highlight as on any chart, with the chart's tooltip finding the nearest point, and the `WebGL` layer the 100,000 points between them. -:example{ component="webgl/Points" name="scatter-with-svg" } +:example{ component="Points" name="scatter-with-svg" } ## Limits diff --git a/docs/src/content/components/webgl/Arc.md b/docs/src/content/components/webgl/Arc.md deleted file mode 100644 index 59b78f6866..0000000000 --- a/docs/src/content/components/webgl/Arc.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -description: 'Primitive component which draws a curved segment on a chart to represent portions of a whole or highlight specific data ranges. In a WebGL layer, it stands up by its z.' -category: WebGL marks -related: [Arc, guides/webgl] -components: - - { name: webgl/Arc, label: Arc } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -An arc with the core [Arc](/docs/components/Arc) props: from `startAngle` to `endAngle` (ex. a slice from `d3.pie()`), or to a `value` through its `domain` and `range`, over a `track`. Radii are pixels, fractions of the chart's radius, or offsets from it, as the core are, and `class` styles it as on any core mark. It's centered in the plot (where the core draws inside a centered `Layer` or `Group`); `x` / `y` move it. `z` stands it up, as on an `isometric` chart; without one it lies flat. - -:example{ name="pie" } - -The core [concentric gauges](/docs/components/Arc/concentric) example, unchanged but for `z`: - -:example{ name="concentric" } diff --git a/docs/src/content/components/webgl/Area.md b/docs/src/content/components/webgl/Area.md deleted file mode 100644 index 2407f2ebc7..0000000000 --- a/docs/src/content/components/webgl/Area.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -description: 'Marking component which shades the space under a line on a chart to emphasize the magnitude and trend of data over a range. In a WebGL layer, it lies on the floor, or rises as a curtain with a z.' -category: WebGL marks -related: [Area, guides/webgl] -components: - - { name: webgl/Area, label: Area } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A curtain from the floor (or `z0`) up to `z` along the rows, one per group. - -:example{ name="areas" } - -:example{ name="ridgeline" } diff --git a/docs/src/content/components/webgl/Axis.md b/docs/src/content/components/webgl/Axis.md deleted file mode 100644 index fed0547f87..0000000000 --- a/docs/src/content/components/webgl/Axis.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -description: "Commonly used component displays the scale and reference lines on a chart, providing context for interpreting data values. In a WebGL layer, it runs along the plot box's edges: bottom for x, left for y, and back for z." -category: WebGL -related: [Axis, guides/webgl] -components: - - { name: webgl/Axis, label: Axis } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -Tick labels along an edge: `bottom` for `x`, `left` for `y`, and `back` for `z` (up the corner behind the plot). They keep to the edges in front as the view turns. - -Labels are drawn on the plot box, turning with it: the floor's (`bottom`, `left`) lie on it, as on an [isometric](/docs/guides/isometric#text) chart, and the height axis' (`back`) stand on the back wall beside its edge. `tickLabelProps={{ viewport: true }}` and `labelProps={{ viewport: true }}` draw them facing the viewer instead, over the scene, upright and crisp however the view turns. - -```svelte - - - - - - -``` - -:example{ component="webgl/Points" name="scatter-3d" } - -:example{ component="webgl/Spline" name="temperatures" } diff --git a/docs/src/content/components/webgl/Bars.md b/docs/src/content/components/webgl/Bars.md deleted file mode 100644 index e66fb874c8..0000000000 --- a/docs/src/content/components/webgl/Bars.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -description: 'Marking component which applies horizontal bars to represent and visually compare discrete data values. In a WebGL layer, each bar is a box standing as tall as its z.' -category: WebGL marks -related: [Bars, guides/webgl] -components: - - { name: webgl/Bars, label: Bars } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A box per row, standing on its `x` × `y` band cell, as tall as its `z`. - -```svelte - - - - - -``` - -:example{ name="columns" } - -## Stacked - -With series and `valueAxis="z"`, bars stack up off the floor. - -:example{ name="stacked-columns" } - -## Heatmap and calendar - -:example{ name="heatmap" } - -:example{ name="calendar" } diff --git a/docs/src/content/components/webgl/Bin.md b/docs/src/content/components/webgl/Bin.md deleted file mode 100644 index 8cc8848567..0000000000 --- a/docs/src/content/components/webgl/Bin.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -description: 'Composite mark grouping two-dimensional points into a grid of hexagons, squares, or triangles, to count or summarize what falls in each cell. In a WebGL layer, each cell stands as tall as its z.' -category: WebGL marks -related: [Bin, GeoBin, guides/webgl] -components: - - { name: webgl/Bin, label: Bin } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -Rows grouped into hexagons (or squares, or triangles) of the plot, or of the map as projected, as the core [Bin](/docs/components/Bin) groups them. Each cell stands up `z` tall (ex. its `count`), colored by its count unless given a `fill`. Every cell is the same shape, so thousands draw as one. - -```svelte - - - -``` - -:example{ name="hexbin" } - -## On a map - -:example{ name="walmart" } - -`weight` counts each row by a value (ex. the people in a cell of gridded population), and `gap` stands the cells apart. - -:example{ name="state-population" } diff --git a/docs/src/content/components/webgl/Contour.md b/docs/src/content/components/webgl/Contour.md deleted file mode 100644 index 4ff422ffa7..0000000000 --- a/docs/src/content/components/webgl/Contour.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -description: 'Composite mark drawing isolines to delineate regions above and below a particular continuous value. Supports grid data, scattered data with spatial interpolation, and continuous functions. In a WebGL layer, its lines lie flat or rise to their heights.' -category: WebGL surfaces -related: [Contour, guides/webgl] -components: - - { name: webgl/Contour, label: Contour } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -Contour lines on their own: flat at `z` pixels (ex. over a `Raster`), or each raised to its threshold's height with `z="value"`. It takes values the same ways as [Surface](/docs/components/webgl/Surface). - -:example{ name="basic" } diff --git a/docs/src/content/components/webgl/GeoPath.md b/docs/src/content/components/webgl/GeoPath.md deleted file mode 100644 index 613a1a7fcf..0000000000 --- a/docs/src/content/components/webgl/GeoPath.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -description: 'Geographic component which renders shapes such as countries, states, or regions by drawing their boundaries based on coordinate data. In a WebGL layer, features rise by their z, or follow a globe.' -category: WebGL geo -related: [GeoPath, guides/webgl, guides/geo] -components: - - { name: webgl/GeoPath, label: GeoPath } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -Features on the floor through the chart's projection, extruded `z` tall (a property key or function of the feature, through the chart's `z` scale, or pixels). Lines, and outlines with `stroke`, draw on top. A collection draws as one mark, so thousands of features stay quick. `motion` eases each feature's height and fill to new values. - -```svelte - - - d.properties.population} fill="var(--color-primary)" /> - - -``` - -:example{ name="election" } - -## Buildings, with shadows - -d3-geo reads a polygon's outside ring clockwise, and the other way round as the rest of the world, so rewind rings from other sources (ex. OpenStreetMap) before drawing them. - -:example{ component="webgl/Light" name="buildings" } - -## On a globe - -With the `globe` projection, features' lines draw over the sphere, and `{ type: 'Sphere' }` fills the globe itself (ex. beneath an image still loading). - -:example{ component="webgl/GeoRaster" name="globe-tiles" } diff --git a/docs/src/content/components/webgl/GeoRaster.md b/docs/src/content/components/webgl/GeoRaster.md deleted file mode 100644 index 769ce42016..0000000000 --- a/docs/src/content/components/webgl/GeoRaster.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -description: 'Geographic component which reprojects a raster image (such as NASA Blue Marble) onto any d3-geo projection. In a WebGL layer, the image can rise into terrain or wrap a globe.' -category: WebGL geo -related: [GeoRaster, guides/webgl, guides/geo] -components: - - { name: webgl/GeoRaster, label: GeoRaster } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -An image (`image`: a URL, or an image, canvas, or bitmap) laid over the map through the chart's projection, as the core [GeoRaster](/docs/components/GeoRaster) reprojects one, and with the same props: it's equirectangular unless `sourceProjection` gives the projection it was drawn in, and `interpolate` / `pixelated` choose blended or crisp pixels. Unlike core's, it blends (`'bilinear'`) by default, which costs the GPU nothing. `elevation` (a function of longitude and latitude) raises it into terrain, and `tooltip` shows the longitude and latitude under the pointer. - -:example{ name="projections" } - -## Terrain - -Map tiles stitched into one image (`sourceProjection` maps longitude and latitude onto its Web Mercator pixels) and draped over `elevation`, lit by a `Light`: satellite imagery over a mountain, at true scale times the exaggeration. The tiles load once for the area, so they don't sharpen as you zoom in. - -:example{ name="terrain" } - -## Globe - -The `globe` projection lays the map on a real sphere you can orbit. Fit it as an orthographic map (the sphere is the size and place the disk would be, standing on the floor) and the same marks draw on it: `GeoRaster` wraps it in an image, `GeoPath` follows its curve, `Points` and `Bars` stand out from it, `Spline` runs along great circles, and `Surface` / `Raster` cover it. - -```svelte - - - - - - - - -``` - -:example{ name="globe" } - -:example{ name="planets" } - -:example{ name="globe-textures" } - -:example{ name="globe-tiles" } diff --git a/docs/src/content/components/webgl/GeoTile.md b/docs/src/content/components/webgl/GeoTile.md deleted file mode 100644 index 069dfaccce..0000000000 --- a/docs/src/content/components/webgl/GeoTile.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -description: 'Geographic component which renders map tiles in a grid supporting efficient zooming and panning for larger scale maps. In a WebGL layer, tiles can rise into terrain from elevation tiles.' -category: WebGL geo -related: [GeoTile, GeoRaster, guides/webgl, guides/geo] -components: - - { name: webgl/GeoTile, label: GeoTile } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -Map tiles from an XYZ tile service, with the core [GeoTile](/docs/components/GeoTile) props (`url`, `zoomDelta`, `tileSize`, `disableCache`, `debug`), picked for the chart's Web Mercator projection as it picks them. A `projection` transform zooms the map, and sharper tiles load as it does. - -:example{ name="zoomable" } - -## Terrain - -`elevation` raises the tiles from a second tile service of elevation tiles (ex. AWS's open terrain tiles, or Mapterhorn): their `url`, `encoding` (`'terrarium'`, or Terrain-RGB as `'mapbox'`), and `maxZoom`, their meters through the chart's `z` scale. `maxZoom` and the elevation's `maxZoom` say how deep each service goes: deeper tiles show part of their ancestor, enlarged. - -```svelte - `https://tiles.versatiles.org/tiles/satellite-raster/${z}/${x}/${y}`} - maxZoom={12} - elevation={{ - url: (x, y, z) => `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`, - maxZoom: 15 - }} -/> -``` - -:example{ name="terrain" } - -## Detail that follows the camera - -In a 3D view, tiles are picked from the camera rather than the projection: each tile is as deep as it needs to be to look about `tileSize` pixels across on screen, so tiles are sharp up close and coarse in the distance, and sharpen as the camera moves in. A new tile draws at once from an ancestor already loaded (blurrier, as the tile it's zoomed in from), then fades to its own as it arrives; tiles leaving the view stay until those taking their place are drawn, the sharpest showing wherever they overlap (so zooming out keeps what was sharp, and fills around it). Beneath them all, a few coarse tiles (the map's own, three zooms up) show through wherever a tile has yet to arrive. So moving never opens a hole, as the core seamless layering of `GeoTile`s does, with one `GeoTile`. The same works on the `globe`, where tiles on its far side are left out. - -:example{ name="globe" } diff --git a/docs/src/content/components/webgl/Grid.md b/docs/src/content/components/webgl/Grid.md deleted file mode 100644 index 35209b96c8..0000000000 --- a/docs/src/content/components/webgl/Grid.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -description: "Commonly used component which draws horizontal and vertical lines respecting scales across a chart to enhance readability and help align data points with axis values. In a WebGL layer, it lines the plot box's floor and back walls." -category: WebGL -related: [Grid, guides/webgl] -components: - - { name: webgl/Grid, label: Grid } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -The floor and the two walls behind the plot, with lines at the scales' ticks. The walls move to the far sides as the view turns. - -```svelte - - - - -``` - -:example{ component="webgl/Points" name="scatter-3d" } - -Set `x`, `y`, or `z` to `false` to leave out a direction's lines (ex. ``). - -:example{ component="webgl/Bin" name="hexbin" } diff --git a/docs/src/content/components/webgl/Highlight.md b/docs/src/content/components/webgl/Highlight.md deleted file mode 100644 index 84deb542d9..0000000000 --- a/docs/src/content/components/webgl/Highlight.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -description: 'Interaction component manages and displays tooltips allowing dynamic information to appear in response to user interactions. In a WebGL layer, it marks the hovered row with a point facing the viewer, traced on the floor and back walls.' -category: WebGL -related: [Highlight, Tooltip, guides/webgl] -components: - - { name: webgl/Highlight, label: Highlight } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -The tooltip's row (or `data`), marked as the core [Highlight](/docs/components/Highlight) marks it on an `isometric` chart, with the same props: `points` rings it with a circle facing the viewer, `lines` trace its position across the floor and, with a `z`, across and up each back wall (`axis` picks which), and `shadows` put a spot beneath it on the floor and level with it on each wall. Pass props to style each, ex. `points={{ r: 8, fill: 'none' }}`. - -```svelte - - - - - -``` - -On a flat `WebGL` chart, core's own `Highlight` in an `Svg` layer over it works as well (ex. [scatter](/docs/components/webgl/Points/scatter)). - -:example{ component="webgl/Points" name="scatter-3d" } diff --git a/docs/src/content/components/webgl/Link.md b/docs/src/content/components/webgl/Link.md deleted file mode 100644 index 8ffaca078b..0000000000 --- a/docs/src/content/components/webgl/Link.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -description: 'Marking component which draws a line or curve between two points to highlight or connect data. In a WebGL layer, links can rise or arch between their ends.' -category: WebGL marks -related: [Link, guides/webgl] -components: - - { name: webgl/Link, label: Link } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A line per row, straight or arched (`arc`), placed as the core [`Link`](/docs/components/Link) places it. `x1` / `y1` and `x2` / `y2` are its ends, as data properties or functions of the row through the chart's scales (longitude and latitude on a map), or numbers in pixels; the end defaults to the start. `z1` / `z2` raise them, through the chart's `z` scale or in pixels: ex. a pin's stem from the floor up to its head. - -```svelte - -``` - -Without `x1` / `y1`, each row is a link from its `source` node to its `target`, at their `x` / `y` in pixels: ex. a hierarchy's `links()`. - -:example{ name="pin-map" } diff --git a/docs/src/content/components/webgl/Points.md b/docs/src/content/components/webgl/Points.md deleted file mode 100644 index 705b04b789..0000000000 --- a/docs/src/content/components/webgl/Points.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -description: 'Marking component which plots individual data points on a graph to show distribution, relationships, or clusters without connecting lines. In a WebGL layer, each point is a sphere (a disc when flat), and can glow or wear an image.' -category: WebGL marks -related: [Points, guides/webgl] -components: - - { name: webgl/Points, label: Points } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A sphere per row, at its `x`, `y`, and `z`. `r` sets the radius in pixels, else the chart's `r` scale. - -```svelte - - - - - -``` - -:example{ name="scatter-3d" } - -## Glow and images - -`glow` draws each sphere in its own color whatever the lights (ex. a star), and `image` wraps each in an equirectangular image (ex. a planet), turned by `rotate` and leaning by `tilt`. - -:example{ name="solar-system" } - -Tens of thousands of glowing points, placed along spiral arms and colored from the middle out, turning slowly (drag to look from another angle). - -:example{ name="galaxy" } - -## Flat - -Without a view, points are discs, for many thousands of them. - -:example{ name="scatter" } - -The grid, axes, and highlight can be core's own `Svg` layers instead, with only the points in WebGL: - -:example{ name="scatter-with-svg" } diff --git a/docs/src/content/components/webgl/Polygon.md b/docs/src/content/components/webgl/Polygon.md deleted file mode 100644 index fbbc07396b..0000000000 --- a/docs/src/content/components/webgl/Polygon.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -description: 'Primitive component which renders a multi-sided shape on a chart to represent complex areas, boundaries, or regions of interest. In a WebGL layer, it stands up by its z.' -category: WebGL marks -related: [Polygon, guides/webgl] -components: - - { name: webgl/Polygon, label: Polygon } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A polygon per row, with the core [Polygon](/docs/components/Polygon) props: a regular polygon (or star, with `inset`) of `points` corners about `cx` / `cy` with radius `r`, or explicit `points` in pixels, `rotate`d, stretched, skewed, and rounded by `cornerRadius`. `z` stands it up, as on an `isometric` chart; without one it lies flat. - -:example{ name="tree" } diff --git a/docs/src/content/components/webgl/Raster.md b/docs/src/content/components/webgl/Raster.md deleted file mode 100644 index b0fb00ccb0..0000000000 --- a/docs/src/content/components/webgl/Raster.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -description: 'Composite mark rendering a pixel-based heatmap where each pixel is colored by a scalar value. Supports grid data, scattered data with spatial interpolation, and continuous functions. In a WebGL layer, it lies on the floor as an image.' -category: WebGL surfaces -related: [Raster, guides/webgl] -components: - - { name: webgl/Raster, label: Raster } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -The values as an image on the floor (or `z` pixels above it), sampled as finely as the image allows rather than at a surface's vertices. It takes values the same ways as [Surface](/docs/components/webgl/Surface), and `imageRendering="pixelated"` shows each cell with hard edges. - -:example{ name="basic" } diff --git a/docs/src/content/components/webgl/Rect.md b/docs/src/content/components/webgl/Rect.md deleted file mode 100644 index b22ec38f52..0000000000 --- a/docs/src/content/components/webgl/Rect.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -description: "Primitive component which draws a rectangle to highlight areas, ranges, or specific regions of interest. In a WebGL layer, it's a box standing as tall as its z." -category: WebGL marks -related: [Rect, guides/webgl] -components: - - { name: webgl/Rect, label: Rect } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A box per row, `z` tall, placed as the core [`Rect`](/docs/components/Rect) places it: by its sides `x0` / `x1` and `y0` / `y1`, or by `x` / `y` and a `width` / `height` in pixels. Sides and positions are data properties or functions of the row through the chart's scales, or numbers in pixels. A `z` function can return `[start, end]` to float a box between two values (ex. a treemap's tiers). - -```svelte - [d.depth, d.depth + 1]} /> -``` - -:example{ name="treemap" } diff --git a/docs/src/content/components/webgl/Rule.md b/docs/src/content/components/webgl/Rule.md deleted file mode 100644 index 9ee15f511b..0000000000 --- a/docs/src/content/components/webgl/Rule.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -description: 'Commonly used component acting as a visual guideline on a chart that helps align and measure data values along an axis. In a WebGL layer, rules lie on the floor.' -category: WebGL marks -related: [Rule, guides/webgl] -components: - - { name: webgl/Rule, label: Rule } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -Reference lines with the core [Rule](/docs/components/Rule) props, on the floor (or `z` pixels above it): `x` / `y` at a value, at the plot's edges (`true`, `'$left'`, `'$top'`, ...), or as an accessor for a line per row, from zero (or the band) to its value. `class` styles them as on any core mark. - -:example{ name="lollipop" } diff --git a/docs/src/content/components/webgl/Spline.md b/docs/src/content/components/webgl/Spline.md deleted file mode 100644 index f211a9094a..0000000000 --- a/docs/src/content/components/webgl/Spline.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -description: 'Marking component which applies data points connected by smooth, curved lines to show trends or patterns over a continuous range. In a WebGL layer, lines run through 3D, colored per point.' -category: WebGL marks -related: [Spline, guides/webgl] -components: - - { name: webgl/Spline, label: Spline } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A line through the rows, one per `g` (or `stroke` key, or `c`) value, at each row's `x`, `y`, and `z`. `stroke` colors it per point, so a line can change color along its length. - -```svelte - - - - - -``` - -:example{ name="series" } - -:example{ name="line3d" } - -:example{ name="temperatures" } diff --git a/docs/src/content/components/webgl/Text.md b/docs/src/content/components/webgl/Text.md deleted file mode 100644 index 50620e3412..0000000000 --- a/docs/src/content/components/webgl/Text.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -description: 'Primitive component which adds custom text for labeling, annotation, or commentary. In a WebGL layer, text lies on the surface beneath it, or faces the viewer.' -category: WebGL -related: [Text, guides/webgl] -components: - - { name: webgl/Text, label: Text } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -A label per row, placed as the core [`Text`](/docs/components/Text) places it: `x`, `y`, and `z` are data properties or functions of the row, through the chart's scales (longitude and latitude on a map), or numbers in pixels. `value` is a property, a function, or the text itself. - -By default a label lies on the surface at its height (ex. the tops of boxes), turning and tipping with the view, in `fontSize` and `fill`. With `viewport` it faces the viewer instead, drawn over the scene upright and crisp however the view turns, styled with `class`. - -```svelte - -``` - -For a layout already in pixels (ex. a tree), place a label per node by numbers. - -:example{ component="webgl/Polygon" name="tree" } - -:example{ component="webgl/Rect" name="treemap" } diff --git a/docs/src/content/components/webgl/Vector.md b/docs/src/content/components/webgl/Vector.md deleted file mode 100644 index 1e77b9dbaf..0000000000 --- a/docs/src/content/components/webgl/Vector.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -description: 'Primitive component which draws directional arrows or spikes at data points to show magnitude and direction. In a WebGL layer, they lie on the floor.' -category: WebGL marks -related: [Vector, guides/webgl] -components: - - { name: webgl/Vector, label: Vector } ---- - -::tip -Part of [`@layerchart/webgl`](/docs/guides/webgl), drawn in a `WebGL` layer. See the [WebGL guide](/docs/guides/webgl) to get started. -:: - -## Usage - -Arrows (`shape="arrow"`), filled arrows (`'arrow-filled'`), or spikes (`'spike'`) with the core [Vector](/docs/components/Vector) props: placed at `x` / `y`, `length` long (through the chart's `r` scale), and turned `rotate` degrees clockwise from up the plot. - -In a 3D view, each is a solid arrow (or cone) that can point any way: `z` places it in the box (through the chart's `z` scale), and `tilt` points it up out of the floor (`90` straight up). Flat, it lies on the floor as core draws it. - -```svelte - -``` - -:example{ name="field" } diff --git a/docs/src/content/guides/bundle-size.md b/docs/src/content/guides/bundle-size.md index d06875f602..7704de2e53 100644 --- a/docs/src/content/guides/bundle-size.md +++ b/docs/src/content/guides/bundle-size.md @@ -129,6 +129,8 @@ Note that it's a flat cost per instance rather than a fixed percentage. The same So the saving matters when you render **many instances** — a scatter plot of thousands of ``s, a heatmap of ``s. For a chart with a handful of marks it won't be measurable. +`@layerchart/webgl` follows the same pattern: its marks are layer-agnostic, drawing core's versions outside a `WebGL` layer, and `@layerchart/webgl/webgl` is WebGL only. See [Switching layers](/docs/guides/webgl#switching-layers). + The `layerchart/svg`, `layerchart/canvas`, and `layerchart/html` sub-paths re-export every layer-agnostic helper too (layouts, scales, tooltip primitives, etc.), so a single per-layer import path can cover a typical chart end-to-end. ### When per-layer is worth it diff --git a/docs/src/content/guides/layers.md b/docs/src/content/guides/layers.md index a27cc2e58c..35870be753 100644 --- a/docs/src/content/guides/layers.md +++ b/docs/src/content/guides/layers.md @@ -56,6 +56,13 @@ LayerChart also support CSS classes and styling for the `Canvas` layer. WebGL layers are drawn by the separate `@layerchart/webgl` package, whose `WebGL` layer and marks are rendered on the GPU. With a `perspective` or `orthographic` chart `view` they're true 3D (lit, shadowed, and orbited); without one they're flat, for charts with far more marks than `Svg` or `Canvas` handle well. See [WebGL](/docs/guides/webgl). +Its marks share their core namesakes' props, and its `Layer` adds `type="webgl"`, so a chart imported from `@layerchart/webgl` moves between all four layers (see [Switching layers](/docs/guides/webgl#switching-layers)). Compound marks (`Pie`, `Labels`, `Calendar`, `BoxPlot`, ...) are LayerChart's own, drawn with its WebGL marks. Examples on these pages draw with WebGL from the layer toggle where they look the same; the rest draw with Canvas, as they use something WebGL doesn't draw yet: + +- `Ellipse`, `Image`, and Sankey and Dagre links +- rounded corners on a 3D chart (flat `Bars` and `Rect` round theirs) +- radial charts' `Spline`, `Grid`, and `Axis` +- labels past the plot's edge + > Most browsers limit the number of concurrent WebGL contexts by page/domain (references: [Chromium](https://issues.chromium.org/issues/40543269), [Rive](https://rive.app/docs/runtimes/web/canvas-vs-webgl)) and is why some libraries such as [μPlot](https://github.com/leeoniya/uPlot) do not leverage it. A `WebGL` layer gives up its context when it's scrolled well off screen, so a page can have more of them than the limit, just not all on screen at once. - **Stengths:** performance (hundreds of thousands of marks), true 3D, lighting and shadows diff --git a/docs/src/content/guides/layers/features.ts b/docs/src/content/guides/layers/features.ts index 63a8615947..ed13f2c2f5 100644 --- a/docs/src/content/guides/layers/features.ts +++ b/docs/src/content/guides/layers/features.ts @@ -56,7 +56,8 @@ export const graphics = [ support: true }, webgl: { - support: true + support: false, + note: 'No Ellipse mark yet' } }, { @@ -71,7 +72,8 @@ export const graphics = [ support: true }, webgl: { - support: true + support: true, + note: 'Path data lies on the floor, filled and outlined (ex. Trail, Violin, Density, Ribbon), with markers' } }, { @@ -101,7 +103,8 @@ export const graphics = [ support: true }, webgl: { - support: true + support: true, + note: 'As Points image (no Image mark yet)' } } ]; @@ -117,7 +120,7 @@ export const styles = [ }, canvas: { support: false, - note: 'LayerChart provides pointer events via a "hit canvas", but no `hover:` styling is provided out of the box' + note: 'LayerChart provides pointer events via a "hit canvas", but no hover: styling is provided out of the box' }, webgl: { support: false @@ -151,7 +154,8 @@ export const styles = [ support: false }, webgl: { - support: false + support: true, + note: "LayerChart's marker shapes (arrow, triangle, circle, dot, square, ...), lying on the floor; not custom snippets" } }, { @@ -172,8 +176,8 @@ export const styles = [ link: 'https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip' }, webgl: { - support: false, - note: 'Requires custom shader implementation' + support: true, + note: 'To the plot box (clip); not to ClipPath shapes' } }, { @@ -183,12 +187,12 @@ export const styles = [ }, svg: { support: false, - note: 'Workaround via `` and 2x stroke', + note: 'Workaround via and 2x stroke', link: 'https://svelte.dev/playground/00fdbf89041340fe9e57c4e83b87ff2a?version=5.25.8' }, canvas: { support: false, - note: 'Workaround via `ctx.clip()` and 2x stroke', + note: 'Workaround via ctx.clip() and 2x stroke', link: 'https://stackoverflow.com/questions/36615592/canvas-inner-stroke' }, webgl: { @@ -213,7 +217,8 @@ export const styles = [ note: 'stroke: along (1/2 in/out)' }, webgl: { - support: false + support: true, + note: 'Outlines of bars, rects, circles, and shapes, and lines a CSS pixel wide, dashed with dashArray' } }, { @@ -228,7 +233,8 @@ export const styles = [ support: false }, webgl: { - support: false + support: false, + note: 'motion (tweens and springs) works' } } ] as const; @@ -246,7 +252,8 @@ export const text = [ support: false }, webgl: { - support: false + support: true, + note: 'Labels lying on the surface wrap to width' } }, { @@ -261,7 +268,7 @@ export const text = [ support: false }, webgl: { - support: false + support: true } }, { @@ -276,7 +283,8 @@ export const text = [ support: false }, webgl: { - support: false + support: false, + note: 'Placed at its offset along the path and turned its way, not bent along it' } }, { @@ -301,7 +309,7 @@ export const text = [ }, svg: { support: false, - note: 'Hacky way with `` but no padding, gradient, etc', + note: 'Hacky way with but no padding, gradient, etc', link: 'https://svelte.dev/playground/6713b04bc8274b6dbf6b7487fdd80404?version=5.28.2' }, canvas: { @@ -380,7 +388,8 @@ export const other = [ support: false }, webgl: { - support: false + support: false, + note: "Drawn within its canvas: tick labels at the plot's edge can be clipped" } }, { @@ -437,11 +446,11 @@ export const other = [ }, svg: { support: false, - note: 'Faux 3D with `isometric`' + note: 'Faux 3D with isometric' }, canvas: { support: false, - note: 'Faux 3D with `isometric`' + note: 'Faux 3D with isometric' }, webgl: { support: true @@ -460,7 +469,8 @@ export const other = [ support: false }, webgl: { - support: false + support: true, + note: 'Inside a Group' } } ]; diff --git a/docs/src/content/guides/transform.md b/docs/src/content/guides/transform.md index 4aaa3e8eb6..58d7b47f25 100644 --- a/docs/src/content/guides/transform.md +++ b/docs/src/content/guides/transform.md @@ -450,7 +450,7 @@ On a chart with a [`view`](/docs/guides/isometric#dragging-the-view) to turn, `r /> ``` -Without them, a drag tips the view from `0` (seen from directly above) to edge on. An `isometric` floor can't go further, but a 3D view (`@layerchart/webgl`) can: `tiltExtent: [0, 180]` turns it on round to look from beneath, ex. a [globe](/docs/components/webgl/GeoRaster)'s south pole. The view's own `rotate` and `tilt` aren't limited, only where a drag takes them. +Without them, a drag tips the view from `0` (seen from directly above) to edge on. An `isometric` floor can't go further, but a 3D view (`@layerchart/webgl`) can: `tiltExtent: [0, 180]` turns it on round to look from beneath, ex. a [globe](/docs/components/GeoRaster#webgl)'s south pole. The view's own `rotate` and `tilt` aren't limited, only where a drag takes them. On a globe projection (`mode: 'projection'`), they bound its yaw and pitch instead: `tiltExtent: [-90, 90]` stops it at the poles (see [Globe rotation constraints](#globe-rotation-constraints)). diff --git a/docs/src/content/guides/views.md b/docs/src/content/guides/views.md index ec1f396924..1f332a8a0d 100644 --- a/docs/src/content/guides/views.md +++ b/docs/src/content/guides/views.md @@ -39,7 +39,7 @@ The same data drawn both ways: `isometric` in an `Svg` layer, and `perspective` :example{ component="Chart" name="isometric-scatter-3d" } -:example{ component="webgl/Points" name="scatter-3d" } +:example{ component="Points" name="scatter-3d" } ## What they share @@ -62,7 +62,7 @@ All three views take the same options, so moving a chart between them is mostly A [geo projection](/docs/guides/geo) and a view do different jobs, and they combine. The projection maps longitude and latitude to the plot area, in place of the `x` / `y` scales: it decides where places are on the flat map. The view then decides how that plot area is seen: straight on without one, or as a floor seen at an angle with one. -So any projection can be the floor of any view, with `z` raising features, points, or bins off the map: ex. [an election map](/docs/components/GeoPath/election-isometric) or [pins](/docs/components/Chart/isometric-pin-map) on an `isometric` floor (see [Paths and maps](/docs/guides/isometric#paths-and-maps)), or [population bins](/docs/components/webgl/Bin/state-population) under a `perspective` camera. +So any projection can be the floor of any view, with `z` raising features, points, or bins off the map: ex. [an election map](/docs/components/GeoPath/election-isometric) or [pins](/docs/components/Chart/isometric-pin-map) on an `isometric` floor (see [Paths and maps](/docs/guides/isometric#paths-and-maps)), or [population bins](/docs/components/Bin/state-population) under a `perspective` camera. Two things look alike but aren't: diff --git a/docs/src/content/guides/webgl.md b/docs/src/content/guides/webgl.md index 4af90339d2..9324c91dd1 100644 --- a/docs/src/content/guides/webgl.md +++ b/docs/src/content/guides/webgl.md @@ -45,7 +45,7 @@ category: state ## Quick start -Everything comes from `@layerchart/webgl`. `Chart`, `Tooltip`, and `Legend` are core's own, re-exported. The chart's `view` says how it's seen (`perspective`, as `isometric` does for flat layers), and the marks inside a [`WebGL`](/docs/components/webgl/WebGL) layer are drawn through it. A `transform` turns, pans, and zooms it. +Everything comes from `@layerchart/webgl`. `Chart`, `Tooltip`, and `Legend` are core's own, re-exported. The chart's `view` says how it's seen (`perspective`, as `isometric` does for flat layers), and the marks inside a [`WebGL`](/docs/components/WebGL) layer are drawn through it. A `transform` turns, pans, and zooms it. ```svelte + + + + + + + + +``` + +`Light` and `Surface` have no core namesake, so they're drawn only in a `WebGL` layer. Core's own `Layer` draws `settings.layer="webgl"` as `canvas`, and warns once. + +For a chart that's only ever WebGL, import from `@layerchart/webgl/webgl` instead, as `layerchart/svg` is for SVG. Its marks draw only in a `WebGL` layer (and `Layer` is `WebGL`), so the chart doesn't bundle core's versions of them: a few KB gz per chart. + ## The view The chart's `view` is the camera. `perspective` draws farther things smaller; `orthographic` keeps sizes true at any depth, as `isometric` does (see [Views](/docs/guides/views) for how they compare). Call either with options, or pass it as is for the defaults: @@ -106,7 +128,7 @@ A chart's `transform` moves a 3D view as it does an [isometric](/docs/guides/iso > ``` -`onTransform` reports the angles a drag turns to as `rotation` (`x` is `rotate`, `y` is `tilt`). Hand them back to the view's options to keep controls in step with a drag. The transform's `zoomIn()`, `zoomOut()`, and `reset()` work as on any chart, so `TransformContextControls` works too; the [terrain](/docs/components/webgl/Surface#terrain) examples have them. +`onTransform` reports the angles a drag turns to as `rotation` (`x` is `rotate`, `y` is `tilt`). Hand them back to the view's options to keep controls in step with a drag. The transform's `zoomIn()`, `zoomOut()`, and `reset()` work as on any chart, so `TransformContextControls` works too; the [terrain](/docs/components/Surface#terrain) examples have them. ```svelte