CamoBarChart
Concept
1. Why
A bar chart compares values across categories: revenue by region, tickets by status (Swift Charts' bar marks, Carbon's bar charts). It covers vertical and horizontal bars, grouped (side by side) and stacked.
2. Shape
Split of duties
| Frame | Bar chart |
|---|---|
| scales, axes, grid, legend, tooltip, keyboard, data table, animation | the bar geometry (group width, gaps, stacking, negatives), orientation, value labels, per-bar hit testing |
Other libraries' mapping: Swift Charts bar marks, Carbon simple, grouped and stacked bar charts.
3. API
Contract
fun CamoBarChart(
categories: List<String>,
series: List<ChartSeries>,
modifier: Modifier = Modifier,
orientation: BarOrientation = Vertical, // Vertical | Horizontal
mode: BarMode = Grouped, // Grouped | Stacked
valueLabels: Boolean = false,
xAxis: ChartAxis = ChartAxis(), yAxis: ChartAxis = ChartAxis(),
title: String, loading: Boolean = false, empty: Slot? = null, showTable: Boolean = false,
)
Tooltip: the hovered bar's series and value (and for Stacked the total of its category). Bars grow from the baseline with the draw-in; negative bars go the other way from zero.
Tokens used
- the frame's tokens;
ChartStyle.barRadius,barGap,groupGap
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 |
|---|---|---|---|
barRadius | Dp | 4 | the free end of a bar (stacked: only the top segment) |
barGap | Dp | 4 | between bars in a group |
groupGap | Float | 0.3 | space between groups, as a share of a group |
valueLabelStyle | text style | labelSmall | valueLabels |
Accessibility
- The frame's summary; per bar "Q1, North, 42" in keyboard traversal (Left and Right between categories, Up and Down between series).
- The data table fallback has the same shape as the chart.
- Bars carry value labels when
valueLabelsis on, so values never rely on reading the axis.
4. Build steps
- Geometry (grouping, stacking, negatives), orientation, the canvas, interaction.
CamoBarCharton the frame, the presets.- Tests: group and stack geometry, negatives, horizontal mirror (including RTL), hit testing, hidden series, the summary.
Done when
- The dashboard's regional bars switch between grouped and stacked and between vertical and horizontal.
yAxisis always the value axis andxAxisthe category axis, whichever way the bars run; their titles are drawn.- The bar under the pointer is the one whose column (row, when horizontal) is nearest across the category axis, so the pointer above a short bar still finds it. Value labels sit at the free end; a stack shows its side's total there and draws them after the draw-in.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Case | Decided behavior |
| --- | --- |
| Many categories | Horizontal bars are the advice; vertical labels rotate or thin out. |
| Zero value | A zero-height bar (still focusable, still announced). |
| Mixed signs when stacked | Positives stack up, negatives down, separately. |
| RTL | Vertical bars run from the right; horizontal bars start at the right edge. |
- Bar labels inside the bar (for wide bars) are later; labels sit at the end.
Implementation
1. Why
One Canvas draws the bars; the geometry is pure (barRects) so grouping, stacking and negatives are tested without a window.
2. Shape
3. API
@Composable public fun CamoBarChart(categories: List<String>, series: List<ChartSeries>, title: String, modifier: Modifier = Modifier,
orientation: BarOrientation = BarOrientation.Vertical, mode: BarMode = BarMode.Grouped, valueLabels: Boolean = false,
xAxis: ChartAxis = ChartAxis(), yAxis: ChartAxis = ChartAxis(), loading: Boolean = false, empty: (@Composable () -> Unit)? = null,
showTable: Boolean = false)
internal fun barRects(plot: Rect, categories: Int, series: List<List<Double?>>, mode: BarMode, orientation: BarOrientation,
style: ChartStyle, rtl: Boolean): List<BarRect> // pure
4. Build steps
barRects, the canvas, interaction.- Tests:
barRectsfor every mode and orientation and RTL, hit testing, summary.
Done when
- Works by touch, mouse, keyboard and screen reader.
yAxisis always the value axis andxAxisthe category axis, whichever way the bars run; their titles are drawn.- The bar under the pointer is the one whose column (row, when horizontal) is nearest across the category axis, so the pointer above a short bar still finds it. Value labels sit at the free end; a stack shows its side's total there and draws them after the draw-in.
- Bars mirror in right-to-left layouts (vertical bars run from the right, horizontal bars start at the right edge); the radius goes on the free end only (a stack's outermost segment).
- Keyboard walk and announcement as in the line chart ("Q1, North, 42");
plotHeightandstyleparameters added.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Hit testing | The rect list from barRects is reused for drawing and for the pointer. |
- None specific.