Last active
July 31, 2021 20:26
-
-
Save zsoltk/7a32ad41c8b56f7edfab6027e57906e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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