holograph-3d
v1.0.0
Published
Zero-dependency WebGL2 3D charts with a holographic look: GPU-instanced, shader-animated, render-on-demand and fully responsive.
Maintainers
Readme
holograph-3d
Zero-dependency WebGL2 3D charts with a holographic look: GPU-instanced, animated entirely in shaders, render-on-demand, and responsive on any screen.
- Bars: an instanced bar matrix with luminous, pixel-exact edges, contact shadows and ripple-wave transitions.
- Scatter: ray-traced sphere impostors (perfectly round at any zoom), floor footprints and drop lines.
- Surface: morphing height fields with per-pixel contour lines, adaptive wireframe, and a contour map projected on the floor.
- Ribbons: multi-series lines as translucent light curtains with pixel-exact glowing crests; hover lights a column.
- Donut: an extruded ring whose slice angles, heights and colors morph on the GPU; hover pulls a slice out.
- Globe: a graticule planet with an atmosphere, value spikes at locations and great-circle arcs that sweep between them.
- Spiral: a time series wound on a rising coil, one turn per cycle, so the same month of every year lines up.
- Voxel cube: a 3D grid of values as cubes sized and colored by value;
setThreshold()peels it open. - Orbit: categories as tilted orbits, items as planets sized by value, the sun sized by the total.
- Horizontal bars: ranked categories with value labels and a back-wall grid; with
sort, updates become a bar race. - Heatmap: a category × category grid of low tiles colored (and slightly raised) by value; missing cells stay empty.
- Treemap: a squarified treemap extruded into blocks (area = value, height = value or a second measure).
- Funnel: stacked tapered stages with conversion callouts;
shape: 'square'makes a stepped pyramid. - Radar: each series is a translucent extruded layer over a radial grid, so overlapping profiles stay readable.
- Network: a 3D force-directed graph with sphere nodes and constant-width links that stay glued to animating nodes.
- Pictogram: isotype charts built from 3D icons (one icon =
unit); the last partial icon is cut at its share, with a capped cross-section and a wire lattice for the empty part. - Icon scatter: a scatter plot whose points are 3D icons: group → icon, color and surface pattern; value → size.
npm install holograph-3dimport { BarChart3D } from 'holograph-3d';
const chart = new BarChart3D('#chart', {
title: 'Revenue by region',
data: {
values: [[120, 90, 140], [80, 110, 95]], // values[row][column]
rows: ['North', 'South'],
columns: ['Q1', 'Q2', 'Q3'],
},
axes: { x: 'Quarter', y: 'Revenue', z: 'Region' },
theme: 'aurora',
});
chart.on('hover', (e) => console.log(e?.datum));
chart.setData(nextData); // morphs from exactly what is on screenThe chart fills its container, so give the container a height (e.g. height: 60vh).
Charts
| Class | Data |
| --- | --- |
| BarChart3D | { values: number[][], rows?: string[], columns?: string[] } |
| ScatterChart3D | { points: { x, y, z, value?, size?, label? }[] } |
| SurfaceChart3D | { values: number[][], x?: [min, max], z?: [min, max] } or { fn: (x, z) => y, x, z, resolution? } |
| RibbonChart3D | { series: { name, values: number[] }[], labels?: string[] } |
| DonutChart3D | { slices: { label, value, color?, height?, children?: [...] }[] } (children = outer breakdown ring) |
| GlobeChart3D | { points?: { lat, lon, value, label? }[], arcs?: { from: [lat, lon], to: [lat, lon], value?, label? }[] } |
| SpiralChart3D | { values: number[], labels?: string[], cycles?: string[] } |
| VoxelChart3D | { values: number[][][] /* [x][y][z] */, x?, y?, z?: string[] } |
| OrbitChart3D | { orbits: { label, items: { label, value }[] }[] } |
| HBarChart3D | { bars: { label, value, color? }[] } |
| HeatmapChart3D | same as BarChart3D: { values: number[][], rows?, columns? } (NaN = empty cell) |
| TreemapChart3D | { nodes: { label, value?, height?, color?, children?: [...] }[] } |
| FunnelChart3D | { stages: { label, value, color? }[] } |
| RadarChart3D | { axes: string[], series: { name, values: number[], color? }[] } |
| NetworkChart3D | { nodes: { id, label?, group?, value?, size? }[], links: { source, target, weight? }[] } |
| PictogramChart3D | { categories: string[], series: { name, values: number[], icon?, color?, pattern? }[] } |
| IconScatterChart3D | { points: { x, y, z, group?, value?, label?, id? }[], groups?: { name, icon, color?, pattern? }[] } |
createChart(el, { type: 'bar' | 'scatter' | 'surface' | 'ribbon' | 'donut' | 'network' | 'treemap' | 'funnel' | 'radar' | 'hbar' | 'heatmap' | 'globe' | 'spiral' | 'voxel' | 'orbit' | 'pictogram' | 'iconScatter', ...options }) is a one-call factory.
Common options
| Option | Default | |
| --- | --- | --- |
| theme | 'auto' | 'aurora' \| 'nebula' \| 'ember' \| 'glacier' \| 'auto' or { extends: 'aurora', accent: '#…', ramp: [...] } |
| title, subtitle | none | Header text |
| axes | none | { x, y, z } axis titles |
| format | compact number format | (v) => string for ticks, legend and tooltips |
| animation | { duration: 1100, stagger: 0.5 } | false to disable |
| autoRotate | false | true (8°/s) or degrees per second; pauses while the user interacts |
| view | { yaw: -38, pitch: 27, zoom: 1 } | Initial camera (degrees) |
| legend, tooltip, hint | true | Toggle UI pieces |
| maxPixelRatio | 2 | DPR cap |
| adaptiveResolution | true | Lowers resolution only while animating on slow GPUs; always full-res when still |
| ariaLabel | title | Accessible label |
Bar options: gap (0–0.9), colorBy ('value' | 'row' | 'column').
Scatter options: pointSize, stems, shadows, valueLabel.
Surface options: contours (number or false), wireframe, floorMap.
Ribbon options: smooth (Catmull-Rom, default true), colorBy ('series' | 'value'), lineWidth (CSS px).
Donut options: innerRadius (0–0.9, 0 = pie), extrude ('value' | 'height' | 'uniform'),
sweep (degrees; e.g. 240 makes a gauge that opens toward the viewer), startAngle, max (gauge scale with an
empty track), centerLabel (true = total, or a caption such as 'Attempts'), colors (palette), callouts.
Slices with children get an outer ring (e.g. success / failure per category); children default to lighter shades
of their parent, outer slices get side callouts (value + share of parent), and the categories move to a list legend.
new DonutChart3D('#manual', {
title: 'Manual Flashing',
centerLabel: 'Attempts',
data: { slices: [
{ label: 'Production Version', value: 1133, color: '#00bf7a',
children: [{ label: 'Success', value: 912 }, { label: 'Failure', value: 221 }] },
{ label: 'Previous Version', value: 1546, color: '#00603f',
children: [{ label: 'Success', value: 1261 }, { label: 'Failure', value: 285 }] },
] },
});
new DonutChart3D('#auto', {
title: 'Auto Flashing', centerLabel: 'Attempts', sweep: 240,
data: { slices: [{ label: 'Success', value: 1235, color: '#ffc400' }, { label: 'Failure', value: 488, color: '#efdcae' }] },
});Bar options also take height, baseHeight and valueAxis (what HeatmapChart3D sets for its flat-tile look).
Horizontal bar options: sort ('none' | 'desc' | 'asc'), colorBy ('value' | 'single'), color, valueLabels, thickness.
Heatmap color scales come from the theme ramp, e.g. theme: { extends: 'aurora', ramp: ['#dbe8ff', '#3b82f6', '#fbbf24', '#dc2626'] }.
Globe options: graticule (degrees), labels (count). Spiral options: period (steps per turn, default 12).
Voxel options: threshold, sizeBy; method setThreshold(v). Orbit options: sunLabel, labels (count).
Treemap options: extrude ('value' | 'height' | 'uniform'; negative heights are fine), colors, labels (count), aspect.
Funnel options: shape ('round' | 'square'), neck (minimum radius fraction), gap, colors.
Radar options: max (number or one per axis), stacked (layers vs overlay), levels (grid rings), colors.
Network options: colorBy ('group' | 'value' | 'degree'), nodeSize, linkWidth, labels (how many top nodes are labelled).
Pictogram options: unit (value per icon; default a round number giving ~10 icons), icon, arrange
('row' isotype rows cropped left→right, 'stack' towers filled bottom→top; 'auto' stacks coins, cubes and gems),
perLayer (stack: icons per side of each layer), patterns (auto-assign a pattern per series, default true), colors, gap.
Icon scatter options: icon, iconSize, patterns, jitter, pointLabels (label each icon instead of axis ticks; good for icon legends).
3D icons and patterns
Icons are generated in code (lathes and extrusions, no asset files), normalized to the same unit frame
(footprint ±0.5, base at y = 0):
person, coin, gem, cube, star, heart, bolt, house, drop, tree, gear, shield.
Patterns are signed-distance fields evaluated per pixel in each icon's object space, so they stick to the icon while it
animates and stay sharp at any zoom. They tell series apart without relying on color:
none, stripes, dots, checker, grid, hex, waves, zigzag, crosshatch, scales, rings, diamonds.
new PictogramChart3D('#people', {
title: 'World population', unit: 0.5, format: (v) => `${v}B`,
data: { categories: ['Asia', 'Africa', 'Europe'], series: [
{ name: '2026', values: [4.75, 1.46, 0.74] },
{ name: '2050', values: [5.1, 2.5, 0.7], pattern: 'stripes' },
] },
});For your own charts, iconMesh(name) returns the raw mesh, IconLayer renders instanced icons with the same
morphing, picking and fill-cut shading, and GLSL_PATTERNS exposes hgPattern(id, uv, w) for any shader.
The network layout is computed once per setData, seeded from the previous positions so
surviving nodes stay put; it is O(n²) per iteration, comfortable up to roughly 1,500 nodes.
Methods
setData(data, { animate? }) · setTheme(theme) · setView({ yaw, pitch, zoom }, immediate?) ·
getView() · resetView() · setAutoRotate(speed) · on('hover' | 'select', fn) → unsubscribe ·
toDataURL() · resize() · destroy()
Interaction
| | Mouse | Touch | Keyboard (focus the chart) |
| --- | --- | --- | --- |
| Rotate | drag | one finger | arrow keys |
| Zoom | wheel | pinch | + / - |
| Pan | right-drag or shift-drag | two-finger drag | none |
| Reset | double-click | double-tap | 0 / Home |
| Inspect | hover | tap | none |
Tooltips are mirrored into an aria-live region for screen readers. prefers-reduced-motion
disables data animation and auto-rotate, and prefers-color-scheme drives theme: 'auto'.
Why it is fast
- One draw call per series. Each bar or point is an instance of one shared mesh.
- Animation runs on the GPU. Every instance stores a from and a to state, and the vertex shader
eases between them from a single
uProgressuniform. A data update is onebufferDatacall. Mid-animation updates start from what is on screen, because the easing exists in JS and GLSL. - Render-on-demand. The loop stops when nothing moves. Off-screen charts (IntersectionObserver) and hidden tabs draw nothing.
- 1×1 GPU picking. Hover renders only the pixel under the cursor into a 1×1 framebuffer through a pick matrix, then reads 4 bytes back.
- Adaptive resolution. On slow GPUs, resolution drops only while animating and comes back to full as soon as motion settles.
- Text is DOM. Labels are pooled HTML nodes moved with
transformonly, so they stay sharp at any DPR and thin out automatically when crowded.
Why it is crisp
Grid lines, bar edges and contours are computed per pixel with fwidth(), so they keep a constant
on-screen width at any zoom. Spheres are analytic and anti-aliased with alpha-to-coverage. The
background gradient is dithered against banding.
Architecture
src/
core/ math, gl helpers, camera, controls, stage (canvas/loop/picking), easing, color, ticks, force layout
render/ shared GLSL, background, frame box (walls + grid), sphere impostors, screen-space lines
ui/ overlay (header, legend, tooltip, hint), labels, injected styles
theme/ theme data + resolver
charts/ base.ts (Chart3D) + bar, scatter, surface, ribbon, donut, networkThe walls use an inside-out box: front faces are culled, so the GPU always draws the floor and the two walls behind the data, whatever the camera angle, with no per-angle logic.
Adding a chart type
Extend Chart3D<TData, TDatum, TOptions> and implement five hooks, then call this.mount(data) at
the end of the constructor:
| Hook | Responsibility |
| --- | --- |
| createResources(gl) | Programs and buffers (re-run after context loss) |
| computeLayout(data) | World bounds, grid spacing, ticks and legend (no GL). Optional: frame ('box' \| 'floor' \| 'none'), custom labels, and a focus sphere for camera framing |
| upload(mode, prevProgress) | Write instance data; for 'morph', start from the on-screen state |
| draw(state) | Draw calls; when state.pick is set, output hgEncodeId(id) instead of color |
| describe(index) | Datum and tooltip content for a picked id |
The base class handles camera, input, picking, highlight easing, labels, theming, resize, DPR, visibility and WebGL context loss and restore.
Development
npm run dev # demo at http://localhost:5173
npm test # unit tests (math, easing, ticks, color, themes, force layout, squarify)
npm run typecheck
npm run build # dist/ (ESM + UMD + .d.ts)
npm run build:demo # static demo site in demo-dist/Requires WebGL2, which all current browsers support (Chrome, Edge, Firefox, Safari 15+). Where it is missing, the container shows a short message instead.
MIT
