Pantrix UI

Funnel Chart

A funnel: the stages of something that fewer and fewer get through, one under another, each as wide as the number that reached it. It shows where the others were lost: the visitors who signed up, the sign-ups who tried, the trials who paid.

import com.pantrixui.components.chart.funnel.PantrixFunnelChart

Examples

From a visit to a payment

At its plainest: the stages, given in their order. Each stage has a key, a name and a value.

Move the pointer over a stage's row, or touch the stage: the stage is ringed and the tooltip writes its value, with its share of the first stage.

PantrixFunnelChart(
    stages = FUNNEL_STEPS,
    description = "The stages a visit goes through until it comes to a payment",
    tagKey = "plain"
)

private val FUNNEL_STEPS = listOf(
    FunnelStage("visits", "Visits", 3000),
    FunnelStage("signups", "Sign-ups", 1240),
    FunnelStage("trials", "Trials", 520),
    FunnelStage("paid", "Paid", 310)
)

Shape and direction

The stages' shape and direction. "Bars" draws each stage as a bar as wide as its value (shape = FunnelShape.Bars); turn the switch: the stages stand side by side (horizontal = true), each as tall as its value. The arrows on the keyboard then go right and left.

var shape by remember { mutableStateOf(FunnelShape.Funnel) }
var horizontal by remember { mutableStateOf(false) }
PantrixSegmentButton(
    options = FUNNEL_SHAPES,
    selected = shape,
    onSelect = { shape = it },
    fullWidth = false,
    tagKey = "funnel_shape"
)
PantrixSwitchButton(
    checked = horizontal,
    onCheckedChange = { horizontal = it },
    label = "Horizontal",
    tagKey = "funnel_horizontal"
)
PantrixFunnelChart(
    stages = FUNNEL_STEPS,
    shape = shape,
    horizontal = horizontal,
    description = "The stages a visit goes through until it comes to a payment",
    tagKey = "shape"
)

private val FUNNEL_STEPS = listOf(
    FunnelStage("visits", "Visits", 3000),
    FunnelStage("signups", "Sign-ups", 1240),
    FunnelStage("trials", "Trials", 520),
    FunnelStage("paid", "Paid", 310)
)

private val FUNNEL_SHAPES = listOf(
    SegmentOption(value = FunnelShape.Funnel, label = "Funnel", tagKey = "funnel"),
    SegmentOption(value = FunnelShape.Bars, label = "Bars", tagKey = "bars")
)

Conversion rates

Conversion rates (rate). "Of the first" writes each stage's share of the first stage, "Of the previous" how many of those who reached the stage before went on to this one, "Both" the two together. On the stage the shares stand bare, two of them apart by a dot; the tooltip and a screen reader say what each share is of.

var rate by remember { mutableStateOf(FunnelRate.Previous) }
PantrixSegmentButton(
    options = FUNNEL_RATES,
    selected = rate,
    onSelect = { rate = it },
    fullWidth = false,
    tagKey = "funnel_rate"
)
PantrixFunnelChart(
    stages = FUNNEL_STEPS,
    rate = rate,
    description = "The stages of a visit up to a payment, with conversion rates",
    tagKey = "rates"
)

private val FUNNEL_STEPS = listOf(
    FunnelStage("visits", "Visits", 3000),
    FunnelStage("signups", "Sign-ups", 1240),
    FunnelStage("trials", "Trials", 520),
    FunnelStage("paid", "Paid", 310)
)

private val FUNNEL_RATES = listOf(
    SegmentOption(value = FunnelRate.First, label = "Of the first", tagKey = "first"),
    SegmentOption(value = FunnelRate.Previous, label = "Of the previous", tagKey = "previous"),
    SegmentOption(value = FunnelRate.Both, label = "Both", tagKey = "both")
)

Values written short

Large numbers are written short (the format of ChartDataLabels): they leave room in the stages. Turn the switch: the words go away (labels = null) and the values stay in the tooltip and for the screen reader alone.

var written by remember { mutableStateOf(true) }
val strings = PantrixTheme.strings
PantrixSwitchButton(
    checked = written,
    onCheckedChange = { written = it },
    label = "Words",
    tagKey = "funnel_labels"
)
PantrixFunnelChart(
    stages = CAMPAIGN_STEPS,
    labels = if (written) ChartDataLabels(format = { strings.compact(it) }) else null,
    description = "The stages of a campaign, from being shown to a sale",
    tagKey = "labels"
)

private val CAMPAIGN_STEPS = listOf(
    FunnelStage("shown", "Shown", 1_250_000),
    FunnelStage("clicks", "Clicks", 410_000),
    FunnelStage("carts", "Carts", 96_000),
    FunnelStage("orders", "Orders", 38_500),
    FunnelStage("repeat", "Bought again", 9_200)
)

Pressing a stage

A press is handed the stage: its key is in its series, its name in its name, its value in its value, and what the chart writes in its text. Press a stage: the line below writes what was pressed.

var pressed by remember { mutableStateOf<String?>(null) }
PantrixFunnelChart(
    stages = FUNNEL_STEPS,
    onSelect = { pressed = "${it.name}: ${it.text}" },
    description = "The stages a visit goes through until it comes to a payment",
    tagKey = "press"
)
PantrixText(text = pressed ?: "Press a stage")

private val FUNNEL_STEPS = listOf(
    FunnelStage("visits", "Visits", 3000),
    FunnelStage("signups", "Sign-ups", 1240),
    FunnelStage("trials", "Trials", 520),
    FunnelStage("paid", "Paid", 310)
)

A stage that widens

A stage can be larger than the one before it: more people called than leads that came in. The chart changes neither the order nor the number; that stage widens instead of narrowing, and its share goes over a hundred per cent.

The last stage is too narrow for its words, so its name and its value stand beside it.

PantrixFunnelChart(
    stages = listOf(
        FunnelStage("leads", "Leads", 800),
        FunnelStage("calls", "Calls", 950),
        FunnelStage("offers", "Offers", 300),
        FunnelStage("won", "Sales", 40)
    ),
    description = "From a lead to a sale: more calls than leads",
    tagKey = "widening"
)

Your own colours

The stages' own colours: a role of the theme, lighter from stage to stage. Each FunnelStage carries its own colour; a stage given none takes the chart colour of its place.

val tone = PantrixTheme.colors.primary.color
PantrixFunnelChart(
    stages = FUNNEL_STEPS.mapIndexed { place, stage ->
        FunnelStage(stage.key, stage.name, stage.value, tone.copy(alpha = 1f - place * 0.2f))
    },
    description = "The stages a visit goes through until it comes to a payment, in one colour",
    tagKey = "own_colors"
)

private val FUNNEL_STEPS = listOf(
    FunnelStage("visits", "Visits", 3000),
    FunnelStage("signups", "Sign-ups", 1240),
    FunnelStage("trials", "Trials", 520),
    FunnelStage("paid", "Paid", 310)
)

Export

export = ChartExport(...) puts an export button over the chart: press it and choose the kind (PNG, SVG or PDF). The chart makes the file and hands it to onExport; below, its name and size show, and a PNG's picture, and "Save the file" hands it over in the platform's way.

The file has the stages, their values and their rates.

var file by remember { mutableStateOf<ChartExportFile?>(null) }
PantrixFunnelChart(
    stages = FUNNEL_STEPS,
    description = "The stages a visit goes through until it comes to a payment",
    tagKey = "exported",
    export = ChartExport(fileName = "visit-to-payment") { file = it }
)
ExportedFile(file, tagKey = "exported")

private val FUNNEL_STEPS = listOf(
    FunnelStage("visits", "Visits", 3000),
    FunnelStage("signups", "Sign-ups", 1240),
    FunnelStage("trials", "Trials", 520),
    FunnelStage("paid", "Paid", 310)
)

API

stages

A funnel: the stages of something that fewer and fewer get through, one under another, each as wide as the number that reached it. It shows where the others were lost: the visitors who signed up, the sign-ups who tried, the trials who paid.

ParameterTypeDefaultWhat it is
stagesList<FunnelStage>the stages, in the order they follow one another. Their keys tell them apart, and two with one key are refused.
modifierModifierModifierthe chart's modifier. A height here is the chart's.
labelsChartDataLabels?ChartDataLabels()what is written at the stages: each stage's name and its value, written as format says or in the theme's language where it says nothing, with its shares. null writes nothing at them.
tooltipChartTooltip?ChartTooltip()what is shown for the stage that is pointed at: its name and its value with its shares. With both shares the value stands alone on the stage's row and each share on a row of its own under it, which a tooltip of the caller's own is handed as a point of the stage named by the share, with the share as its value and no text. A stage has no place to share and no line through it: shared and crosshair are not read. null shows none.
empty(@Composable () -> Unit)?nullwhat the chart shows 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.
stateChartStaterememberChartState()what the reader points at: the chart's own where none is given.
descriptionString?nullwhat the chart shows, in a few words, for a screen reader: the first thing it says of the chart. Left out, the chart is announced by the names of its stages.
onSelect((ChartPoint) -> Unit)?nullcalled with the stage that is pressed: its key is its series and its x, its name its name and its label, and its text its value with its shares after it.
styleChartStyle?nullthis chart's own geometry: the fields set here, with the theme's for the rest. Two stages are a sliceGap apart.
colorsChartColors?nullthis chart's own colours, where they are not the theme's.
tagKeyString?nullthe chart's automation key: the chart is Funnel_<tagKey>, its stages together Funnel_<tagKey>.Plot, a stage Funnel_<tagKey>.Stage_<number>, counted from one, and the tooltip Funnel_<tagKey>.Tooltip. A press on a stage is reported as a Funnel select event with the stage's key. Nothing of the values is reported.
shapeFunnelShapeFunnelShape.Funnelhow the stages are drawn: as one funnel, or as bars.
horizontalBooleanfalsewhether the stages stand side by side, from where lines start, and not one under another.
rateFunnelRateFunnelRate.Firstwhich shares a stage's value is written with: of the first stage, of the stage before it, or both. At a stage they stand in brackets after the value, two of them apart by a dot; to a tooltip and a screen reader one of the stage before it, and each of two, says which it is (PantrixStrings.shareOfFirst and shareOfPrevious).
exportChartExport?nullwhat lets the reader take the chart out of the app as a PNG, an SVG or a PDF: a button over the chart makes the file of it as it is and hands it over (see ChartExport). null, the chart has no such button.

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.

Accessibility