susielu / d3-legend

A reusable d3 legend component.
http://d3-legend.susielu.com/
Apache License 2.0
727 stars 104 forks source link

Legend Size Scales By Radius, Not Area #53

Closed jeffcatania closed 7 years ago

jeffcatania commented 7 years ago

Hi Susie,

Awesome library. Definitely simplifies my life quite a bit.

There seems to be a bug with the implementation of the d3.legendSize() computations, as per Tufte's data-ink ratio.

If you take the circles example, you can see the computed radius mappings are 5.0->20px and 10.0->30px.

screen shot 2017-03-09 at 3 47 39 pm

For the purposes of simplifying the mapping, I will assume that the scale should be zeroed (where 0->0px, 5.0->10px, 10.0->20px). According to Tufte's data-ink theory, the entire area of each circle should scale linearly. However, in the rendered example 5.0->10px radius->100 sq px area and 10.0->20px radius->400 sq. px area. As you can see, double the radius is 4x the area. 5.0 should be mapped to 14px radius if the radius of 10.0->20px.

This bug affects rects as well.

curran commented 7 years ago

@jeffcatania This seems to be localized to the scale that's passed into the legend rendering in the example, not the legend rendering itself. The solution would be to use a sqrt scale for radius and rect size where the range starts at zero, so the area is always proportional to the quantity.

susielu commented 7 years ago

@jeffcatania yes I agree with @curran here (thanks for the follow up). The assumption is that you would use a sqrt scale in the case. I will update the documentation so it is a better example, but yes it's just dependent on the scale you send it.

jeffcatania commented 7 years ago

Awesome. Thanks for the help!