diff --git a/chart/src/commonMain/kotlin/com/aay/compose/donutChart/component/PiePedigreeChart.kt b/chart/src/commonMain/kotlin/com/aay/compose/donutChart/component/PiePedigreeChart.kt index 812c79b..21a483a 100644 --- a/chart/src/commonMain/kotlin/com/aay/compose/donutChart/component/PiePedigreeChart.kt +++ b/chart/src/commonMain/kotlin/com/aay/compose/donutChart/component/PiePedigreeChart.kt @@ -17,6 +17,7 @@ import com.aay.compose.donutChart.model.ChartTypes import kotlin.math.cos import kotlin.math.roundToInt import kotlin.math.sin +import kotlin.math.PI @OptIn(ExperimentalTextApi::class) internal fun DrawScope.drawPedigreeChart( @@ -34,8 +35,14 @@ internal fun DrawScope.drawPedigreeChart( val outerCircularRadius = (minValue / 2) + (arcWidth / 1.2f) var startArc = -90F var startArcWithoutAnimation = -90f + + // If totalSum equals zero, there's nothing to show + if (totalSum == 0f) return + pieValueWithRatio.forEachIndexed { index, _ -> + if (pieChartData[index].data == 0.0) return@forEachIndexed + val arcWithAnimation = calculateAngle( dataLength = pieChartData[index].data.toFloat(), totalLength = totalSum, progress = transitionProgress.value ) @@ -132,7 +139,7 @@ internal fun DrawScope.drawPedigreeChart( } private val Float.degreeToAngle - get() = (this * (22/7) / 180f) + get() = this * PI / 180f private fun calculateAngle(dataLength: Float, totalLength: Float, progress: Float): Float = -360F * dataLength * progress / totalLength