Sparkline #
A Sparkline renders a series of values as a small inline SVG line graph, designed for comparable small multiples.
import Sparkline from '@fuzdev/fuz_ui/Sparkline.svelte'; <Sparkline values={[3, 5, 2, 8, 6, 9, 4, 7, 5, 10, 8, 12]} /> With a shared max #
By default each sparkline stretches its own max to full height. Pass a shared max so a set of sparklines renders at the same vertical scale and stays visually comparable:
<Sparkline values={a} max={12} />
<Sparkline values={b} max={12} /> Individually scaled (misleading — the second series peaks at 3):
Shared scale:
With a nonlinear scale #
Under a large shared max, low-activity series hug the baseline. Set scale to compress the top of the range so small values stay legible — increasingly so from "sqrt" to a power exponent (a number in (0, 1], where 1 is linear) to "log". The alpha fade still tracks the linear ratio, so it keeps encoding true
magnitude:
<Sparkline values={b} max={12} scale="sqrt" />
<Sparkline values={b} max={12} scale={1 / 3} />
<Sparkline values={b} max={12} scale="log" /> linear, sqrt, cube root, log
With custom color #
The stroke uses currentColor, so set color on the component or a parent: (see the fuz_css colors docs)
<span class="color_b_50"><Sparkline values={a} /></span>
With alpha scaling #
Each point's stroke alpha scales with its value, from alpha_floor at 0 (default
0.4) up to 1 at max, de-emphasizing quiet stretches. Set alpha_floor to 1 to disable the fade:
<Sparkline values={b} alpha_floor={1} /> default fade, no fade
Project commit activity #
The dataset behind ProjectLinks: monthly commit counts per project
from project_stats_data.ts, derived with project_stats_to_monthly_series so every project shares one time
window and one scale, rendered with a cube-root scale.
- fuz_app
- fuz_css
- fuz_ui
- fuz_template
- fuz_blog
- fuz_code
- fuz_mastodon
- fuz_gitops
- svelte-docinfo
- fuz_util
- gro
- tsv
ProjectActivityChart draws every project's weekly series over one another at a shared scale, built on the same geometry via sparkline.ts — hover a line for the project's stats: