Meter Group
A meter group: several amounts of one whole, side by side on one bar. What a storage is filled with, how a budget is spent: the parts are read against each other and against what is left.
import com.pantrixui.components.chart.metergroup.PantrixMeterGroup
- Values. A part's value is counted in what
maxis counted in. A part with no value, or one that is not over nought, takes none of the bar, and its name stays in the legend. What the parts come to pastmaxis cut off at the bar's end. - Legend. It writes each part's name, then its value, beside its colour. It stands above the bar or under it: a legend at the start counts as above, one at the end as under. Its entries are no switches here: the bar shows what it is given.
- Writing.
formatsays how a value is written in the legend; left out, it is written as a number in the theme's language. - Direction. In a language read from right to left the first part stands at the right.
- Export.
exportputs a button over the chart: the chart is made, as it is on the screen and without the part that is pointed at or its tooltip, into a PNG, an SVG or a PDF file and handed to the app. - Automation.
MeterGroup_<tagKey>; the bar.Bar, the legend's entries.Legend_<the part's key>.
Examples
What fills a whole
At its plainest: four things that fill a storage of sixty-four gigabytes. The end of the bar that is not filled shows the room that is left; the legend writes each part with its value.
PantrixMeterGroup(
items = METER_STORAGE,
max = 64,
format = { "${it.toInt()} GB" },
description = "Storage",
tagKey = "plain"
)
private val METER_STORAGE = listOf(
MeterItem("apps", "Apps", 16),
MeterItem("photos", "Photos", 24),
MeterItem("messages", "Messages", 8),
MeterItem("system", "System", 10)
)
The legend above
The legend is above the bar and at the start of the line (ChartLegend(position = Top, alignment = Start)). The values are written as shares of the whole, in the theme's language.
val strings = PantrixTheme.strings
PantrixMeterGroup(
items = METER_BUDGET,
format = { strings.percent(it / 100) },
legend = ChartLegend(position = ChartLegendPosition.Top, alignment = ChartLegendAlignment.Start),
description = "How the budget is spent",
tagKey = "legend_above"
)
private val METER_BUDGET = listOf(
MeterItem("rent", "Rent", 40),
MeterItem("food", "Food", 25),
MeterItem("transport", "Transport", 15),
MeterItem("savings", "Savings", 20)
)
The bar alone
A bar with no legend (legend = null): inside a row, where the words beside it already say what it shows. A screen reader hears the parts from the bar itself.
PantrixMeterGroup(
items = METER_STORAGE,
max = 64,
format = { "${it.toInt()} GB" },
legend = null,
description = "Storage",
tagKey = "bar_only"
)
private val METER_STORAGE = listOf(
MeterItem("apps", "Apps", 16),
MeterItem("photos", "Photos", 24),
MeterItem("messages", "Messages", 8),
MeterItem("system", "System", 10)
)
Your own colours and sizes
A bar's own look: each part names its own colour, the bar is thicker (meterHeight), its ends are square (barRadius) and there is no gap between the parts (sliceGap). A field that is not given stays the theme's.
val violet = PantrixPalette.Violet
PantrixMeterGroup(
items = listOf(
MeterItem("done", "Done", 18, color = violet.shade700),
MeterItem("doing", "In progress", 9, color = violet.shade500),
MeterItem("waiting", "Waiting", 13, color = violet.shade300)
),
max = 40,
description = "State of the work",
style = ChartStyle(meterHeight = 16.dp, barRadius = 0.dp, sliceGap = 0.dp),
tagKey = "own_look"
)
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 bar and the legend under it: each part's name and value.
var file by remember { mutableStateOf<ChartExportFile?>(null) }
PantrixMeterGroup(
items = METER_STORAGE,
max = 64,
format = { "${it.toInt()} GB" },
description = "Storage",
tagKey = "exported",
export = ChartExport(fileName = "storage") { file = it }
)
ExportedFile(file, tagKey = "exported")
private val METER_STORAGE = listOf(
MeterItem("apps", "Apps", 16),
MeterItem("photos", "Photos", 24),
MeterItem("messages", "Messages", 8),
MeterItem("system", "System", 10)
)
API
items
A meter group: several amounts of one whole, side by side on one bar. What a storage is filled with, how a budget is spent: the parts are read against each other and against what is left.
| Parameter | Type | Default | What it is |
|---|---|---|---|
items | List<MeterItem> | the amounts, in the order they lie on the bar. Their keys tell them apart, and two with one key are refused. | |
modifier | Modifier | Modifier | the group's modifier. |
max | Number | 100 | how much the whole bar is: more than nought. |
format | ((Double) -> String)? | null | how a value is written in the legend. Left out, it is written as a number in the theme's language. |
legend | ChartLegend? | ChartLegend() | where the names of the items stand, above the bar or under it. null shows none. |
description | String? | null | what the bar measures, in a few words, for a screen reader. |
style | ChartStyle? | null | this group's own geometry: the fields set here, with the theme's for the rest. |
colors | ChartColors? | null | this group's own colours, where they are not the theme's. |
tagKey | String? | null | the group's automation key: the group is MeterGroup_<tagKey>, its bar MeterGroup_<tagKey>.Bar and the legend's entry of an item MeterGroup_<tagKey>.Legend_<item's key>. |
export | ChartExport? | null | what 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. The legend stands under the bar in the file. |
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.
| Parameter | Type | Default | What it is |
|---|---|---|---|
height | Dp | Dp.Unspecified | How 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. |
lineWidth | Dp | Dp.Unspecified | The width of a series' line. |
markerSize | Dp | Dp.Unspecified | The width and height of the mark on a point. |
selectedMarkerSize | Dp | Dp.Unspecified | The same of the mark on the point that is pointed at. |
gridWidth | Dp | Dp.Unspecified | The 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. |
labelGap | Dp | Dp.Unspecified | Between the plot and what is written beside it and under it, and between that and an axis' title. |
tickSpacing | Dp | Dp.Unspecified | The least room between two values marked along the axis of values: what decides how many are marked where the axis does not say. |
legendGap | Dp | Dp.Unspecified | Between the legend and the chart it stands beside. |
legendItemGap | Dp | Dp.Unspecified | Between one entry of the legend and the next. |
swatchSize | Dp | Dp.Unspecified | How 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. |
swatchGap | Dp | Dp.Unspecified | Between that sample and the name after it. |
tooltipShape | ShapeSpec | ShapeSpec.Unspecified | The tooltip's corners: a step of the brand's shape scale, or a fixed shape. |
tooltipHorizontalPadding | Dp | Dp.Unspecified | Between the tooltip's sides and what it holds. |
tooltipVerticalPadding | Dp | Dp.Unspecified | Between its top and bottom and what it holds, and between its heading and rows. |
tooltipGap | Dp | Dp.Unspecified | Between the place pointed at and the tooltip beside it. |
tooltipElevation | Dp | Dp.Unspecified | The tooltip's shadow. |
barGap | Dp | Dp.Unspecified | Between two bars that stand side by side at a place. Bars too thin for it stand closer. |
barMaxWidth | Dp | Dp.Unspecified | The widest a bar is, however much room its place has: a chart of three places is not three slabs. |
barRadius | Dp | Dp.Unspecified | How round the corners of a bar's end are, the end away from nought. |
sliceGap | Dp | Dp.Unspecified | Between two slices of a pie that lie side by side, the same from the pie's middle to its rim. |
selectedSliceOffset | Dp | Dp.Unspecified | How 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. |
gaugeWidth | Dp | Dp.Unspecified | How thick the arc of a gauge is. An arc is no thicker than half its radius. |
meterHeight | Dp | Dp.Unspecified | How tall the bar of a meter group is. |
trackerHeight | Dp | Dp.Unspecified | How tall the blocks of a status tracker are. |
bubbleMinSize | Dp | Dp.Unspecified | How 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. |
bubbleMaxSize | Dp | Dp.Unspecified | How far across its largest bubble is: the one whose size is the most of the chart's. |
navigatorHeight | Dp | Dp.Unspecified | How 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. |
barBandShare | Float | Float.NaN | How 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. |
markLineWidth | Dp | Dp.Unspecified | The 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. |
markBandAlpha | Float | Float.NaN | How 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. |
patterns | Boolean? | null | Whether 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. |
nodeWidth | Dp | Dp.Unspecified | How wide a node of a sankey is. |
nodeGap | Dp | Dp.Unspecified | Between 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.
| Parameter | Type | Default | What it is |
|---|---|---|---|
series | List<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. |
grid | Color | Color.Unspecified | The lines drawn across the chart at the marks of an axis. The theme's divider. |
axis | Color | Color.Unspecified | The line along an axis. The theme's border. |
label | Color | Color.Unspecified | What is written beside the axes: the values, the places and the axes' titles, and the names in the legend. The theme's textSecondary. |
crosshair | Color | Color.Unspecified | The 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. |
tooltipContainer | Color | Color.Unspecified | The tooltip's fill. The theme's surface. |
tooltipBorder | Color | Color.Unspecified | The tooltip's edge. The theme's border. |
tooltipText | Color | Color.Unspecified | The tooltip's heading and its values. The theme's textPrimary. |
tooltipLabel | Color | Color.Unspecified | The names of the series in the tooltip. The theme's textSecondary. |
rising | Color | Color.Unspecified | What a value that goes up is drawn in: a step of a waterfall that adds. The theme's success. |
falling | Color | Color.Unspecified | What a value that goes down is drawn in: a step of a waterfall that takes away. The theme's danger. |
Accessibility
- Screen reader. The bar is a picture with its
description; the legend's entries say the parts. A bar with no legend says its parts itself.