Skip to content

Semicircle (concave/convex) shaped piechart slices#125

Merged
gsteckman merged 4 commits into
KoalaPlot:mainfrom
postfixNotation:contribution/piechartshapes-roundedslices
Aug 30, 2025
Merged

Semicircle (concave/convex) shaped piechart slices#125
gsteckman merged 4 commits into
KoalaPlot:mainfrom
postfixNotation:contribution/piechartshapes-roundedslices

Conversation

@postfixNotation
Copy link
Copy Markdown
Contributor

Motivation

When I was looking for a CMP chart library I needed to keep style specifications in mind which are established in an app I'm currently working on. One of these are rounded slices in pie charts. I've first encountered this functionality when I was using MPAndroidChart.

Since koalaplot has been designed with a straighforward approach of providing custom rendering, providing a Shape implementation was relatively easy but at the same time none-trivial. This is why I think it is best to share this addition with everyone.

Description

  • Concave/convex semicircle shaped endings
  • Nearly exact API as DefaultSlice except doesn't accept BorderStroke
  • Gaps can lead to negative sweep angles which cause rendering issues; only rendering positive angles

The following screenshot illustrates the basic thought behind this feature.

rounded_sliced_piechart

Current limitations

To reduce mental load, I'm using 3 distinct paths which are finally combined with addPath. This however treats them as 3 seperate paths, which causes issues when BorderStroke is applied, which is why I decided to abandon this for the moment.

- Concave/convex semicircle shaped endings
- Nearly exact API as DefaultSlice except doesn't accept BorderStroke
- Gaps can lead to negative sweep angles which cause rendering issues; only rendering positive angles
@postfixNotation
Copy link
Copy Markdown
Contributor Author

Ohhh, I just saw there's a copyright tag in the source code which originates from my default Android Studio settings. I'll remove this in a few minutes.

Copy link
Copy Markdown
Member

@gsteckman gsteckman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Please run detekt and correct any code style errors it finds. Expanding on hover does not produce a nice effect, in my opinion...maybe it should be disabled for this type of slice shape? Another option could be to make it thicker on hover. That might look ok, given a big enough hole size.

Comment thread src/commonMain/kotlin/io/github/koalaplot/core/pie/PieChartShapes.kt Outdated
- adding gap argument comment
- extracting inner circle sweep angle constant
- slices don't expand on hover event
- fixing detekt's argument number constraint by introducing parameter data classes
- gap cannot be negative `require` constraint
@postfixNotation
Copy link
Copy Markdown
Contributor Author

Thanks for the contribution. Please run detekt and correct any code style errors it finds. Expanding on hover does not produce a nice effect, in my opinion...maybe it should be disabled for this type of slice shape? Another option could be to make it thicker on hover. That might look ok, given a big enough hole size.

  • Fixed all detekt related issues.
  • I totally agree with your argument with respect to hovering. I removed it since I don't see an appealing alternative. All slices except the last one are drawn below the consecutive one which makes it look weird.
concave-convex-hover

Copy link
Copy Markdown
Member

@gsteckman gsteckman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@gsteckman gsteckman merged commit 70e1bee into KoalaPlot:main Aug 30, 2025
1 check passed
@postfixNotation postfixNotation deleted the contribution/piechartshapes-roundedslices branch October 29, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants