⚠ Early release: v0.3.2.sophistry is not ready for production use. Until 1.0, any minor release may break the API; expect missing features and bugs too.Stability and versioning
Chart animation
A chart is a function of its props, and props can be tracks, so there are three ways to animate one: reveal it, transition its data, or move its domain. Each is a pure function of a number, so it scrubs, seeks and plays backwards like any other animation. A fourth, for live data, lets the marks tween on the clock when data is replaced (below).
Reveals
Section titled “Reveals”Every chart takes progress (0 to 1). Pass a track and drive it with draw():
4 collapsed lines
import { draw, track } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { BarChart } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
export function Reveal() { const progress = track(0); const player = usePlayer(); onSettled(() => { void player.play(draw(progress, { duration: 1.5 })); }); return ( <Stage units={10}> <BarChart data={[3, 7, 4, 9]} width={8} height={4} progress={progress} /> </Stage> );}A <Chart>’s progress draws the frame first (grid, axes, titles), then the layers, then the legend: the order a person draws a chart in. One track on the <Chart> is usually all you need; a layer’s own progress is scaled into the frame’s data half.
Each kind of mark reveals the way that reads honestly:
| Mark | Reveals by | reveal options |
|---|---|---|
LinePlot, Stairs, Ecdf, FillBetween |
a front sweeping along x at a constant rate | "length" cuts each line by arc length |
Density, Regression |
a clip sweeping along x | Density: "grow" rises from the baseline |
Bars, BarChart, Histogram, Stem |
growing out of the baseline (fading in when the axis has no zero) | "stack", "fade" |
StackPlot, stacked Bars |
every band growing together, so each frame is a true stack | "x", "length" |
Scatter, Strip, Beeswarm |
markers growing in place | |
ErrorBar, RuleX, RuleY |
bars reaching out of their marker; rules drawn from their low end | |
PieChart, RadarChart |
slices or polygons growing out from the centre | "sweep" wipes round from 12 o’clock |
Imshow, Cells, Heatmap, Hist2D, HexBin |
cells fading in reading order, never by value | |
Contour, ContourF |
lines cut along their length; filled bands fading in, lowest first | |
BoxPlot, ViolinPlot |
boxes opening from the median, then whiskers, then outliers fading in; violins widening from the centre line | |
Hierarchies, Tree, Sankey |
nodes staggered in from the root outwards (Sankey: column by column); tree links and Sankey ribbons cut along their length |
Batched items carry per-item geometry and opacity, but no per-item arc-length progress. So a mark that would trace an outline instead has its geometry cut (lines, contour lines, links, ribbons), grows (markers, bars, wedges), or fades in (filled contour bands, box-plot outliers). Every reveal ends on exactly the finished chart.
- One front.
<Chart reveal="x">sweeps one clip edge across the whole plot instead, so a band, its line and its markers enter together. - Stagger.
stagger(0 to 0.95) is the fraction of the reveal spent bringing marks in one after another, in the encoded order (along x, by category, by value). The last mark always finishes atprogress = 1.staggerOrder="random"uses a hash of each key instead: shuffled-looking, but the same on every frame.
Keep draw() linear for curves, so the sweep keeps pace with x.
One reveal front
reveal="x" sweeps a single clip edge across the plot, so the band, the line and its markers enter together, at a constant rate along x.
9 collapsed lines
import { draw, track } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Chart, FillBetween, LinePlot, Scatter,} from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const runs = [3.1, 4.2, 3.8, 5.6, 6.1, 5.4, 7.2, 7.9, 7.1, 8.6].map((y, x) => ({ x, y, lo: y - 0.8, hi: y + 0.8,}));
export default function SweepReveal() { const { play } = usePlayer(); const progress = track(0); onSettled(() => { void play(draw(progress, { duration: 3 })); });
return ( <Stage units={12}> <Chart width={9} height={4.5} grid="y" reveal="x" progress={progress}> <FillBetween data={runs} x="x" y1="lo" y2="hi" /> <LinePlot data={runs} x="x" y="y" /> <Scatter data={runs} x="x" y="y" radius={0.07} /> </Chart> </Stage> );}Data transitions
Section titled “Data transitions”Pass a derive of a track as data and the chart redraws as it changes. When both datasets have the same items in the same order, blending the arrays is enough:
const blend = track(0);const data = derive(blend, (t) => before.map((v, i) => v + (after[i] - v) * t));// <BarChart data={data} ... />, then player.play(valueTo(blend, 1))Morphing chart data
Charts redraw from their data, so animating the data animates the chart: one blend track mixes two datasets and every bar follows.
4 collapsed lines
import { derive, hold, sequence, track, valueTo } from "@sophistry/core";import { Stage, Text, usePlayer } from "@sophistry/solidjs";import { BarChart } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const before = [3, 7, 4, 9, 6];const after = [8, 2, 9, 3, 5];
export default function BarChartMorph() { const { play, signal } = usePlayer(); const blend = track(0); // The chart binds this derived array, so every change to `blend` redraws the bars. const data = derive(blend, (t) => before.map((v, i) => v + (after[i] - v) * t), );
onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( hold(0.8), valueTo(blend, 1, { duration: 1.5 }), hold(0.8), valueTo(blend, 0, { duration: 1.5 }), ), ); } })(); });
return ( <Stage units={10}> <BarChart data={data} label={(_, i) => "abcde"[i]} yRange={[0, 10, 2]} width={8} height={4} /> <Text text="same chart, new data" y={2.5} fontSize={0.4} /> </Stage> );}When items come and go, give the chart the far end as to and drive blend from 0 to 1:
const blend = track(0);<Chart clip> <Scatter data={before} to={after} blend={blend} key="city" x="income" y="life" /></Chart>;// then: player.play(valueTo(blend, 1, { duration: 2.4, easing: "linear" }))Items are matched by key (per-datum marks), by series (lines and areas), by category, slice, bin or node path (the rest). A matched item updates: it moves between its two values in data units, so every frame is a valid chart; lines morph on a shared x grid and stacks stay touching. An item only in to enters the way it reveals; an item only in data exits by its reveal run backwards. staging="staged" (the default) spends blend on exits, then updates, then entries, each eased on its own, so drive it linearly; staging="together" runs them at once, for stepping through keyframes (data={frames[k]} to={frames[k + 1]} blend={time - k}).
On a batched mark the join is the batch’s own: each key keeps its item from one end of the transition to the other, so a scatter of ten thousand points transitions as cheaply as one of ten.
enterStagger(0 to 0.95) brings entering items in one after another within the enter stage. Updates and exits never stagger: a staggered move is harder to follow.- The frame follows. Fitted axes, category names, the legend and the room it takes all blend on the same track, so
blend = 0is exactlydata’s chart andblend = 1exactlyto’s. Under reduced motion, a run started withusePlayer(orscene.play) jumps to its end, so the chart lands on the far frame. - Axes can change kind. Bars with
to={[]}leaving while points withdata={[]}arrive cross-fade a category axis into a number line, and marks that stay slide between their two drawings. - One clock per chart. Drive all of a chart’s layers from one
blendtrack; layers on separate schedules belong in separate charts. Pin<Chart color={{ domain }}>when series come and go, so colours stay put.
Keyed scatter update
One blend track joins two datasets by key: Lima shrinks away where it stood, the fitted y axis grows, matched cities move in data space, then Oslo grows in. Played forward, then scrubbed back.
5 collapsed lines
import { okabeIto } from "@sophistry/charts";import { hold, sequence, track, valueTo } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Chart, Scatter } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const before = [ { city: "Accra", region: "Africa", income: 2.1, life: 61 }, { city: "Dhaka", region: "Asia", income: 1.6, life: 70 }, { city: "Hanoi", region: "Asia", income: 3.4, life: 72 }, { city: "Lima", region: "Americas", income: 6.6, life: 74 }, { city: "Nairobi", region: "Africa", income: 2.0, life: 63 },];const after = [ { city: "Accra", region: "Africa", income: 4.4, life: 66 }, { city: "Dhaka", region: "Asia", income: 2.7, life: 73 }, { city: "Hanoi", region: "Asia", income: 8.3, life: 76 }, { city: "Nairobi", region: "Africa", income: 3.1, life: 67 }, { city: "Oslo", region: "Europe", income: 9.5, life: 83 },];
export default function KeyedScatter() { const { play, signal } = usePlayer(); const blend = track(0); onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( hold(0.6), // Staged transitions ease each stage themselves: drive them linearly. valueTo(blend, 1, { duration: 2.4, easing: "linear" }), hold(0.8), valueTo(blend, 0, { duration: 2.4, easing: "linear" }), ), ); } })(); });
return ( <Stage units={12}> <Chart width={10} height={4.4} clip grid xLabel="income" yLabel="life" color={{ range: okabeIto, domain: ["Africa", "Asia", "Americas", "Europe"], }} > <Scatter data={before} to={after} blend={blend} key="city" x="income" y="life" series="region" radius={0.14} /> </Chart> </Stage> );}Line morph in data space
Each line morphs on one shared x grid, so values move vertically and a line that gains data grows at its end; the old forecast fades out, the new series sweeps in, and the axes rescale with them.
4 collapsed lines
import { hold, sequence, track, valueTo } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Chart, LinePlot } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const wave = (n: number, f: (x: number) => number) => Array.from({ length: n }, (_, x) => f(x));const rows = (name: string, ys: number[]) => ys.map((y, month) => ({ name, month, y }));
const before = [ ...rows( "north", wave(7, (x) => 20 + 6 * Math.sin(x / 1.6)), ), ...rows( "south", wave(7, (x) => 12 + x * 1.5), ), ...rows( "forecast", wave(7, (x) => 16 + x), ),];const after = [ ...rows( "north", wave(11, (x) => 24 + 10 * Math.sin(x / 1.8)), ), ...rows( "south", wave(11, (x) => 10 + x * 2.6), ), ...rows( "east", wave(11, (x) => 30 - x * 1.4), ),];
export default function LineMorph() { const { play, signal } = usePlayer(); const blend = track(0); onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( hold(0.6), valueTo(blend, 1, { duration: 3, easing: "linear" }), hold(0.8), valueTo(blend, 0, { duration: 3, easing: "linear" }), ), ); } })(); });
return ( <Stage units={12}> <Chart width={10} height={4.4} clip grid="y" xLabel="month"> <LinePlot data={before} to={after} blend={blend} x="month" y="y" series="name" strokeWidth={0.05} /> </Chart> </Stage> );}Stacked area morph
Each end is stacked on its own and every band's two edges morph together on one shared x grid, so each frame is still a stack: a leaving band shrinks and the bands above settle onto it, a new one grows in its place.
4 collapsed lines
import { hold, sequence, track, valueTo } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Chart, StackPlot } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const rows = (source: string, f: (week: number) => number, weeks = 9) => Array.from({ length: weeks }, (_, week) => ({ source, week, gw: f(week) }));
const before = [ ...rows("coal", (w) => 14 - w * 0.8), ...rows("gas", (w) => 10 + 2 * Math.sin(w / 1.5)), ...rows("wind", (w) => 4 + w * 0.6),];const after = [ ...rows("gas", (w) => 8 + 1.5 * Math.cos(w / 2), 12), ...rows("wind", (w) => 7 + w * 0.9, 12), ...rows("solar", (w) => 3 + 4 * Math.sin(w / 3.5), 12),];
export default function StackMorph() { const { play, signal } = usePlayer(); const blend = track(0); onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( hold(0.6), valueTo(blend, 1, { duration: 3, easing: "linear" }), hold(0.8), valueTo(blend, 0, { duration: 3, easing: "linear" }), ), ); } })(); });
return ( <Stage units={12}> <Chart width={10} height={4.4} xLabel="week" yLabel="GW" // Weeks 0–11 fit 0–11, not 0–15: the axis stops at the data // rather than running most of a tick step past it. xAxis={{ nice: "tight" }} color={{ domain: ["coal", "gas", "wind", "solar"] }} > <StackPlot data={before} to={after} blend={blend} x="week" y="gw" series="source" /> </Chart> </Stage> );}Keyed pie morph
One blend track joins two years of browser share by name: IE's slice closes and its neighbours take the room, the shares change in data space, then Edge opens where the new year has it. Every frame is a whole pie.
4 collapsed lines
import { hold, sequence, track, valueTo } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { PieChart } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const before = [ { name: "Chrome", share: 45 }, { name: "IE", share: 25 }, { name: "Firefox", share: 20 }, { name: "Safari", share: 10 },];const after = [ { name: "Chrome", share: 64 }, { name: "Edge", share: 5 }, { name: "Firefox", share: 8 }, { name: "Safari", share: 19 },];
export default function KeyedPie() { const { play, signal } = usePlayer(); const blend = track(0); onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( hold(0.6), // Staged transitions ease each stage themselves: drive them linearly. valueTo(blend, 1, { duration: 2.4, easing: "linear" }), hold(0.8), valueTo(blend, 0, { duration: 2.4, easing: "linear" }), ), ); } })(); });
return ( <Stage units={11}> <PieChart data={before} to={after} blend={blend} value="share" label="name" radius={2.6} innerRadius={1.1} labelFontSize={0.26} /> </Stage> );}Bars into a scatter
One blend track turns a bar chart into a scatter plot: the bars shrink away, the category axis cross-fades into a number line, and the dots on the bars' tops slide to their new places in scene units while the y axis glides to the new axis's zero. Played forward, then back.
4 collapsed lines
import { hold, sequence, track, valueTo } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Bars, Chart, Scatter } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const countries = [ { name: "Chile", life: 79, growth: 2.4 }, { name: "Ghana", life: 64, growth: 5.1 }, { name: "India", life: 70, growth: 6.8 }, { name: "Italy", life: 83, growth: -1.6 }, { name: "Peru", life: 76, growth: 3.3 },];// The dots sit on the bars' tops (slot `i` is centred at `i + 0.5`), then// on a number line of GDP growth (%), which spans 0.const onBars = countries.map((c, i) => ({ name: c.name, x: i + 0.5, y: c.life,}));const spread = countries.map((c) => ({ name: c.name, x: c.growth, y: c.life }));
export default function BarsToScatter() { const { play, signal } = usePlayer(); const blend = track(0); onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( hold(0.8), valueTo(blend, 1, { duration: 2.6, easing: "linear" }), hold(1.2), valueTo(blend, 0, { duration: 2.6, easing: "linear" }), ), ); } })(); });
return ( <Stage units={12}> <Chart width={9.4} height={4.4} yLabel="life expectancy"> <Bars data={countries} to={[]} blend={blend} key="name" category="name" value="life" /> <Scatter data={onBars} to={spread} blend={blend} key="name" x="x" y="y" radius={0.13} /> </Chart> </Stage> );}Hierarchies (Treemap, Sunburst, Tree, …) take the same to and blend, matched by name path; see the catalogue.
Clock-driven updates
Section titled “Clock-driven updates”A to/blend transition is seekable, which suits a scripted scene. For data that simply changes (a live feed, a filter the user toggles), the per-datum marks (Scatter, Bars, Histogram, Strip, Beeswarm, Stem, Rug, TickX/TickY, RuleX/RuleY, Rects, ErrorBar, Cells, Hist2D, Pcolormesh) take transition: when data is replaced, kept items tween (or spring) to their new values on the scene’s clock, new items grow in and departing ones shrink out, matched by key.
<Scatter data={points} // a track or derive the app replaces key="id" x="x" y="y" transition={{ duration: 0.6, easing: "inOut", stagger: 0.2 }}/>transition takes duration and easing, or spring (an item retargeted mid-flight keeps its velocity), plus delay and stagger; enter and exit turn the grow-in and shrink-out off (false) or give them their own timing. Only data changes animate this way: a reveal, a to/blend transition or a range change stays exact. The first data a mark draws appears in place, for its reveal to bring in.
Domain transitions
Section titled “Domain transitions”To move a scale smoothly, give <Chart> a range transition instead of a range. As a derive of a track, it binds without any framework work per frame:
const zoom = track(0);const yRange = derive(zoom, (t) => ({ from: [0, 10] as [number, number], to: [0, 100] as [number, number], t }));<Chart clip yRange={yRange}>...</Chart>;The axis, grid and every layer map through the range blended at t, so marks and ticks never disagree. The blend happens in the scale’s own space (a log axis zooms geometrically), and ticks are matched by value: shared ticks slide, the rest fade. Pair it with clip, so what leaves the domain leaves the picture. When data changes too, rescale first if the domain grows and last if it shrinks; keyed transitions do this for you.
Animated axis rescale
One track drives the y domain and the data together, shared by the axis, the grid and the marks: the values grow tenfold as the axis rescales under them, so the points barely move while the numbers change. Ticks on both ends slide, the rest cross-fade, and labels that would crowd fade out as they close up.
4 collapsed lines
import { derive, hold, sequence, track, valueTo } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Chart, LinePlot, Scatter } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const before = [2, 6, 4, 8, 5];const after = [20, 65, 35, 90, 55];
export default function AxisRescale() { const { play, signal } = usePlayer(); const blend = track(0); // Data and domain on one track: they move together. const data = derive(blend, (t) => before.map((v, i) => v + (after[i] - v) * t), ); const yRange = derive(blend, (t) => ({ from: [0, 10] as [number, number], to: [0, 100] as [number, number], t, }));
onSettled(() => { void (async () => { while (!signal.aborted) { await play( sequence( hold(0.6), valueTo(blend, 1, { duration: 1.6 }), hold(0.6), valueTo(blend, 0, { duration: 1.6 }), ), ); } })(); });
return ( <Stage units={12}> <Chart width={9} height={4.5} clip grid="y" xRange={[0, 4, 1]} yRange={yRange} > <LinePlot data={data} /> <Scatter data={data} x={(_, i) => i} y={(d) => d} radius={0.08} /> </Chart> </Stage> );}Streaming is the same transition driven by one time track: each whole step slides the window by one, and t is the fraction of the current step.
const time = track(0);const xRange = derive(time, (t) => { const step = Math.floor(t); return { from: [step, step + 10] as [number, number], to: [step + 1, step + 11] as [number, number], t: t - step };});<Chart clip xRange={xRange}> <LinePlot data={data} x="x" y="y" /></Chart>;Streaming series
New samples arrive off-screen right and the x domain slides left under a clip; the leaving tick fades out. Everything is a function of one time track, so it scrubs.
4 collapsed lines
import { derive, track, valueTo } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Chart, LinePlot } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const WINDOW = 10;/** The same sample at the same x however the timeline is scrubbed. */const sample = (x: number) => 5 + 2 * Math.sin(x * 0.9) + Math.sin(x * 2.3);
export default function StreamingSeries() { const { play } = usePlayer(); const time = track(0); onSettled(() => { void play(valueTo(time, 40, { duration: 40, easing: "linear" })); });
// Whole steps change the data; the fraction slides the x domain. const step = derive(time, (t) => Math.floor(t)); // One sample past the right edge, so it slides in rather than popping. const data = derive(step, (step) => Array.from({ length: step + WINDOW + 2 }, (_, x) => ({ x, y: sample(x), })), ); const xRange = derive(time, (t) => { const step = Math.floor(t); return { from: [step, step + WINDOW] as [number, number], to: [step + 1, step + WINDOW + 1] as [number, number], t: t - step, }; });
return ( <Stage units={12}> <Chart width={9} height={4.5} clip grid="y" yRange={[0, 10]} xRange={xRange} > <LinePlot data={data} x="x" y="y" /> </Chart> </Stage> );}<Axes>, <NumberPlane> and <NumberLine> take the same { from, to, t } ranges; interpolateRange and transitionTicks in @sophistry/core/geometry are the pure functions underneath.
Sorting and races
Section titled “Sorting and races”A band axis’s slot option places each category at a slot index you choose, fractional included, and every band mark follows. Drive it from createSlots and a sort is one seekable permute:
const slots = createSlots(names, { layout: (i) => ({ x: i, y: 0 }), lag: 0.08 });// Rebuild the axis option whenever a slot moves.const xAxis = derive( names.flatMap((name) => slots.item(name)?.position ?? []), () => ({ slot: (key: string | number) => slots.item(String(key))?.position.peek().x }),);<Chart xAxis={xAxis}> <Bars data={fruit} category="name" value="sold" /></Chart>;// then: player.play(slots.plan().permute(sortedNames))Sorting bars with slots
A slots model owns the order; the chart's band axis reads each category's slot through `slot`, so bars and their names slide together. Each sort is one seekable `permute`, staggered.
4 collapsed lines
import { createSlots, derive, hold, sequence } from "@sophistry/core";import { Stage, usePlayer } from "@sophistry/solidjs";import { Bars, Chart } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const fruit = [ { name: "fig", sold: 4 }, { name: "kiwi", sold: 9 }, { name: "lime", sold: 2 }, { name: "pear", sold: 7 }, { name: "plum", sold: 5 }, { name: "yuzu", sold: 8 },];const names = fruit.map((d) => d.name);const bySales = [...fruit].sort((a, b) => b.sold - a.sold).map((d) => d.name);
export default function SortedBars() { const { play, signal } = usePlayer(); // Slot i laid out at x = i: the chart turns slots into band positions. const slots = createSlots(names, { layout: (i) => ({ x: i, y: 0 }), duration: 0.7, lag: 0.08, }); // The axis rebuilds whenever any slot position moves. const xAxis = derive( names.flatMap((name) => slots.item(name)?.position ?? []), () => ({ slot: (key: string | number) => slots.item(String(key))?.position.peek().x, }), ); onSettled(() => { void (async () => { while (!signal.aborted) { await play(sequence(hold(0.8), slots.plan().permute(bySales))); await play(sequence(hold(1.2), slots.plan().permute(names))); } })(); });
return ( <Stage units={10}> <Chart width={8} height={4} yLabel="sold" xAxis={xAxis}> <Bars data={fruit} category="name" value="sold" labels /> </Chart> </Stage> );}rankRace(rows, { key, time, value, top }) makes a bar chart race: it interpolates each key’s value over time, ranks by it, and slides each swap on its own short ease. race.view(time) gives the axis its categories and slots and the entries in view.
const race = rankRace(rows, { key: "name", time: "year", value: "score", top: 5 });const view = derive(year, (time) => race.view(time));const yAxis = derive(view, (frame) => ({ categories: frame.categories, slot: frame.slot }));const entries = derive(view, (frame) => frame.entries);<Chart clip color={{ domain: race.keys }} yAxis={yAxis}> <Bars data={entries} category="key" value="value" key="key" series="key" orientation="horizontal" /></Chart>;Bar chart race
Values interpolate between yearly keyframes, ranks come from the interpolated values, and each overtake slides on its own short ease. The category axis follows the ranks through its `slot`, so names ride with their bars, and only the top five are shown: whoever drops out slides under the last place and out of view.
5 collapsed lines
import { rankRace } from "@sophistry/charts";import { derive, track, valueTo } from "@sophistry/core";import { Stage, Text, usePlayer } from "@sophistry/solidjs";import { Bars, Chart } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const NAMES = ["Ada", "Basil", "Cleo", "Dara", "Esme", "Farid", "Greta"];const YEARS = Array.from({ length: 11 }, (_, k) => 2010 + k);const rows = NAMES.flatMap((name, i) => YEARS.map((year, k) => ({ name, year, score: Math.round( 20 + (i % 3) * 6 + k * (3 + i) + 9 * Math.sin(k * 0.8 + i * 1.7), ), })),);const race = rankRace(rows, { key: "name", time: "year", value: "score", swap: 0.35, top: 5,});const MAX = Math.max(...rows.map((d) => d.score));
export default function BarChartRace() { const { play } = usePlayer(); const year = track(YEARS[0]); onSettled(() => { // Playback through time is linear; the swaps ease on their own. void play(valueTo(year, 2020.4, { duration: 10.4, easing: "linear" })); }); // Five slots on the axis; entries past them slide out under the last. // They come and go, so the colours are pinned to every name below. const view = derive(year, (time) => race.view(time)); const yAxis = derive(view, (frame) => ({ categories: frame.categories, slot: frame.slot, })); const entries = derive(view, (frame) => frame.entries); const caption = derive(year, (time) => String(Math.min(2020, Math.floor(time))), );
return ( <Stage units={12}> <Chart width={9} height={4.6} center={{ x: -0.4, y: -0.2 }} clip grid="x" legend={false} color={{ domain: race.keys }} xRange={[0, Math.ceil(MAX / 20) * 20]} yAxis={yAxis} > <Bars data={entries} category="key" value="value" key="key" series="key" orientation="horizontal" labels={(d) => d.value.toFixed(0)} /> </Chart> <Text text={caption} x={3.6} y={-1.9} fontSize={0.9} opacity={0.5} /> </Stage> );}Time as an encoding
Section titled “Time as an encoding”Give Scatter long-format rows with a time channel and a moment at: it draws one marker per key at that moment, interpolated between the moments either side, and trail draws the path each has taken. The axes fit every moment, so they hold still while time plays. Pass a track as at and play valueTo on it.
Animated scatter with trails
Time as an encoding, Gapminder-style: one marker per country at the moment `at`, sized by population (area ∝ value, the `size` channel) and interpolated between decades, with a trail of the path it took. The axes fit every decade, so they hold still while time plays.
4 collapsed lines
import { derive, track, valueTo } from "@sophistry/core";import { Stage, Text, usePlayer } from "@sophistry/solidjs";import { Chart, Scatter } from "@sophistry/solidjs/charts";import { onSettled } from "solid-js";
const DECADES = [1960, 1970, 1980, 1990, 2000, 2010, 2020];const COUNTRIES = [ { name: "A", region: "Asia", income: 600, growth: 1.42, life: 42, pop: 9 }, { name: "B", region: "Asia", income: 900, growth: 1.25, life: 48, pop: 7 }, { name: "C", region: "Africa", income: 1100, growth: 1.1, life: 41, pop: 4 }, { name: "D", region: "Africa", income: 450, growth: 1.12, life: 36, pop: 3 }, { name: "E", region: "Europe", income: 9000, growth: 1.22, life: 69, pop: 2 }, { name: "F", region: "Americas", income: 4000, growth: 1.16, life: 58, pop: 5, },];const rows = COUNTRIES.flatMap((c) => DECADES.map((year, k) => ({ country: c.name, region: c.region, year, income: Math.round(c.income * c.growth ** k), life: Math.min( 84, c.life + k * (5.5 - c.life / 20) + 2 * Math.sin(k + c.pop), ), pop: c.pop * (1 + 0.25 * k), })),);
export default function AnimatedScatterTrails() { const { play } = usePlayer(); const year = track(DECADES[0]); onSettled(() => { void play(valueTo(year, 2020, { duration: 8, easing: "linear" })); });
return ( <Stage units={12}> <Chart width={10} height={4.6} center={{ x: 0, y: -0.2 }} grid xAxis={{ scale: "log", tickFormat: "$,.0f" }} xLabel="income" yLabel="life" > <Scatter data={rows} x="income" y="life" key="country" series="region" time="year" at={year} size="pop" sizeRange={[0.06, 0.32]} trail fillOpacity={0.85} /> </Chart> <Text text={derive(year, (time) => String(Math.floor(time)))} x={1.9} y={-1.8} fontSize={0.9} opacity={0.45} /> </Stage> );}Next steps
Section titled “Next steps”- Charts: data, channels, the frame and marks.
- Timelines and playback: seek and scrub these transitions.
- Chart transitions gallery: every transition here, running live.