PlSparkline
A chart with everything taken away except the shape. No axes, no grid, no legend, no tooltip, a word-sized picture that goes inside a sentence and says which way something has been going.
import { PlSparkline } from 'plass-ui';
<PlSparkline data={signups} endDot />;import 'package:plass_ui/plass_ui.dart';
PlSparkline(data: signups, endDot: true);A sparkline is a different thing from a chart shrunk down. Every number it could label is one the surrounding text already has, which is why it labels none of them. Put it beside a PlStat, in a table cell, or in a line of prose.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| data * | readonly PlassChartDatum[] | — | The values. A null is a gap here too |
| shape | 'line' | 'area' | 'bar' | 'line' | Which mark. A line for a trend, an area for a quantity, bars for a count of discrete things |
| curve | 'linear' | 'smooth' | 'step' | 'linear' | How the line gets from one point to the next |
| color | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | (string & {}) | '--plass-chart-1' | The mark's colour, taken directly: one series and no legend, so there is nothing for a palette to hand out |
| endDot | boolean | false | Puts a dot on the last point that is a point — the one direct label a strip this small has room for |
| baseline | number | — | A rule across the strip: a target or a budget, the one piece of context a sparkline can carry |
| min | number | — | The bottom of the scale. Left out, the strip fills itself with its own range |
| max | number | — | And the top of it. Give a row of strips the same pair and they become small multiples |
| width | number | string | '100%' | How wide |
| label | string | — | A name for the strip. Without one it is taken off the accessibility tree entirely |
| sizeshared | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | How tall the strip is, sized against the line of text it sits beside rather than the page |
| Prop | Type | Default | Description |
|---|---|---|---|
| data * | List<PlassChartDatum> | — | The values. A null is a gap here too |
| shape | PlSparklineShape | PlSparklineShape.line | Which mark. A line for a trend, an area for a quantity, bars for a count of discrete things |
| curve | PlChartCurve | PlChartCurve.linear | How the line gets from one point to the next |
| color | PlassColor? | '--plass-chart-1' | The mark's colour family. An exact colour goes to tint instead |
| tint | Color? | — | An exact colour, the other half of React's PlassColor | (string & {}) — Dart has no union |
| endDot | bool | false | Puts a dot on the last point that is a point — the one direct label a strip this small has room for |
| baseline | double? | — | A rule across the strip: a target or a budget, the one piece of context a sparkline can carry |
| min | double? | — | The bottom of the scale. Left out, the strip fills itself with its own range |
| max | double? | — | And the top of it. Give a row of strips the same pair and they become small multiples |
| width | double? | '100%' | How wide |
| semanticLabel | String? | — | A name for the strip. Without one it is taken off the accessibility tree entirely |
| sizeshared | PlassSize | PlassSize.md | How tall the strip is, sized against the line of text it sits beside rather than the page |
Unlike the full charts this one takes its colour directly. A sparkline has exactly one series and no legend, so there is nothing for a palette to hand out.
There is no tooltip and no legend, and adding either would make it a chart. A null is a gap here as everywhere, and the line breaks at it.
Examples
shape
The same three sentences the full charts say, at a size where nothing else is being said at all. A line for a trend, an area for a quantity, bars for a count of discrete things.
min and max
A sparkline scales itself to its own range, so the strip is always full. That is what makes it readable at twenty pixels tall, and it is also the trap: two of them side by side are drawn on two different scales, so a strip that climbs steeply may be the smaller number. Give a row of them the same min and max and they become a small-multiples chart instead.
baseline
A target, a budget, last year's average. The one piece of context a strip this small can carry. It is pulled into the range if it sits outside the data, so the rule is always visible.
endDot
Puts a dot on the last point that is actually a point, not on the last slot. It is the one direct label a strip this small has room for, and it says where the series ended up. Bars do not take it: a bar already ends where it ends.
Accessibility
- Without a
labelthe strip is taken off the accessibility tree entirely. A sparkline is decoration beside text that already carries the numbers, and an unlabelled image announced as an image is noise. - With a
labelit becomes a namedrole="img", and the values are written out beside it, clipped from view, never hidden from the tree. What a sparkline has to give a screen reader is the numbers, not a description of the shape they make. - Colour is never the only channel here either: a sparkline sits beside the name and the number it belongs to.