-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Allow PieChartView to hide labels for tiny slices #944
Conversation
@@ -25,6 +25,7 @@ public class PieChartView: PieRadarChartViewBase | |||
private var _circleBox = CGRect() | |||
|
|||
private var _drawXLabelsEnabled = true | |||
private var _drawXLabelsMinimumAngle: Double = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CGFloat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I could have sworn that I used a Double
here for a reason, but I can't remember that reason now, so I've switched it to a CGFloat
.
This is not a good solution, as some big slices have short x value string(should display), and some small slice have long x value (should hide), a specific value of angle could not determine this. |
@DingSoung I would say "it's not the perfect solution", not necessarily not a "good" one. |
@danielgindi Do you have any recommendations on how to make it more magic? I did try a few solutions that were more intricate, but in the end I thought it was best to keep this simple. (For my purposes, the most important thing was to hide the labels for a series of extremely small slices, each around 1% of the pie or less – they were all showing up on top of each other in a garbled mess. Not sure how common that is for other people.) A few things I considered:
Let me know if you have thoughts on any of those possibilities! |
@danielgindi @rofreg step:
2 in drawValues of PieChartRenderer, check before draw, example
I do this in subClass and used particular configuration, some more need be considered (with hole or not, show y value or not etc.) |
@DingSoung
We could potentially do more advanced math to figure out the actual maximum size (calculating the largest box that could fit in the center of the pie slice, then hiding the label if it doesn't fit in that box), but that seemed like overkill to me, at least for the application where I used this code. The main goal I wanted to achieve was to hide labels for insignificant pie slices (e.g. sections that only make up 1% of the pie), in order to filter out "less important" parts of the data set and highlight the larger pie slices. |
I'm closing this in favor of #2062, which appears to reimplement the same improvements in Swift 3. |
Right now, if you have a labelled pie chart with a large number of tiny sections, the labels are very likely to overlap in a visually unappealing way. This commit adds a basic property to auto-hide labels for any pie chart section below a certain size – e.g. only show pie chart labels for pie sections that span at least 20º.
I also updated the color of the labels in the PieChart demo from white to black for legibility.
Before:
After: