Skip to main content

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

FrameBar chart
scales, axes, grid, legend, tooltip, keyboard, data table, animationthe 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).

FieldTypeDefaultWhat it's for
barRadiusDp4the free end of a bar (stacked: only the top segment)
barGapDp4between bars in a group
groupGapFloat0.3space between groups, as a share of a group
valueLabelStyletext stylelabelSmallvalueLabels

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 valueLabels is on, so values never rely on reading the axis.

4. Build steps​

  1. Geometry (grouping, stacking, negatives), orientation, the canvas, interaction.
  2. CamoBarChart on the frame, the presets.
  3. 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.
Changed in the M11 build (2026-11-03)
  • yAxis is always the value axis and xAxis the 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​

CaseDecided behavior
CaseDecided behavior
------
Many categoriesHorizontal bars are the advice; vertical labels rotate or thin out.
Zero valueA zero-height bar (still focusable, still announced).
Mixed signs when stackedPositives stack up, negatives down, separately.
RTLVertical 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​

  1. barRects, the canvas, interaction.
  2. Tests: barRects for every mode and orientation and RTL, hit testing, summary.

Done when

  • Works by touch, mouse, keyboard and screen reader.
Changed in the M11 build (2026-11-03)
  • yAxis is always the value axis and xAxis the 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"); plotHeight and style parameters added.

5. Edge cases​

CaseDecided behavior
Hit testingThe rect list from barRects is reused for drawing and for the pointer.
  • None specific.