Charts: "utility marks"

import io.data2viz.charts.* import io.data2viz.charts.core.Padding 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.layout.* import io.data2viz.charts.config.configs.* import io.data2viz.charts.config.* import io.data2viz.charts.core.CursorType import io.data2viz.math.* import io.data2viz.geom.* import io.data2viz.viz.* import io.data2viz.color.* import kotlin.math.* import kotlinx.datetime.Instant val width = 450.0 val height = 300.0 data class Value(val index: Int, val value: Double?) val values = listOf( Value(2, 16.4), Value(3, 18.2), Value(4, 22.9), Value(5, 23.3), Value(6, 20.6), Value(7, 15.9), Value(8, 12.9), Value(9, 12.4), Value(10, 15.2), Value(11, null), Value(12, null), Value(13, 16.2), Value(14, 17.1), Value(15, 18.8), Value(15, 18.8), ) fun main() { // Creating and sizing the VizContainer val vc = newVizContainer().apply { size = Size(width, height) } vc.chart(values) { config { cursor { show = true type = CursorType.Vertical } events { highlightMode = HighlightMode.None } } val indexDim = discrete( { domain.index } ) val valueDim = quantitative( { domain.value } ) val lowDim = valueDim.child( { 14.0 } ) val hiDim = valueDim.child( { 20.0 } ) val stepDimLow = valueDim.child( { if (domain.value != null ) ((domain.value!! / 4).toInt() * 4.0) else null } ) val stepDimHi = valueDim.child( { if (domain.value != null ) (ceil(domain.value!! / 4) * 4.0) else null } ) val dashDimension = discrete( { if (values[indexInData].value == null || (indexInData < values.size - 1 && values[indexInData+1].value == null)) { doubleArrayOf(2.0, 4.0) } else null } ) line(indexDim, valueDim) { showMarkers = true strokeWidth = constant(2.0) y { start = 10.0 end = 24.0 } } line(indexDim, lowDim) { strokeLine = dashDimension strokeColor = constant(Colors.Web.black) } line(indexDim, hiDim){ strokeLine = dashDimension strokeColor = constant(Colors.Web.black) } line(indexDim, stepDimLow){ curve = MarkCurves.Step strokeColor = constant(Colors.Web.red) } line(indexDim, stepDimHi){ curve = MarkCurves.Step strokeColor = constant(Colors.Web.red) } } }
pierre avatar

Sketch created by

pierre

comments

Gaetan Zoritchak