CamoSparkline
Concept
1. Why
A sparkline is a small trend line inside a sentence, a row or a card: the last 30 days next to a number, a row's activity (Apple's small charts, Fluent's tiles, Carbon's mini charts). It has no axes, no grid and no legend, and it must still be readable by a screen reader.
2. Shape
Split of duties
| Sparkline | Style |
|---|---|
| the scale (min and max or a given range), drawing the line, area or bars, the highlight on the last or the extreme points, the generated summary | line width, area opacity, bar radius, the palette color, the highlight marker |
Other libraries' mapping: Apple's inline charts, Carbon's mini charts, Fluent's tile trends.
3. API
Contract
fun CamoSparkline(
values: List<Double?>,
kind: SparklineKind = Line, // Line | Area | Bars
modifier: Modifier = Modifier, // the size: the chart fills it
range: ClosedFloatingPointRange<Double>? = null, // null: from the data
highlight: SparklineHighlight = Last, // None | Last | Extremes
tone: Tone = Default, // the series color family
description: String? = null, // names it ("Signups, last 30 days")
)
Summary: when description is null the sparkline announces "Trend from 3 to 9, up 200%" (first to last value and the change); with a description: "Signups, last 30 days: from 3 to 9, up 200%". It is a single image node, not focusable.
Tokens used
- the tone's family (
strong) for the line,containerfor the area ChartStyle.lineWidth,areaOpacity,barRadius,markerSize
Chart style
ChartStyle fields this chart reads (see Chart Frame for how the style is resolved: theme-derived defaults, the skin's preset, ChartTokens, then this chart's parameters).
| Field | Type | Default | What it's for |
|---|---|---|---|
lineWidth | Dp | 2 | the line |
areaOpacity | Float | 0.18 | the area form |
barRadius / barGap | Dp | 2 / 2 | the bars form |
markerSize | Dp | 5 | the highlight |
Accessibility
- One image node with the generated summary (or the description plus it); it is not interactive and not focusable.
- The trend direction is in the text, never only in the color.
4. Build steps
SparklineKind, the scale, drawing, the summary function (pure), the style reads.- Tests: the summary (up, down, flat, gaps), the scale with a given range, one value, all equal.
Done when
- The dashboard's tiles show their trends and read aloud as text.
sparklineSummary,downsample,sparklinePoints, segments and extremes are public pure functions with their own tests.- A single value draws a dot; an isolated point between gaps draws a dot too.
- Size: 100 x 28 when the parent gives no constraint, otherwise what it gives (a
layoutfallback in Compose,CustomPaint.sizein Flutter). - The draw-in is a clip that grows from the start edge over
motion.durationLong; it is skipped when the duration is zero (reduced motion) orChartStyle.animateis off.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Case | Decided behavior |
| --- | --- |
| One value | A dot (no line). |
Gaps (null) | The line breaks; bars skip. |
| All equal | A flat line in the middle. |
| Hundreds of points | Downsampled to the pixel width (min and max per bucket) so peaks stay. |
- Reference band (a normal range behind the line) is later.
Implementation
1. Why
A sparkline is one Canvas with Modifier.semantics; no axes, no text, so it needs no TextMeasurer.
2. Shape
3. API
@Composable public fun CamoSparkline(values: List<Double?>, modifier: Modifier = Modifier, kind: SparklineKind = SparklineKind.Line,
range: ClosedFloatingPointRange<Double>? = null, highlight: SparklineHighlight = SparklineHighlight.Last,
tone: Tone = Tone.Default, description: String? = null)
internal fun sparklineSummary(values: List<Double?>, description: String?): String // pure, tested alone
4. Build steps
- Scale, drawing, summary, style reads.
- Tests: the summary, the scale, downsampling.
Done when
- Works by touch, mouse, keyboard and screen reader.
style: ChartStyle?parameter added for per-chart overrides.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Size | Defaults to 100 x 28 dp when the caller gives none. |
- None specific.