Charts: sign customization

import io.data2viz.charts.* import io.data2viz.charts.core.* import io.data2viz.charts.dimension.* import io.data2viz.charts.chart.* import io.data2viz.charts.chart.mark.* import io.data2viz.charts.viz.* import io.data2viz.charts.layout.* import io.data2viz.geom.* import io.data2viz.color.* import io.data2viz.random.RandomDistribution import io.data2viz.timeFormat.* import io.data2viz.timeFormat.TimeLocale import kotlinx.datetime.Instant import io.data2viz.math.* import io.data2viz.shape.* fun main() { // Creating and sizing the VizContainer val vc = newVizContainer().apply { size = Size(width, height) } vc.chart(samples) { config { events { zoomMode = ZoomMode.X panMode = PanMode.X } tooltip { fontSize = config.tooltip.fontSize + 2.0 } cursor { show = true } } tooltip { formatter = { "${domain.batchCode}: ${domain.temperature.formatToInteger()}°C" } } val timeDim = temporal( { domain.timestamp } ) val tempDim = quantitative( { domain.temperature } ) { name = "Temperature in °C" } val colorDim = discrete( { Colors.hsl((domain.temperature / 400.0 - 3).rad, 80.pct, 50.pct) as Color? } ) val maxTemp = samples.maxOf {it.temperature} plot(timeDim, tempDim) { strokeColor = colorDim strokeColorHighlight = colorDim marker = discrete( { if (domain.temperature >= maxTemp) Symbols.Star else Symbols.Circle} ) size = discrete( { if (domain.temperature >= maxTemp) 80.0 else 15.0} ) } } } val width = 450.0 val height = 300.0 val randomGenerator = RandomDistribution(42).normal(100.0, 18.0) data class Sample( val sampleIndex: Int, val batchCode: String, val timestamp: Instant, val temperature: Double, val pressure: Double ) val samples = generateSamples(200) fun generateSamples(numSamples: Int) = (0 until numSamples).map { val batchIndex = 1 + (it % 4) val pressure: Double = randomGenerator() * 1000 val temp: Double = randomGenerator() * batchIndex * pressure / 100000 val ts = Instant.fromEpochMilliseconds(1611150127144L + (it * 8632L)) Sample(it, "Batch #$batchIndex", ts, temp, pressure) }
pierre avatar

Sketch created by

pierre

A simple chart symbols customisation: - change color based on "temperature" value - use a star symbol for the hottest record

comments