I'm adding labels to an angular meter using BaseMeter.addLabel. I also want to add some other text using BaseMeter.addText, but I need to make sure that the text does not overlap the labels. In my application, the end user can change the size and font of both the labels and the text, and can resize the meter as well, so I have to calculate the position of the added text at runtime.
I can get the size of each label box by making a dummy call to addText, but how can I get the exact position? I'm approximating at the moment with a call to getCoor and some trigonometry, but this is just an approximation, and testing shows that it isn't correct in all cases.
Is there a way that I can get the exact position of the box for each label?
Unluckily, there is no API to get back the position and size of the labels. Internally, ChartDirector computes the position and size when it actually needs to draw the labels on the image, but it will not store the results.
The starting point of the label position is computed using trigonometry. It is then adjusted using some experimentally determined algorithm based on our testing of human perception. It will consider the angle, number of characters in the text, the size of the label and the tick length and label gap, etc.. We can change and tune the algorithm in future versions of ChartDirector.
May be you can consider to use some other methods, such as to simply add a small mark to the meter and add a "legend box" somewhere to indicate what the mark means. If the added text is important, it may have a semi-transparent background color so that it is readable even if it overlaps with the other parts of the label.