Charts
Chartsanimated
Crosshair area
An area chart with a tracking crosshair and a floating value tag at the focus point.
82%
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 CrosshairArea(
values: List<Float> = listOf(0.4f, 0.55f, 0.5f, 0.7f, 0.62f, 0.82f, 0.74f),
focus: Int = 5,
accent: Color = Color(0xFF3B82F6),
modifier: Modifier = Modifier,
) {
val reveal by animateFloatAsState(1f, tween(1000, easing = EaseOutCubic), label = "r")
val guide = MaterialTheme.colorScheme.outlineVariant
Canvas(modifier.fillMaxWidth().height(124.dp)) {
val step = size.width / (values.size - 1)
val line = Path()
values.forEachIndexed { i, v ->
val x = i * step
val y = size.height * (1f - v)
if (i == 0) line.moveTo(x, y) else line.lineTo(x, y)
}
val area = Path().apply { addPath(line); lineTo(size.width, size.height); lineTo(0f, size.height); close() }
clipRect(right = size.width * reveal) {
drawPath(area, Brush.verticalGradient(listOf(accent.copy(alpha = 0.3f), Color.Transparent)))
drawPath(line, accent, style = Stroke(3.dp.toPx(), cap = StrokeCap.Round))
}
val fx = focus * step
val fy = size.height * (1f - values[focus])
drawLine(guide, Offset(fx, 0f), Offset(fx, size.height), 1.dp.toPx(), pathEffect = PathEffect.dashPathEffect(floatArrayOf(6f, 6f)))
drawCircle(accent, 5.dp.toPx(), Offset(fx, fy))
drawCircle(Color.White, 2.dp.toPx(), Offset(fx, fy))
}
}