Skip to content

Instantly share code, notes, and snippets.

@zsoltk
Last active July 31, 2021 20:26
Show Gist options
  • Save zsoltk/7a32ad41c8b56f7edfab6027e57906e1 to your computer and use it in GitHub Desktop.
Save zsoltk/7a32ad41c8b56f7edfab6027e57906e1 to your computer and use it in GitHub Desktop.
object DatasetVisualiser : SquareDecoration {
@Composable
override fun render(properties: SquareRenderProperties) {
ActiveDatasetVisualisation.current.let { viz ->
val datapoint = viz.dataPointAt(
properties.position,
properties.boardProperties.toState
)
val percentage = datapoint?.value?.let {
(1.0f * datapoint.value - viz.minValue) / (viz.maxValue - viz.minValue)
}?.coerceIn(0f, 1f)
val interpolatedColor = percentage?.let {
lerp(datapoint.colorScale.first, datapoint.colorScale.second, percentage)
}
val color by animateColorAsState(
targetValue = interpolatedColor ?: Color.Transparent,
animationSpec = tween(1500)
)
datapoint?.let {
Box(
modifier = properties.sizeModifier
.background(color),
contentAlignment = Alignment.TopEnd
) {
datapoint.label?.let {
Text(
text = datapoint.label,
fontSize = 10.sp
)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment