Charts
Chartsanimated

Bump

A bump chart tracking rank changes over time with crossing, draw-on lines.

Installation

caveui components are copy-paste Jetpack Compose built entirely on Material 3 — there's no caveui dependency to add. Make sure Material 3 is on your classpath (it ships with the Compose BOM), then copy the Usage snippet below into your project.

kotlin
// build.gradle.kts (module)
dependencies {
    implementation(platform("androidx.compose:compose-bom:2025.06.00"))
    implementation("androidx.compose.material3:material3")
}

Usage

kotlin
@Composable
fun BumpChart(
    series: List<List<Int>> = listOf(
        listOf(1, 2, 1, 3), listOf(2, 1, 3, 1),
        listOf(3, 3, 2, 2), listOf(4, 4, 4, 4),
    ),
    palette: List<Color> = listOf(Color(0xFF6366F1), Color(0xFF10B981), Color(0xFFF59E0B), Color(0xFFEC4899)),
    modifier: Modifier = Modifier,
) {
    val draw = remember { Animatable(0f) }
    LaunchedEffect(Unit) { draw.animateTo(1f, tween(1100, easing = EaseInOutCubic)) }
    Canvas(modifier.fillMaxWidth().height(120.dp)) {
        val cols = series[0].size
        val ranks = 4
        val stepX = size.width / (cols - 1)
        val stepY = size.height / (ranks + 1)
        series.forEachIndexed { s, ranksList ->
            val path = Path().apply {
                ranksList.forEachIndexed { i, rank ->
                    val x = i * stepX
                    val y = stepY * rank
                    if (i == 0) moveTo(x, y) else lineTo(x, y)
                }
            }
            val m = PathMeasure().apply { setPath(path, false) }
            drawPath(
                Path().also { m.getSegment(0f, m.length * draw.value, it, true) },
                palette[s], style = Stroke(3.dp.toPx(), cap = StrokeCap.Round, join = StrokeJoin.Round),
            )
            ranksList.forEachIndexed { i, rank ->
                if (i / (cols - 1f) <= draw.value) drawCircle(palette[s], 4.dp.toPx(), Offset(i * stepX, stepY * rank))
            }
        }
    }
}