Skip to content

Commit

Permalink
Fix the bug with single-slice pie
Browse files Browse the repository at this point in the history
  • Loading branch information
mahozad committed Aug 25, 2021
1 parent cbd2c21 commit d79fdf1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Binary file added piechart/src/androidTest/assets/screenshot-72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ class ScreenshotTest {
}
}

@Test fun chartWithASingleSlice() {
compareScreenshots("screenshot-72") {
slices = listOf(Slice(1f, Color.rgb(133, 77, 206)))
}
}

/**
* FIXME: the name of the function is misleading. It also works in a saving
* mode in that it just saves the screenshot on device and skips the comparison.
Expand Down
6 changes: 5 additions & 1 deletion piechart/src/main/kotlin/ir/mahozad/android/component/Pie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ internal class Pie(
mainPaint.shader = gradient
mainPaint.alpha = 255

val slicePath = makeSlice(center, pieEnclosingRect, currentAngle, slice.fraction, pieDrawDirection, slice.pointer ?: slicesPointer)
val slicePath = if (slice.fraction == 1f) {
Path().apply { addCircle(center.x, center.y, radius, Path.Direction.CW) }
} else {
makeSlice(center, pieEnclosingRect, currentAngle, slice.fraction, pieDrawDirection, slice.pointer ?: slicesPointer)
}
canvas.withClip(clip) {
canvas.drawPath(slicePath, mainPaint)
}
Expand Down

0 comments on commit d79fdf1

Please sign in to comment.