From a97ec286470a32652e34ccdcc0e8c103d12bbf28 Mon Sep 17 00:00:00 2001 From: Patrick Michalik <120058021+patrickmichalik@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:09:29 +0100 Subject: [PATCH] `LineCartesianLayer`: Make `DynamicShader`-related fixes and improvements --- .../vico/core/chart/layer/LineCartesianLayer.kt | 5 ++--- .../core/model/drawing/LineCartesianLayerDrawingModel.kt | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/chart/layer/LineCartesianLayer.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/chart/layer/LineCartesianLayer.kt index f33bbd90d..4fe657fe4 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/chart/layer/LineCartesianLayer.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/chart/layer/LineCartesianLayer.kt @@ -58,7 +58,6 @@ import com.patrykandpatrick.vico.core.model.drawing.DrawingModelInterpolator import com.patrykandpatrick.vico.core.model.drawing.LineCartesianLayerDrawingModel import com.patrykandpatrick.vico.core.model.forEachInIndexed import com.patrykandpatrick.vico.core.util.Point -import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -277,7 +276,7 @@ public open class LineCartesianLayer( val drawingModel = model.extraStore.getOrNull(drawingModelKey) val yRange = chartValues.getYRange(verticalAxisPosition) - val zeroLineYFraction = 1f - (drawingModel?.zeroY ?: abs(yRange.minY / yRange.length)) + val zeroLineYFraction = drawingModel?.zeroY ?: (yRange.minY / yRange.length + 1f).coerceIn(0f..1f) model.series.forEachIndexed { entryListIndex, entries -> @@ -617,7 +616,7 @@ public open class LineCartesianLayer( } } .let { pointInfo -> - LineCartesianLayerDrawingModel(pointInfo, abs(yRange.minY / yRange.length)) + LineCartesianLayerDrawingModel(pointInfo, (yRange.minY / yRange.length + 1f).coerceIn(0f..1f)) } } } diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/model/drawing/LineCartesianLayerDrawingModel.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/model/drawing/LineCartesianLayerDrawingModel.kt index 766db9ca1..4084d78dc 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/model/drawing/LineCartesianLayerDrawingModel.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/model/drawing/LineCartesianLayerDrawingModel.kt @@ -21,9 +21,9 @@ import com.patrykandpatrick.vico.core.extension.lerp import com.patrykandpatrick.vico.core.extension.orZero /** - * Houses drawing information for a [LineCartesianLayer]. [opacity] is the lines’ opacity. [zeroY] specifies the - * position of the zero line (_y_ = 0) from the bottom of the [LineCartesianLayer] as a fraction of the - * [LineCartesianLayer]’s height. + * Houses drawing information for a [LineCartesianLayer]. [opacity] is the lines’ opacity. [zeroY], restricted to the + * interval [0, 1], specifies the position of the zero line (_y_ = 0) from the top of the [LineCartesianLayer] as a + * fraction of the [LineCartesianLayer]’s height. */ public class LineCartesianLayerDrawingModel( pointInfo: List>,