Skip to content

⚠ 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

Bars, pies and part-to-whole

Charts from @sophistry/charts that compare amounts or split a whole: bars in every layout, histograms, and the part-to-whole marks. Start with BarChartReveal, then GroupedAndStackedBars for series and layouts.

Bar chart reveal

A bar chart whose bars grow in as draw() drives its progress.

BarChartReveal.tsx
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 default function BarChartReveal() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 1.5 }));
});
return (
<Stage units={10}>
<BarChart
data={[3, 7, 4, 9, 6]}
label={(_, i) => "abcde"[i]}
yRange={[0, 10, 2]}
width={8}
height={4}
progress={progress}
/>
</Stage>
);
}

Horizontal bars

<Bars> on a categorical y axis: names laid out top-down, bars growing from zero one after another, values counting up. Hover a bar.

HorizontalBars.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Bars, Chart } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const langs = [
{ name: "TypeScript", share: 38 },
{ name: "Python", share: 31 },
{ name: "Rust", share: 14 },
{ name: "Go", share: 11 },
{ name: "Zig", share: 3 },
];
export default function HorizontalBars() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2 }));
});
return (
<Stage units={12}>
<Chart
width={7}
height={4.5}
center={{ x: 0.6, y: 0 }}
xAxis={{ tickFormat: (v) => `${v}%` }}
grid="x"
progress={shown}
>
<Bars
data={langs}
category="name"
value="share"
orientation="horizontal"
labels={(d) => `${d.share}%`}
stagger={0.5}
tooltip
/>
</Chart>
</Stage>
);
}

Grouped and stacked bars

One long-format table, two layouts of one bar mark: series colours the regions through the chart's scale and legend, the dodge layout puts them side by side in each quarter, the stack layout piles them up. The stack grows as one, so every frame is a true stacked chart.

GroupedAndStackedBars.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, Text, usePlayer } from "@sophistry/solidjs";
import { Bars, Chart } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const sales = ["Q1", "Q2", "Q3", "Q4"].flatMap((quarter, q) =>
["north", "south", "east"].map((region, r) => ({
quarter,
region,
units: [
[4, 6, 5, 8],
[3, 3, 4, 5],
[2, 4, 3, 4],
][r][q],
})),
);
const palette = ["#4c78a8", "#f58518", "#54a24b"];
export default function GroupedAndStackedBars() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2.5 }));
});
return (
<Stage units={16}>
<Chart
width={6}
height={4}
center={{ x: -4, y: 0 }}
grid="y"
color={{ range: palette }}
legend="top"
progress={shown}
>
<Bars
data={sales}
category="quarter"
value="units"
series="region"
layout="dodge"
stagger={0.4}
/>
</Chart>
<Chart
width={6}
height={4}
center={{ x: 4, y: 0 }}
grid="y"
color={{ range: palette }}
legend="top"
progress={shown}
>
<Bars
data={sales}
category="quarter"
value="units"
series="region"
layout="stack"
/>
</Chart>
<Text text="dodge" x={-4} y={-3.2} fontSize={0.4} />
<Text text="stack" x={4} y={-3.2} fontSize={0.4} />
</Stage>
);
}

Value labels in stacked bars

labels={{ position: "inside", total: true }} centres each segment's value in it, in whichever of dark and light text reads on its fill, and writes each stack's total past its end. Labels count up and grow in with their segments; one too small for its segment (the 1 in Q2) is left out.

StackedBarLabels.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Bars, Chart } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const sales = ["Q1", "Q2", "Q3", "Q4"].flatMap((quarter, q) =>
["north", "south", "east"].map((region, r) => ({
quarter,
region,
units: [
[4, 6, 5, 8],
[3, 1, 4, 5],
[2, 4, 3, 4],
][r][q],
})),
);
export default function StackedBarLabels() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2.5 }));
});
return (
<Stage units={12}>
<Chart
width={8}
height={4.5}
grid="y"
color={{ range: ["#1f3b73", "#f58518", "#c9e3b2"] }}
legend="top"
progress={shown}
>
<Bars
data={sales}
category="quarter"
value="units"
series="region"
layout="stack"
labels={{ position: "inside", total: true }}
stagger={0.4}
/>
</Chart>
</Stage>
);
}

Diverging stacked bars

A Likert chart from long-format rows: series="answer" with layout="stack" sends negative values down from zero and positive values up, so disagreement and agreement grow apart from one centre line, and the chart's colour scale gives the legend in answer order. The question axis stands at the left edge, clear of the bars, and a zero line marks the baseline they grow from.

DivergingBars.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Bars, Chart } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const answers = ["strongly disagree", "disagree", "agree", "strongly agree"];
const sign = [-1, -1, 1, 1];
const survey = [
{ q: "Clear docs", counts: [4, 10, 38, 22] },
{ q: "Fast builds", counts: [12, 20, 25, 9] },
{ q: "Easy setup", counts: [6, 14, 30, 18] },
].flatMap(({ q, counts }) =>
counts.map((n, a) => ({ q, answer: answers[a], share: sign[a] * n })),
);
const palette = ["#ca0020", "#f4a582", "#92c5de", "#0571b0"];
export default function DivergingBars() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2 }));
});
return (
<Stage units={12}>
<Chart
// "contain": width × height holds everything — the question
// names on the left, the numbers below, the legend on top — so
// the chart is simply centred on the stage.
width={10.4}
height={4.8}
autosize="contain"
xRange={[-40, 60, 20]}
xAxis={{ tickFormat: (v) => `${Math.abs(v)}` }}
// The question axis is a band axis, so it stands at the left
// edge (not at zero, mid-chart), and the frame draws a zero
// line for the bars to grow from. The domain pins the legend
// to answer order and the range gives the diverging colours.
color={{ domain: answers, range: palette }}
legend="top"
progress={shown}
>
<Bars
data={survey}
category="q"
value="share"
series="answer"
orientation="horizontal"
// Inner answers first, so each side stacks outward from zero.
layout="stack"
order={["disagree", "strongly disagree", "agree", "strongly agree"]}
tooltip={(d) => `${d.answer}: ${Math.abs(d.share)}`}
/>
</Chart>
</Stage>
);
}

Histogram bins

The same 120 samples regrouped into more and more bins, from coarse to fine.

HistogramBins.tsx
4 collapsed lines
import { derive, track, valueTo } from "@sophistry/core";
import { Axes, Stage, Text, usePlayer } from "@sophistry/solidjs";
import { Histogram } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
// 120 bell-shaped samples in [0, 6]: each is the sum of six uniform numbers from a tiny generator.
let seed = 7;
const uniform = () => {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
};
const samples = Array.from({ length: 120 }, () =>
Array.from({ length: 6 }, uniform).reduce((a, b) => a + b),
);
export default function HistogramBins() {
const { play } = usePlayer();
const bins = track(4);
onSettled(() => {
void play(valueTo(bins, 20, { duration: 4 }));
});
return (
<Stage units={14}>
<Axes xRange={[0, 6, 1]} yRange={[0, 70, 10]} width={10} height={5}>
<Histogram
data={samples}
binCount={derive(bins, Math.round)}
range={[0, 6]}
/>
</Axes>
<Text
text={derive(bins, (value) => `${Math.round(value)} bins`)}
y={3.5}
/>
</Stage>
);
}

Waterfall

How a starting figure became a final one: each change grows from where the last left off.

WaterfallSteps.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Waterfall } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const quarter = [
{ name: "Q1 start", change: 120 },
{ name: "Sales", change: 64 },
{ name: "Services", change: 22 },
{ name: "Refunds", change: -18 },
{ name: "Salaries", change: -71 },
{ name: "Rent", change: -24 },
{ name: "Q1 end", change: 0, total: true },
];
export default function WaterfallSteps() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 3.5 }));
});
return (
<Stage units={13}>
<Waterfall
data={quarter}
value="change"
label="name"
total={(d) => d.total === true}
width={10}
height={4.5}
progress={shown}
tooltip
/>
</Stage>
);
}

Bullet chart

Stephen Few's bullet graph: four KPIs against their targets over poor / fair / good bands, each on its own scale. The bands fade in first, then each bar grows from zero and its target marker draws in.

BulletChart.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Bullet } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const kpis = [
{ name: "Revenue ($k)", actual: 270, goal: 250, bands: [150, 225, 300] },
{ name: "Profit (%)", actual: 22.5, goal: 27, bands: [20, 25, 30] },
{ name: "Order size ($)", actual: 320, goal: 550, bands: [350, 500, 600] },
{ name: "Satisfaction", actual: 4.3, goal: 4.5, bands: [3.5, 4.25, 5] },
];
export default function BulletChart() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 2.5 }));
});
return (
<Stage units={12}>
<Bullet
data={kpis}
value="actual"
target="goal"
ranges="bands"
label="name"
width={10.5}
height={5}
progress={progress}
tooltip
/>
</Stage>
);
}

Funnel

Stages of a process, top-down: each widens out from the centre, the loss between them shaded.

FunnelStages.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Funnel } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const signups = [
{ step: "Visited", n: 12000 },
{ step: "Signed up", n: 4800 },
{ step: "Activated", n: 2600 },
{ step: "Subscribed", n: 900 },
];
export default function FunnelStages() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2.5 }));
});
return (
<Stage units={12}>
<Funnel
data={signups}
value="n"
label="step"
width={7}
height={4.5}
center={{ x: 0.8, y: 0 }}
progress={shown}
tooltip
/>
</Stage>
);
}

Waffle chart

A 10 × 10 waffle where each cell is one percent, filling from the bottom-left like a container. Counts use largest-remainder rounding, so they always add up to 100.

Waffle.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Waffle } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const commute = [
{ mode: "Bike", share: 41.6 },
{ mode: "Bus", share: 30.1 },
{ mode: "Car", share: 18.9 },
{ mode: "Walk", share: 9.4 },
];
export default function WaffleExample() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 2.5 }));
});
return (
<Stage units={10}>
<Waffle
data={commute}
value="share"
label="mode"
width={4}
height={4}
center={{ x: 0, y: 0.5 }}
legend
progress={progress}
tooltip
/>
</Stage>
);
}

Mosaic (Marimekko) chart

Sales by region × product: each column is as wide as its region's share of the market, split by product mix, so every tile's area is its sales. Region names fade in first, then the columns grow left to right.

MosaicShares.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Mosaic } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const regions = {
Americas: [42, 30, 18],
Europe: [25, 28, 12],
Asia: [20, 14, 26],
};
const products = ["Phones", "Laptops", "Tablets"];
const sales = Object.entries(regions).flatMap(([region, units]) =>
units.map((n, k) => ({ region, product: products[k], units: n })),
);
export default function MosaicShares() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 2.5 }));
});
return (
<Stage units={10}>
<Mosaic
data={sales}
x="region"
y="product"
value="units"
width={8}
height={4}
center={{ x: 0, y: 0.4 }}
shares
progress={progress}
tooltip
/>
</Stage>
);
}

Pie and radar charts

A doughnut chart and a two-series radar chart, both built from plain data and revealed together: the doughnut's slices open together from 12 o'clock, each pushed round by the ones before, while the radar's polygons grow out of the centre. ariaLabel gives each slice an accessible name.

PieAndRadar.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, Text, usePlayer } from "@sophistry/solidjs";
import { PieChart, RadarChart } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const share = [
{ name: "Solid", pct: 42 },
{ name: "Svelte", pct: 23 },
{ name: "Vue", pct: 20 },
{ name: "Other", pct: 15 },
];
const skills = [
{ who: "Ada", scores: [8, 5, 7, 9, 6] },
{ who: "Grace", scores: [6, 9, 5, 7, 8] },
];
export default function PieAndRadar() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 2 }));
});
return (
<Stage units={14}>
<PieChart
data={share}
value="pct"
label="name"
ariaLabel="Framework share"
center={{ x: -3.6, y: 0.2 }}
radius={2.2}
innerRadius={1}
progress={progress}
/>
<RadarChart
data={skills}
axisValues="scores"
axisLabels={["Speed", "Craft", "Docs", "Tests", "Design"]}
maxValue={10}
center={{ x: 3.6, y: 0.2 }}
radius={2.2}
progress={progress}
/>
<Text text="doughnut" x={-3.6} y={-3.1} fontSize={0.4} />
<Text text="radar, two series" x={3.6} y={-3.1} fontSize={0.4} />
</Stage>
);
}

KPI gauge and radial bars

A gauge with threshold bands and a needle, beside activity rings. Each draws its track first, then sweeps clockwise while the readout counts up.

Gauge.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Gauge, RadialBarChart } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const rings = [
{ goal: "Move", pct: 82 },
{ goal: "Exercise", pct: 64 },
{ goal: "Stand", pct: 45 },
];
export default function GaugeExample() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 2.5 }));
});
return (
<Stage units={12}>
<Gauge
value={72.4}
unit="%"
label="CPU load"
bands={[
{ to: 60, color: "#83c167" },
{ to: 85, color: "#f0ac5f" },
{ to: 100, color: "#fc6255" },
]}
needle
center={{ x: -2.8, y: 0 }}
radius={2.2}
progress={progress}
tooltip
/>
<RadialBarChart
data={rings}
value="pct"
label="goal"
maxValue={100}
center={{ x: 2.8, y: 0 }}
radius={2.2}
progress={progress}
tooltip
/>
</Stage>
);
}