Skip to content

Commit

Permalink
Add ability to separately specify pie chart label animation from pie …
Browse files Browse the repository at this point in the history
…animation.
  • Loading branch information
gsteckman committed Nov 3, 2024
1 parent 68cab11 commit bb23c94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- setViewRange function on LinearAxisModel interface.
- zoom and pan support for all platforms within XYGraph
- labelAnimationSpec parameter for PieCharts

### Changed

Expand All @@ -21,6 +22,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Upgrade gradle wrapper to 8.10
- Upgrade Compose to 1.7.0
- Upgrade coroutines to 1.9.0
- Rename PieChart's animationSpec parameter to pieAnimationSpec

### Fixed

Expand Down
21 changes: 14 additions & 7 deletions src/commonMain/kotlin/io/github/koalaplot/core/pie/PieChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ private const val LabelFadeInDuration = 1000
* @param maxPieDiameter Maximum diameter allowed for the pie. May be Infinity but not Unspecified.
* @param forceCenteredPie If true, will force the pie to be centered within its parent, by adjusting (decreasing) the
* pie size to accommodate label sizes and positions. If false, will maximize the pie diameter.
* @param animationSpec Specifies the animation to use when the pie chart is first drawn.
* @param pieAnimationSpec Specifies the animation to use when the pie chart is first drawn.
* @param labelAnimationSpec Specifies the animation to use when the labels are drawn. Drawing of the labels begins
* after the pie animation is complete.
* @param pieStartAngle Sets an angle for the pie data to start at. Defaults to the top of the pie.
* @param pieExtendAngle Sets a max angle for the pie to extend to, with a value between 1 and 360.
* Defaults to [DegreesFullCircle].
Expand All @@ -216,7 +218,8 @@ public fun PieChart(
minPieDiameter: Dp = 100.dp,
maxPieDiameter: Dp = 300.dp,
forceCenteredPie: Boolean = false,
animationSpec: AnimationSpec<Float> = KoalaPlotTheme.animationSpec,
pieAnimationSpec: AnimationSpec<Float> = KoalaPlotTheme.animationSpec,
labelAnimationSpec: AnimationSpec<Float> = tween(LabelFadeInDuration, 0, LinearOutSlowInEasing),
pieStartAngle: AngularValue = AngleCCWTop.deg,
pieExtendAngle: AngularValue = DegreesFullCircle.deg,
) {
Expand All @@ -230,9 +233,9 @@ public fun PieChart(
val labelAlpha = remember(values) { Animatable(0f) }

LaunchedEffect(values) {
beta.animateTo(1f, animationSpec = animationSpec)
beta.animateTo(1f, animationSpec = pieAnimationSpec)
// fade in labels after pie animation is complete
labelAlpha.animateTo(1f, animationSpec = tween(LabelFadeInDuration, 0, LinearOutSlowInEasing))
labelAlpha.animateTo(1f, labelAnimationSpec)
}

// pieSliceData that gets animated - used for drawing the pie
Expand Down Expand Up @@ -341,7 +344,9 @@ public fun PieChart(
* @param maxPieDiameter Maximum diameter allowed for the pie. May be Infinity but not Unspecified.
* @param forceCenteredPie If true, will force the pie to be centered within its parent, by adjusting (decreasing) the
* pie size to accommodate label sizes and positions. If false, will maximize the pie diameter.
* @param animationSpec Specifies the animation to use when the pie chart is first drawn.
* @param pieAnimationSpec Specifies the animation to use when the pie chart is first drawn.
* @param labelAnimationSpec Specifies the animation to use when the labels are drawn. Drawing of the labels begins
* after the pie animation is complete.
*/
@ExperimentalKoalaPlotApi
@Composable
Expand All @@ -360,7 +365,8 @@ public fun PieChart(
minPieDiameter: Dp = 100.dp,
maxPieDiameter: Dp = 300.dp,
forceCenteredPie: Boolean = false,
animationSpec: AnimationSpec<Float> = KoalaPlotTheme.animationSpec
pieAnimationSpec: AnimationSpec<Float> = KoalaPlotTheme.animationSpec,
labelAnimationSpec: AnimationSpec<Float> = tween(LabelFadeInDuration, 0, LinearOutSlowInEasing),
) {
require(labelSpacing >= 1f) { "labelSpacing must be greater than 1" }
PieChart(
Expand All @@ -375,7 +381,8 @@ public fun PieChart(
minPieDiameter,
maxPieDiameter,
forceCenteredPie,
animationSpec
pieAnimationSpec,
labelAnimationSpec
)
}

Expand Down

0 comments on commit bb23c94

Please sign in to comment.