Gauge
A gauge: one reading on a scale, as how far round an arc it reaches. A speed, a load, a share of a quota: a value that is read against the least and the most it can be.
import com.pantrixui.components.chart.gauge.PantrixGauge
- Scale.
minandmaxare the ends of the scale. A value past an end stands at that end and is written as it is. A gauge with no value (null) shows only its scale. - Ranges.
segmentsgives parts of the scale a colour and a name: the range that is fine, the range that is too much. EachGaugeSegmentsays where it ends (upTo); the first begins where the scale does, the others where the one before ends. The arc fills in the colour of the range the value has reached; the ranges themselves stay under it in their faint colours. - Needle. With
needlea hand reaches from the middle to the value, and the value is written under it. In a gauge with both a needle and ranges the ranges are drawn in their full colours and the arc is not filled: the hand is read against them. - Writing.
formatsays how the value and the two ends of the scale are written; left out, they are written as numbers in the theme's language.centerputs your own content in place of the value's writing. - Size and motion. The gauge is as wide as the room it is given and as tall as the chart's style says; the arc is the largest that fits there. When the value changes the arc and the hand go to the new value; where the system asks for reduced motion they do not go, they are there.
- Direction. The scale turns the same way in a language read from right to left too.
- 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.
Gauge_<tagKey>.
Examples
A value on a scale
At its plainest: a value and the end of the scale. Thirty-two gigabytes of a storage of fifty are used; format writes the value and the two ends of the scale with their unit.
PantrixGauge(
value = 32,
max = 50,
format = { "${it.toInt()} GB" },
description = "Storage used",
tagKey = "plain"
)
Ranges
The scale has three ranges: normal up to sixty, high up to eighty-five, critical after that. The arc fills in the colour of the range the value has reached; the ranges show under it in their faint colours.
Choose a value: the arc goes there and its colour changes with the range it has reached. A screen reader says the range's name after the value too: "72%, High". format writes the value in the theme's language (PantrixTheme.strings.percent).
The ranges name their own colours here: the theme's success, warning and danger colours. A range that is given no colour takes the theme's next chart colour; those colours carry no meaning.
var load by remember { mutableStateOf(72) }
val strings = PantrixTheme.strings
PantrixSegmentButton(
options = loadReadings(),
selected = load,
onSelect = { load = it },
fullWidth = false,
tagKey = "gauge_load"
)
PantrixGauge(
value = load,
segments = loadRanges(),
format = { strings.percent(it / 100) },
description = "Processor load",
tagKey = "segments"
)
@Composable
private fun loadRanges(): List<GaugeSegment> {
val colors = PantrixTheme.colors
return listOf(
GaugeSegment(upTo = 60, color = colors.success.color, name = "Normal"),
GaugeSegment(upTo = 85, color = colors.warning.color, name = "High"),
GaugeSegment(upTo = 100, color = colors.danger.color, name = "Critical")
)
}
@Composable
private fun loadReadings(): List<SegmentOption<Int>> {
val strings = PantrixTheme.strings
return listOf(40 to "low", 72 to "high", 93 to "critical").map { (load, key) ->
SegmentOption(value = load, label = strings.percent(load / 100.0), tagKey = key)
}
}
A needle
A gauge with a needle: a hand reaches from the middle to the value, and the value is written under it. The ranges are drawn in their full colours and the arc is not filled: the hand is read against them.
var load by remember { mutableStateOf(40) }
val strings = PantrixTheme.strings
PantrixSegmentButton(
options = loadReadings(),
selected = load,
onSelect = { load = it },
fullWidth = false,
tagKey = "gauge_needle_load"
)
PantrixGauge(
value = load,
segments = loadRanges(),
needle = true,
format = { strings.percent(it / 100) },
description = "Processor load",
tagKey = "needle"
)
@Composable
private fun loadRanges(): List<GaugeSegment> {
val colors = PantrixTheme.colors
return listOf(
GaugeSegment(upTo = 60, color = colors.success.color, name = "Normal"),
GaugeSegment(upTo = 85, color = colors.warning.color, name = "High"),
GaugeSegment(upTo = 100, color = colors.danger.color, name = "Critical")
)
}
@Composable
private fun loadReadings(): List<SegmentOption<Int>> {
val strings = PantrixTheme.strings
return listOf(40 to "low", 72 to "high", 93 to "critical").map { (load, key) ->
SegmentOption(value = load, label = strings.percent(load / 100.0), tagKey = key)
}
}
A scale that does not start at nought
A gauge with a needle and no ranges: the arc fills up to the value and the hand points at it too. A scale need not start at nought: this thermometer goes from twenty below to forty.
val strings = PantrixTheme.strings
PantrixGauge(
value = 7.5,
min = -20,
max = 40,
needle = true,
format = { "${strings.decimal(it, fractionDigits = 1)}°" },
description = "Outside temperature",
tagKey = "below_zero"
)
Your own content in the middle
center puts your own content in place of the value's writing: here the unit under the value. The content fits the room the arc leaves in its middle.
A screen reader hears the value from the gauge itself (description and format); what is written in the middle is for the eye.
PantrixGauge(
value = 86,
max = 120,
format = { "${it.toInt()} km/h" },
center = {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
PantrixText(text = "86", style = PantrixTheme.typography.headline)
PantrixText(text = "km/h", color = PantrixTheme.colors.textSecondary)
}
},
description = "Speed",
tagKey = "own_center"
)
Your own sizes
A gauge's own sizes: a thinner arc (gaugeWidth) and a lower gauge (height). No gap between the ranges (sliceGap). A field that is not given stays the theme's.
val strings = PantrixTheme.strings
PantrixGauge(
value = 54,
segments = loadRanges(),
format = { strings.percent(it / 100) },
description = "Processor load",
style = ChartStyle(gaugeWidth = 8.dp, height = 160.dp, sliceGap = 0.dp),
tagKey = "own_look"
)
@Composable
private fun loadRanges(): List<GaugeSegment> {
val colors = PantrixTheme.colors
return listOf(
GaugeSegment(upTo = 60, color = colors.success.color, name = "Normal"),
GaugeSegment(upTo = 85, color = colors.warning.color, name = "High"),
GaugeSegment(upTo = 100, color = colors.danger.color, name = "Critical")
)
}
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 value in the middle is written in the file too; content put there by center is not in the file.
var file by remember { mutableStateOf<ChartExportFile?>(null) }
PantrixGauge(
value = 32,
max = 50,
format = { "${it.toInt()} GB" },
description = "Storage used",
tagKey = "exported",
export = ChartExport(fileName = "storage") { file = it }
)
ExportedFile(file, tagKey = "exported")
API
value
A gauge: one reading on a scale, as how far round an arc it reaches. A speed, a load, a share of a quota: a value that is read against the least and the most it can be.
| Parameter | Type | Default | What it is |
|---|---|---|---|
value | Number? | the reading. null, and what is no number, is no reading: the gauge shows its scale and nothing on it. | |
modifier | Modifier | Modifier | the gauge's modifier. A height here is the gauge's. |
min | Number | 0 | where the scale begins. |
max | Number | 100 | where the scale ends: more than min. |
segments | List<GaugeSegment> | emptyList() | the stretches of the scale that have a colour and a name, in the order they lie along it; each ends past where the one before it does. None, and the arc is drawn in the first of the chart's colours. |
needle | Boolean | false | whether a hand points at the value. |
format | ((Double) -> String)? | null | how a value is written: the reading, and the two ends of the scale. Left out, they are written as numbers in the theme's language. |
center | (@Composable () -> Unit)? | null | what stands in the gauge in place of the reading as it is written: the reading with a unit under it, an icon. It has the room the arc leaves in its middle, or the room between the arc's two ends where the gauge has a needle. |
description | String? | null | what the gauge measures, in a few words, for a screen reader: the first thing it says of the gauge. |
style | ChartStyle? | null | this gauge's own geometry: the fields set here, with the theme's for the rest. |
colors | ChartColors? | null | this gauge's own colours, where they are not the theme's. |
tagKey | String? | null | the gauge's automation key: the gauge is Gauge_<tagKey>. |
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. What stands in the middle, center, is not in the file; the reading the gauge writes there of itself is. |
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 gauge is one thing: its
description, then the value as it is written and, where it has one, the name of the range it is in.