Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion of degree to radian angle #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -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(
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down