Skip to content

Instantly share code, notes, and snippets.

@TemMax
Created June 10, 2025 12:38
Show Gist options
  • Save TemMax/5bbb01b87b1e864f340e681c1d22f109 to your computer and use it in GitHub Desktop.
Save TemMax/5bbb01b87b1e864f340e681c1d22f109 to your computer and use it in GitHub Desktop.
private class DualLineFill(
private val fillBefore: Fill,
private val fillAfter: Fill,
) : LineCartesianLayer.LineFill {
private val paintBefore = Paint().apply { color = fillBefore.color }
private val paintAfter = Paint().apply { color = fillAfter.color }
private var markerX: Float? = null
fun updateMarkerX(x: Float?) {
markerX = x
}
override fun draw(
context: CartesianDrawingContext,
halfLineThickness: Float,
verticalAxisPosition: Axis.Position.Vertical?,
) {
with(context) {
fillBefore.brush?.applyTo(size = layerBounds.size, p = paintBefore, alpha = 1f)
fillAfter.brush?.applyTo(size = layerBounds.size, p = paintAfter, alpha = 1f)
canvas.withSave {
canvas.translate(layerBounds.left, layerBounds.top)
canvas.drawRect(0f, 0f, layerBounds.width, layerBounds.height, paintBefore)
markerX?.let { x ->
canvas.drawRect(x, 0f, layerBounds.width, layerBounds.bottom, paintAfter)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment