Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ fun LineChart(
val properties = line.popupProperties ?: popupProperties
if (!properties.enabled) return@forEachIndexed

if (line.values.isEmpty()) return@forEachIndexed
val pathData = linesPathData.getOrNull(dataIndex) ?: return@forEachIndexed
if (pathData.xPositions.isEmpty()) return@forEachIndexed

val positionX = position.x.coerceIn(0f, size.width.toFloat())
val pathData = linesPathData[dataIndex]

val isSingleValue = line.values.count() == 1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ir.ehsannarmani.compose_charts.extensions.line_chart

import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.*
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas

internal fun DrawScope.drawLineGradient(
path: Path,
Expand All @@ -13,25 +14,25 @@ internal fun DrawScope.drawLineGradient(
progress: Float,
size: Size? = null,
startOffset: Float,
endOffset: Float
endOffset: Float,
) {
val _size = size ?: this.size
drawIntoCanvas {
val p = Path()
p.addPath(path)
p.lineTo(endOffset, _size.height)
p.lineTo(startOffset, _size.height)
p.close()
val paint = Paint()
paint.shader = LinearGradientShader(
Offset(0f, 0f),
Offset(0f, _size.height),
listOf(
val filled = Path().apply {
addPath(path)
lineTo(endOffset, _size.height)
lineTo(startOffset, _size.height)
close()
}
drawPath(
path = filled,
brush = Brush.verticalGradient(
colors = listOf(
color1.copy(alpha = color1.alpha * progress),
color2.copy(alpha = color2.alpha * progress),
),
tileMode = TileMode.Mirror
)
it.drawPath(p, paint)
}
}
startY = 0f,
endY = _size.height,
tileMode = TileMode.Mirror,
),
)
}