Charts
Chartsanimated

Chord

A chord diagram with an arc ring and relationship ribbons revealed by an iris wipe.

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 ChordDiagram(
    chords: List<Pair<Float, Float>> = listOf(
        0f to 0.45f, 0.2f to 0.7f, 0.55f to 0.9f, 0.35f to 0.8f,
    ),
    palette: List<Color> = listOf(Color(0xFF6366F1), Color(0xFF10B981), Color(0xFFF59E0B), Color(0xFFEC4899)),
    modifier: Modifier = Modifier,
) {
    val reveal by animateFloatAsState(1f, tween(1000, easing = EaseOutCubic), label = "r")
    Canvas(modifier.size(150.dp)) {
        val r = size.minDimension / 2 * 0.82f
        fun onCircle(t: Float) = center + Offset(cos(t * 2 * PI.toFloat() - PI.toFloat() / 2) * r, sin(t * 2 * PI.toFloat() - PI.toFloat() / 2) * r)
        repeat(4) { i ->
            drawArc(
                palette[i], -90f + i * 90f + 4f, 82f, false,
                topLeft = center - Offset(r, r), size = Size(r * 2, r * 2),
                style = Stroke(8.dp.toPx(), cap = StrokeCap.Round),
            )
        }
        chords.forEachIndexed { i, (a, b) ->
            val pa = onCircle(a)
            val pb = onCircle(b)
            val path = Path().apply { moveTo(pa.x, pa.y); quadraticBezierTo(center.x, center.y, pb.x, pb.y) }
            drawPath(path, palette[i % palette.size].copy(alpha = 0.45f * reveal), style = Stroke(2.dp.toPx()))
        }
    }
}