Skip to main content

CamoLineChart

Concept​

1. Why​

A line chart shows how one or more values change across an ordered axis: sales per month, latency per minute (Swift Charts' line and area marks, Carbon's line and area charts). It covers three forms: line, area and stacked area.

2. Shape​

Split of duties

FrameLine chart
scales, ticks, axes, grid, legend, tooltip, keyboard, data table, animationthe line paths (linear, smooth, step), the areas and their stacking, the markers, nearest-x hit testing, the crosshair

Other libraries' mapping: Swift Charts line and area marks, Carbon line, area and stacked area charts, Fluent's chart tokens.

3. API​

Contract​

fun CamoLineChart(
categories: List<String>, // the x labels
series: List<ChartSeries>,
modifier: Modifier = Modifier,
kind: LineKind = Line, // Line | Area | StackedArea
curve: LineCurve = Linear, // Linear | Smooth | Step
markers: MarkerVisibility = OnHover, // Always | OnHover | Never
xAxis: ChartAxis = ChartAxis(), yAxis: ChartAxis = ChartAxis(),
title: String, loading: Boolean = false, empty: Slot? = null,
showTable: Boolean = false,
)

Tooltip: the nearest category lists each visible series' value with its color; with StackedArea it adds the total. Legend: toggles series (a hidden series leaves the stack and the scale recomputes).

Tokens used​

  • the frame's tokens; ChartStyle.lineWidth, areaOpacity, markerSize, curveTension

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
lineWidthDp2
areaOpacityFloat0.18Area and StackedArea
curveTensionFloat0.4the Smooth curve
markerSizeDp6
gridLinesBooleanhorizontal

Accessibility​

  • The frame's summary plus, per point, "Jan, Sales, 42" (keyboard traversal); StackedArea also announces the total.
  • A data table is one press away (showTable), with the series as columns and the categories as rows.
  • Lines also differ by dash or marker shape when patterns is on, never by color alone.

4. Build steps​

  1. Line geometry (linear, smooth by monotone cubic, step), the stacking function, hit testing.
  2. CamoLineChart on the frame, the Minimal and Fluent presets.
  3. Tests: stacking sums, smoothing never overshoots (monotone), nearest-x, gaps, hidden series, the summary.

Done when

  • The dashboard's revenue chart switches between line, area and stacked area, reads as a table and follows the skin.
Changed in the M11 build (2026-11-03)
  • times (epoch milliseconds, ascending) and timeZoneOffsetMinutes place the categories on a time axis with calendar ticks (minute to ten years, weeks start on Monday, quarters and years on round starts); there is no time library, the app passes the zone as a UTC offset. Unsorted times fall back to even spacing. The time axis keeps its direction in right-to-left layouts.
  • xAxis.title and yAxis.title are drawn (value title above the plot at the start edge, category title below the labels).
  • ChartStyle.curveTension was not built: monotone cubic and Catmull-Rom need no tension. LineCurve has Linear, Smooth, CatmullRom and Step.

5. Edge cases​

CaseDecided behavior
CaseDecided behavior
------
null valuesThe line breaks; areas close at the gap.
One categoryMarkers only.
Many categoriesTick labels thin out to fit; the tooltip still lists the nearest.
Stacked negative valuesStacked areas treat negatives as zero and say so in the docs (use lines).
Decided in review (2026-11-03)
  • A time axis is in M11: ChartAxis gets a time scale (ticks at nice calendar steps: minutes, hours, days, months), used by the line chart (batch 2). Zoom, pan and brush selection stay later.
  • Smoothing: monotone cubic and Catmull-Rom both ship (LineCurve.Smooth and LineCurve.CatmullRom).
  • The default palette is not color-blind-safe; a safe palette is a ChartStyle.palette away.
  • Smoothing: monotone cubic only (no overshoot); say if you want Catmull-Rom as well.
  • Dual y axes are later.

Implementation​

1. Why​

One Canvas draws grid, axes, areas, lines and markers from the frame's scales; hit testing is the nearest x among the categories.

2. Shape​

3. API​

@Composable public fun CamoLineChart(categories: List<String>, series: List<ChartSeries>, title: String, modifier: Modifier = Modifier,
kind: LineKind = LineKind.Line, curve: LineCurve = LineCurve.Linear, markers: MarkerVisibility = MarkerVisibility.OnHover,
xAxis: ChartAxis = ChartAxis(), yAxis: ChartAxis = ChartAxis(), loading: Boolean = false, empty: (@Composable () -> Unit)? = null,
showTable: Boolean = false)
internal fun stack(series: List<List<Double?>>): List<List<Pair<Double, Double>>> // pure
internal fun monotonePath(points: List<Offset>): Path

4. Build steps​

  1. Geometry, stacking, the canvas, interaction.
  2. Tests: stacking, monotone smoothing, hit testing, summary.

Done when

  • Works by touch, mouse, keyboard and screen reader.
Changed in the M11 build (2026-11-03)
  • times (epoch milliseconds, ascending) and timeZoneOffsetMinutes place the categories on a time axis with calendar ticks (minute to ten years, weeks start on Monday, quarters and years on round starts); there is no time library, the app passes the zone as a UTC offset. Unsorted times fall back to even spacing. The time axis keeps its direction in right-to-left layouts.
  • xAxis.title and yAxis.title are drawn (value title above the plot at the start edge, category title below the labels).
  • ChartStyle.curveTension was not built: monotone cubic and Catmull-Rom need no tension. LineCurve has Linear, Smooth, CatmullRom and Step.
  • A hidden series leaves a stacked area's stack and the scale recomputes; stacked areas treat negatives as zero; a gap in one series leaves the others' stack intact.
  • The tooltip, crosshair and keyboard walk (Left and Right between categories, Up and Down between series, Home and End) announce "Jan, Sales, 42"; plotHeight and style parameters added.
  • CamoLineChart and CamoBarChart take plotHeight: Dp; ChartRenderer gained drawLineChart and drawBarChart with default implementations, so a custom renderer overrides only the marks it wants.

5. Edge cases​

CaseDecided behavior
RecompositionThe paths are rebuilt only when data, size or visibility changes (remember keys), not per animation frame.
  • None specific.