i'd automatically place 100-200 bubble labels following requirements met:
- labels should not overlap
- labels should preferably not overlap bubbles
- label should close bubble
- preferred label position (top left, top, bottom, right etc.) should respected extent
- font-size can vary
are there helpful libraries / algorithms this? (preferably javascript or php)
(the label placement in image not meet these requirements)
this can formulated linear programming problem. want maximize or minimize function (representing "weight" or "goodness" of solution) subject constraints (your requirements). you'll need formalize requirements values. this:
variables: x1 = 1 if labels overlap, 0 otherwise x2 = measure of "how much" label overlaps bubble x3 = distance label bubble //label should close bubble x4 = distance between ideal , actual label position x5 = difference between actual , ideal font size minimize x1 + 10*x2 + x3 + 20*x4 + 5*x5 subject constraints: x1 = 0 // labels can never overlap x2 < /* maximum amount label allowed overlap bubble */ ... x5 < 6 // font size not vary more +/- 6 pts.
i made coefficients , constraints, can use them tune result based on features important you. coefficients increase value of requirement (in case, f4
weighted 'most important'. constraints hard limits cannot violated.
since well-known problem, can solve using number of methods. simplex algorithm popular. there whole chapter in cormen et. al these problems.
Comments
Post a Comment