Charts
Chartsanimated

Spiral

An Archimedean spiral plot whose path draws on to map a cyclical series.

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 SpiralChart(
    turns: Int = 4,
    accent: Color = Color(0xFFEC4899),
    modifier: Modifier = Modifier,
) {
    val draw = remember { Animatable(0f) }
    LaunchedEffect(Unit) { draw.animateTo(1f, tween(1600, easing = EaseInOutCubic)) }
    Canvas(modifier.size(150.dp)) {
        val maxR = size.minDimension / 2 * 0.9f
        val path = Path()
        val steps = turns * 60
        for (i in 0..steps) {
            val t = i / steps.toFloat()
            val a = t * turns * 2 * PI.toFloat() - PI.toFloat() / 2
            val r = maxR * t
            val p = center + Offset(cos(a), sin(a)) * r
            if (i == 0) path.moveTo(p.x, p.y) else path.lineTo(p.x, p.y)
        }
        val m = PathMeasure().apply { setPath(path, false) }
        drawPath(
            Path().also { m.getSegment(0f, m.length * draw.value, it, true) },
            Brush.sweepGradient(listOf(accent, Color(0xFF8B5CF6), accent), center),
            style = Stroke(3.dp.toPx(), cap = StrokeCap.Round),
        )
    }
}