
Код: Выделить всё
@Composable
fun Chart(
min: Double = 0.0,
max: Double = 3823.0,
) {
val textMeasurer = rememberTextMeasurer()
val padding = 40f
val yAxisLabelMaxWidth = textMeasurer.measure(text = "${max.toInt()}").size.width.toFloat()
val yAxisLabelMinWidth = textMeasurer.measure(text = "${min.toInt()}").size.width.toFloat()
Canvas(Modifier.size(100.dp)) {
drawText(
textMeasurer = textMeasurer,
text = "${max.toInt()}",
topLeft = Offset(
x = 0f,
y = padding - textMeasurer.measure(text = "$max").size.height / 2,
),
style = TextStyle(
fontSize = 10.sp,
background = Color.Green,
),
)
drawText(
textMeasurer = textMeasurer,
text = "${min.toInt()}",
topLeft = Offset(
x = yAxisLabelMaxWidth - yAxisLabelMinWidth,
y = size.height - padding - textMeasurer.measure(text = "$min").size.height / 2,
),
style = TextStyle(
fontSize = 10.sp,
background = Color.Green,
),
)
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ck-compose