diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt index 2c461d018..ce54c1937 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineCartesianLayer.kt @@ -21,6 +21,7 @@ import android.graphics.Canvas import android.graphics.Paint import android.graphics.Path import android.graphics.PorterDuff +import android.graphics.PorterDuffXfermode import androidx.compose.runtime.Immutable import androidx.compose.runtime.Stable import com.patrykandpatrick.vico.core.cartesian.CartesianDrawingContext @@ -36,6 +37,7 @@ import com.patrykandpatrick.vico.core.cartesian.data.LineCartesianLayerDrawingMo import com.patrykandpatrick.vico.core.cartesian.data.LineCartesianLayerModel import com.patrykandpatrick.vico.core.cartesian.data.MutableCartesianChartRanges import com.patrykandpatrick.vico.core.cartesian.data.forEachIn +import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer.Line import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarker import com.patrykandpatrick.vico.core.cartesian.marker.LineCartesianLayerMarkerTarget import com.patrykandpatrick.vico.core.cartesian.marker.MutableLineCartesianLayerMarkerTarget @@ -125,6 +127,7 @@ protected constructor( public fun draw( context: CartesianDrawingContext, path: Path, + lineCanvas: Canvas, fillCanvas: Canvas, verticalAxisPosition: Axis.Position.Vertical?, ) { @@ -133,7 +136,7 @@ protected constructor( linePaint.strokeWidth = thickness val halfThickness = thickness.half areaFill?.draw(context, path, halfThickness, verticalAxisPosition) - fillCanvas.drawPath(path, linePaint) + lineCanvas.drawPath(path, linePaint) withOtherCanvas(fillCanvas) { fill.draw(context, halfThickness, verticalAxisPosition) } } } @@ -141,7 +144,7 @@ protected constructor( /** Draws a [LineCartesianLayer] line’s fill. */ public interface LineFill { - /** Draws the line fill. [PorterDuff.Mode.SRC_IN] should be used. */ + /** Draws the line fill. */ public fun draw( context: CartesianDrawingContext, halfLineThickness: Float, @@ -306,8 +309,12 @@ protected constructor( protected val linePath: Path = Path() + protected val lineCanvas: Canvas = Canvas() + protected val lineFillCanvas: Canvas = Canvas() + private val srcInPaint = Paint().apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) } + protected val cacheKeyNamespace: CacheStore.KeyNamespace = CacheStore.KeyNamespace() override val markerTargets: Map> = _markerTargets @@ -366,10 +373,13 @@ protected constructor( canvas.saveLayer(opacity = drawingModel?.opacity ?: 1f) - val lineFillBitmap = getBitmap(cacheKeyNamespace, seriesIndex) + val lineBitmap = getBitmap(cacheKeyNamespace, seriesIndex, "line") + lineCanvas.setBitmap(lineBitmap) + val lineFillBitmap = getBitmap(cacheKeyNamespace, seriesIndex, "lineFill") lineFillCanvas.setBitmap(lineFillBitmap) - line.draw(context, linePath, lineFillCanvas, verticalAxisPosition) - canvas.drawBitmap(lineFillBitmap, 0f, 0f, null) + line.draw(context, linePath, lineCanvas, lineFillCanvas, verticalAxisPosition) + lineCanvas.drawBitmap(lineFillBitmap, 0f, 0f, srcInPaint) + canvas.drawBitmap(lineBitmap, 0f, 0f, null) forEachPointInBounds(series, drawingStart, pointInfoMap) { entry, x, y, _, _ -> updateMarkerTargets(entry, x, y, lineFillBitmap) diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineFills.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineFills.kt index 05123870b..69c79d463 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineFills.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/cartesian/layer/LineFills.kt @@ -17,19 +17,13 @@ package com.patrykandpatrick.vico.core.cartesian.layer import android.graphics.Paint -import android.graphics.PorterDuff -import android.graphics.PorterDuffXfermode import com.patrykandpatrick.vico.core.cartesian.CartesianDrawingContext import com.patrykandpatrick.vico.core.cartesian.axis.Axis import com.patrykandpatrick.vico.core.common.Fill import com.patrykandpatrick.vico.core.common.data.ExtraStore internal data class SingleLineFill(val fill: Fill) : LineCartesianLayer.LineFill { - private val paint = - Paint(Paint.ANTI_ALIAS_FLAG).apply { - color = fill.color - xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) - } + private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = fill.color } override fun draw( context: CartesianDrawingContext, @@ -55,8 +49,7 @@ internal data class DoubleLineFill( val bottomFill: Fill, val splitY: (ExtraStore) -> Number, ) : LineCartesianLayer.LineFill { - private val paint = - Paint(Paint.ANTI_ALIAS_FLAG).apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) } + private val paint = Paint(Paint.ANTI_ALIAS_FLAG) override fun draw( context: CartesianDrawingContext,