I need to attach text labels to objects that are spread randomly across the screen and keep moving.
The default and ideal position for a label is on the right side of the object it refers to. I need a way to dynamically rearrange (or possibly merge) the labels so that they never overlap each other or other objects.
They should still be as close to the objects as possible and should not, provided that the objects themselves move smoothly, show any suddent jerky movement.
I have no idea how to do it, is there an algorithm for something like this?
I would suggest using physics. Attach the label to the object with a spring and apply a repelling force to every label so they avoid getting close to other objects (and their labels), excluding the one they describe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With