On Thu, Mar 21, 2013 at 03:11:35PM -0700, marc fawzi wrote:
> The problem is that using path.centroid(d...) the labels for FL and LA
> are awkwardly positioned on the border of those states.
I'd recommend manually positioning labels that are awkwardly positioned
when using the centroid of a polygon. The problem with polygon
centroids is that they're not guaranteed to lie within the polygon (at
least for our definition of centroid: barycenter).
You should already correct the y-position slightly using the "dy"
attribute on your text, and use text-anchor="middle". But if the
polygon is a strange shape, e.g. L-shaped, it's quite likely the
centroid will be too close to a border, or might even lie outside of the
polygon.
Related: D3's polygon centroids are currently weighted by the lengths of
their line segments, not areas. The difference will not be noticeable
in most scenarios. Area-weighted centroids will arrive in a future
release:
https://github.com/mbostock/d3/pull/1011
--
Jason Davies,
http://www.jasondavies.com/