futuredapp / donut

Doughnut-like graph view capable of displaying multiple datasets with assignable colors
MIT License
546 stars 46 forks source link

Question: Any way to find midpoint of a section? #67

Closed hrafnthor closed 3 years ago

hrafnthor commented 3 years ago

First off all, thank you for this fantastic library and all the time and effort that you have put into it!

I've been looking into the possibility of adding optional drawables to each section, and specifically I've been trying for a while now to figure out a good way to find the midpoint coordinates of each painted section for the placement of the drawables but have been unable to find a reliable way to do so.

You wouldn't happen to have any pointers on how best to go about doing so?

matejsemancik commented 3 years ago

Hi! What kind of drawables are you looking to add to each section? Icons? As of now, the DonutProgressView does not provide any info on where the sections are drawn, so for now, my only advice would be to fork and try to implement the drawables by yourself, since the functionality you require is out of scope.

hrafnthor commented 3 years ago

Yes, I had already forked the library and started looking into adding drawables (i.e icons) that scale with the section widths, and would be drawn inside the sections.

I have most of it up and running, though my placement of the icons is not the most reliable (currently performing averaging of all points in the path to find the midpoint), and so simply wanted to reach out and see if you had any ideas. I'll keep at it then.

matejsemancik commented 3 years ago

Sorry, maybe I understood the question differently. Well, in that case I would go about looking at resolveState and getDrawAmountForLine which are private methods of DonutProgressView. Each line is drawn from start of the circle and lines are basically rendered on top of each other. You could use getDrawAmountForLine method to calculate where each section starts and ends to determine the line midpoints. The getDrawAmountForLine returns normalised value between 0f..1f which is then mapped to full circle length (from gap start to gap end).

hrafnthor commented 3 years ago

No worries! Thank you for the info, this will surely help me.