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 12 - freakOut function in each() #51

Open ialsjbn opened 1 year ago

ialsjbn commented 1 year ago

The original code for freakout() has:

var colors = d3.schemeCategory20;
var colorIndex = Math.round(Math.random() *20);

For D3v5 and newer:

D3 no longer provides the d3.schemeCategory20* categorical color schemes. These twenty-color schemes were flawed because their grouped design could falsely imply relationships in the data: a shared hue can imply that the encoded data are part of a group (a super-category), while relative lightness can imply order

To get it to work, I changed it to:

var colors = d3.schemeCategory10;
var colorIndex = Math.round(Math.random() *10);
scotthmurray commented 1 year ago

Thanks @ialsjbn! I'm keeping this issue open, but filing it away in the event of a v5+ update for the book.