scotthmurray / d3-book

Code examples for “Interactive Data Visualization for the Web”
http://d3book.com
Other
2.4k stars 1.79k forks source link

Chapter 6: wrong Circle area #10

Closed LeonardoGentile closed 9 years ago

LeonardoGentile commented 9 years ago

Hello, I'n not sure I should post this here, but I've found an error in the book.

Following along with the book at the chapter 6 (about the Scatterplot, page 109 of printed book) I read that the Area of a cirlce is A = pi*r^2 . Then we chose our area to be A = h - d[1] and I read that as a consequence the radius was supposed to be r = Math.sqrt(h - d[1]).

Shouldn't it be r = Math.sqrt((h - d[1]) / Math.PI) ?

scotthmurray commented 9 years ago

Thanks, @LeonardoGentile! Technically, yes, we should divide by π, but in practice, that just ends up scaling the value, just as dividing by any arbitrary number. That is, it would achieve the same result as not dividing by π, only it would be 3.14… times smaller. So then we'd have really tiny circles, and would need to scale those values back up again, for visual purposes.

The important part of the radius-area relationship (for our purposes) is the square (root) relationship.

If we cared about calculating the actual size of a specific circle, then π is important, but we care only about the relative areas of our circles, for purposes of graphical honesty.

That said, the example I have here on p. 109 in which circles are scaled in relationship to their y value is very confusing, because you would never do that in practice. I'm going to rewrite this one for the 2nd edition of the book. Thank you for calling it to my attention!

LeonardoGentile commented 9 years ago

Glad I could help :+1: