Pantrix UI

Area Chart

An area chart of rows that are given once: for each of the values read from them a line, with the room between it and nought filled.

import com.pantrixui.components.chart.area.PantrixAreaChart

Examples

A single amount

A single amount over the months: the line goes through smoothly and the room under it is filled, its colour fading towards zero. The value axis starts at zero by itself; its values are written short (format).

A chart of one series has no legend: what the line is belongs to the words around the chart.

val strings = PantrixTheme.strings
PantrixAreaChart(
    data = STORAGE,
    x = { it.month },
    values = listOf(ChartValue("used", "Space used") { it.used }),
    curve = ChartCurve.Smooth,
    yAxis = ChartAxis(format = { "${strings.decimal(it)} GB" }),
    description = "Storage space used by month",
    tagKey = "plain"
)

private data class Storage(
    val month: String,
    val used: Int,
    val backups: Int
)

private val STORAGE = listOf(
    Storage("Jan", used = 120, backups = 40),
    Storage("Feb", used = 138, backups = 46),
    Storage("Mar", used = 151, backups = 52),
    Storage("Apr", used = 149, backups = 61),
    Storage("May", used = 176, backups = 64),
    Storage("Jun", used = 203, backups = 72),
    Storage("Jul", used = 221, backups = 85),
    Storage("Aug", used = 214, backups = 91),
    Storage("Sep", used = 252, backups = 96),
    Storage("Oct", used = 281, backups = 110),
    Storage("Nov", used = 305, backups = 124),
    Storage("Dec", used = 342, backups = 131)
)

Two amounts, two fills

Two amounts, the larger given first. With Gradient each area fades from its line towards zero, and the area underneath shows through the one above; with Solid the fill is an even tint. Turn the switch and compare the two.

var solid by remember { mutableStateOf(false) }
PantrixSwitchButton(
    checked = solid,
    onCheckedChange = { solid = it },
    label = "Solid fill",
    tagKey = "area_solid"
)
PantrixAreaChart(
    data = STORAGE,
    x = { it.month },
    values = listOf(
        ChartValue("used", "Space used") { it.used },
        ChartValue("backups", "Backups") { it.backups }
    ),
    curve = ChartCurve.Smooth,
    fill = if (solid) ChartFill.Solid else ChartFill.Gradient,
    description = "Space used and backups by month",
    tagKey = "fills"
)

private data class Storage(
    val month: String,
    val used: Int,
    val backups: Int
)

private val STORAGE = listOf(
    Storage("Jan", used = 120, backups = 40),
    Storage("Feb", used = 138, backups = 46),
    Storage("Mar", used = 151, backups = 52),
    Storage("Apr", used = 149, backups = 61),
    Storage("May", used = 176, backups = 64),
    Storage("Jun", used = 203, backups = 72),
    Storage("Jul", used = 221, backups = 85),
    Storage("Aug", used = 214, backups = 91),
    Storage("Sep", used = 252, backups = 96),
    Storage("Oct", used = 281, backups = 110),
    Storage("Nov", used = 305, backups = 124),
    Storage("Dec", used = 342, backups = 131)
)

Values that go below zero

Values on both sides of zero: a month's profit or loss. An area always fills towards zero: downwards in profit, upwards in loss. A line is drawn at zero, and the fading fill is strongest at the farthest point on either side of zero.

val strings = PantrixTheme.strings
PantrixAreaChart(
    data = PROFIT,
    x = { it.first },
    values = listOf(ChartValue("profit", "Profit") { it.second }),
    yAxis = ChartAxis(format = { strings.compact(it) }),
    description = "Profit and loss by month",
    tagKey = "below_zero"
)

private val PROFIT = listOf(
    "Jan" to 84_000,
    "Feb" to 52_000,
    "Mar" to 21_000,
    "Apr" to -18_000,
    "May" to -46_000,
    "Jun" to -31_000,
    "Jul" to 9_000,
    "Aug" to 38_000,
    "Sep" to 67_000,
    "Oct" to 95_000,
    "Nov" to 112_000,
    "Dec" to 140_000
)

A stepped area

A value that holds until it changes: a warehouse's stock. StepAfter carries each value level until the next, and the fill fills the room under the steps.

PantrixAreaChart(
    data = STOCK,
    x = { it.first },
    values = listOf(ChartValue("stock", "Stock") { it.second }),
    curve = ChartCurve.StepAfter,
    fill = ChartFill.Solid,
    description = "Stock in the warehouse by week",
    tagKey = "stepped"
)

private val STOCK = listOf(
    "Week 1" to 480,
    "Week 2" to 480,
    "Week 3" to 310,
    "Week 4" to 310,
    "Week 5" to 640,
    "Week 6" to 520,
    "Week 7" to 520,
    "Week 8" to 270
)

Stacked areas

The parts of a whole: visits from three sources, stacked (stacked). Each area starts at the line of the one under it, and the topmost line is all the visits. The fill is a flat tint: so it reads where each area of the stack ends. The tooltip writes the month's total after the sources.

Turn the switch: each month counts as a hundred percent (stacking = ChartStacking.Percent). The areas are now the sources' shares and the axis writes percentages; the tooltip adds each value's share beside it.

Press a name in the legend: the source goes, and the ones over it come down into its place.

var shares by remember { mutableStateOf(false) }
PantrixSwitchButton(
    checked = shares,
    onCheckedChange = { shares = it },
    label = "As shares",
    tagKey = "area_shares"
)
PantrixAreaChart(
    data = SOURCES,
    x = { it.month },
    values = listOf(
        ChartValue("search", "Search") { it.search },
        ChartValue("direct", "Direct") { it.direct },
        ChartValue("social", "Social") { it.social }
    ),
    fill = ChartFill.Solid,
    stacked = true,
    stacking = if (shares) ChartStacking.Percent else ChartStacking.Normal,
    description = "Visits from three sources by month, stacked",
    tagKey = "stacked"
)

private data class Sources(
    val month: String,
    val search: Int,
    val direct: Int,
    val social: Int
)

private val SOURCES = listOf(
    Sources("Jan", search = 420, direct = 240, social = 130),
    Sources("Feb", search = 480, direct = 260, social = 120),
    Sources("Mar", search = 455, direct = 300, social = 165),
    Sources("Apr", search = 530, direct = 280, social = 190),
    Sources("May", search = 510, direct = 330, social = 240),
    Sources("Jun", search = 560, direct = 310, social = 285)
)

API

data

An area chart of rows that are given once: for each of the values read from them a line, with the room between it and nought filled.

ParameterTypeDefaultWhat it is
dataList<T>the rows, in the order the lines go through them.
x(T) -> Anywhere a row stands along the chart: a name, a day, anything that is equal to itself.
valuesList<ChartValue<T>>the series: what each reads from a row, and how it is called and drawn.
modifierModifierModifierthe chart's modifier. A height here is the chart's, the legend's with it.
curveChartCurveChartCurve.Linearhow each line goes from a point to the next.
fillChartFillChartFill.Gradientwhat the room under each line is filled with: its colour fading down to nought, or a tint of it.
missingChartMissingChartMissing.Gapwhat a line does at a row that has no value.
stackedBooleanfalsewhether each area stands on the one before it, in the order of values, and not on nought.
stackingChartStackingChartStacking.Normalhow the stacked areas stand on one another: as their values, or as their shares of the stack. Areas that are not stacked have no stack for it to go by.
labelsChartDataLabels?nullthe values written over the points of every line, where they have room. null writes none.
xAxisChartAxis?ChartAxis()the axis of the places, under the chart. null draws nothing of it.
yAxisChartAxis?ChartAxis()the axis of the values, beside the chart. null draws nothing of it.
secondYAxisChartAxis?ChartAxis()the second axis of the values, at the chart's other side: drawn where a value is read by it (ChartValue.axis), and not otherwise. null draws nothing of it.
marksList<ChartMark>emptyList()the lines and the bands drawn in the plot besides the series: a target, a limit, a stretch of places.
legendChartLegend?ChartLegend()where the names of the series stand. null shows none.
tooltipChartTooltip?ChartTooltip()what is shown for the place that is pointed at. null shows none.
zoomChartZoom?nullwhat lets the reader look closer at a part of the places and move along the rest. null, which it is unless the chart is given one, shows all the places and no more.
decimationChartDecimation?ChartDecimation()how a line with more points in view than the plot has room for is drawn through fewer of them. null draws every point, as many as there are.
exportChartExport?nullwhat lets the reader take the chart out of the app as a file: a picture, or a drawing that is sharp at any size. null, which it is unless the chart is given one, and the chart has no such button.
empty(@Composable () -> Unit)?nullwhat the chart shows in its plot while it has no value to draw, in the place of the theme's words for it ("No data"), which a screen reader is then not told either. null writes the words. A file the chart is exported as says them.
stateChartStaterememberChartState()what the reader has hidden and what they point at: the chart's own where none is given.
descriptionString?nullwhat the chart shows, in a few words, for a screen reader.
onSelect((ChartPoint) -> Unit)?nullcalled with the value that is pressed.
styleChartStyle?nullthis chart's own geometry.
colorsChartColors?nullthis chart's own colours, where they are not the theme's.
tagKeyString?nullthe chart's automation key. The chart is tagged as the PantrixChart it is, Chart_<tagKey>, and its parts and events are that chart's.

ChartStyle

A chart's geometry: how tall it is where nothing says, how thick its lines and how large its marks are, and the room between its parts; and whether its fills have textures besides their colours.

ParameterTypeDefaultWhat it is
heightDpDp.UnspecifiedHow tall a chart's plot is, with its axes, where the chart's modifier gives it no height. A legend above or under the plot adds its own.
lineWidthDpDp.UnspecifiedThe width of a series' line.
markerSizeDpDp.UnspecifiedThe width and height of the mark on a point.
selectedMarkerSizeDpDp.UnspecifiedThe same of the mark on the point that is pointed at.
gridWidthDpDp.UnspecifiedThe width of the grid's lines, of the lines along the axes and of the line that marks the place pointed at. Zero draws none.
labelGapDpDp.UnspecifiedBetween the plot and what is written beside it and under it, and between that and an axis' title.
tickSpacingDpDp.UnspecifiedThe least room between two values marked along the axis of values: what decides how many are marked where the axis does not say.
legendGapDpDp.UnspecifiedBetween the legend and the chart it stands beside.
legendItemGapDpDp.UnspecifiedBetween one entry of the legend and the next.
swatchSizeDpDp.UnspecifiedHow wide the sample of a series is in the legend and in the tooltip: a short run of its line, or a patch of its fill.
swatchGapDpDp.UnspecifiedBetween that sample and the name after it.
tooltipShapeShapeSpecShapeSpec.UnspecifiedThe tooltip's corners: a step of the brand's shape scale, or a fixed shape.
tooltipHorizontalPaddingDpDp.UnspecifiedBetween the tooltip's sides and what it holds.
tooltipVerticalPaddingDpDp.UnspecifiedBetween its top and bottom and what it holds, and between its heading and rows.
tooltipGapDpDp.UnspecifiedBetween the place pointed at and the tooltip beside it.
tooltipElevationDpDp.UnspecifiedThe tooltip's shadow.
barGapDpDp.UnspecifiedBetween two bars that stand side by side at a place. Bars too thin for it stand closer.
barMaxWidthDpDp.UnspecifiedThe widest a bar is, however much room its place has: a chart of three places is not three slabs.
barRadiusDpDp.UnspecifiedHow round the corners of a bar's end are, the end away from nought.
sliceGapDpDp.UnspecifiedBetween two slices of a pie that lie side by side, the same from the pie's middle to its rim.
selectedSliceOffsetDpDp.UnspecifiedHow far the slice of a pie that is pointed at stands out past the pie's rim. The pie keeps this much room about itself, so that the slice has where to stand.
gaugeWidthDpDp.UnspecifiedHow thick the arc of a gauge is. An arc is no thicker than half its radius.
meterHeightDpDp.UnspecifiedHow tall the bar of a meter group is.
trackerHeightDpDp.UnspecifiedHow tall the blocks of a status tracker are.
bubbleMinSizeDpDp.UnspecifiedHow far across the smallest bubble of a scatter chart is: a point whose size is nothing, or too little to be seen as an area, is still a point.
bubbleMaxSizeDpDp.UnspecifiedHow far across its largest bubble is: the one whose size is the most of the chart's.
navigatorHeightDpDp.UnspecifiedHow tall the strip under a chart's plot is, on which the part of the chart that is in view is marked and moved, in a chart whose zoom has one: how wide, beside a plot whose places go down its side.
barBandShareFloatFloat.NaNHow much of a place's band its bars take, more than nought and one at the most: the rest is the room between one place's bars and the next's. Bars are no wider than barMaxWidth all the same.
markLineWidthDpDp.UnspecifiedThe width of a mark's line: a target, a limit, a day. Zero draws none, and the mark's words are written all the same.
markBandAlphaFloatFloat.NaNHow much of its colour a mark's band is drawn in, from nought to one: a band lies behind the series, and is a tint.
patternsBoolean?nullWhether the fills of a chart's series, slices and tiles are drawn with textures besides their colours, and its lines broken in turn (ChartPattern): what tells them apart for a reader who cannot tell the colours apart. Left out, as the system is set: on where it is set to tell things apart without colour, iOS's "Differentiate Without Color" and Android's colour correction, and off otherwise.
nodeWidthDpDp.UnspecifiedHow wide a node of a sankey is.
nodeGapDpDp.UnspecifiedBetween two nodes of a column of a sankey.

ChartColors

What a chart is painted with, for a chart that does not take the theme's colours: a colour that is set is used, and one that is left out stays the theme's.

ParameterTypeDefaultWhat it is
seriesList<Color>emptyList()The colours the series are drawn in, in the order they are handed out, for the series that name none of their own. Empty, they are the theme's chart colours.
gridColorColor.UnspecifiedThe lines drawn across the chart at the marks of an axis. The theme's divider.
axisColorColor.UnspecifiedThe line along an axis. The theme's border.
labelColorColor.UnspecifiedWhat is written beside the axes: the values, the places and the axes' titles, and the names in the legend. The theme's textSecondary.
crosshairColorColor.UnspecifiedThe line that marks the place pointed at. The theme's borderHover: stronger than the grid it crosses, and quieter than the series it stands behind.
tooltipContainerColorColor.UnspecifiedThe tooltip's fill. The theme's surface.
tooltipBorderColorColor.UnspecifiedThe tooltip's edge. The theme's border.
tooltipTextColorColor.UnspecifiedThe tooltip's heading and its values. The theme's textPrimary.
tooltipLabelColorColor.UnspecifiedThe names of the series in the tooltip. The theme's textSecondary.
risingColorColor.UnspecifiedWhat a value that goes up is drawn in: a step of a waterfall that adds. The theme's success.
fallingColorColor.UnspecifiedWhat a value that goes down is drawn in: a step of a waterfall that takes away. The theme's danger.