Last active
August 29, 2015 14:11
-
-
Save 1wheel/97e538c098e1a310224e to your computer and use it in GitHub Desktop.
d3.scale.category20() randomizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//paste in the console to swap out the d3.scale.category20() pallet | |
var oldColors = oldColors ? oldColors : d3.scale.category20().range() | |
var newColors = oldColors.map(function(){ | |
return '#'+Math.floor(Math.random()*16777215).toString(16) }) | |
oldColors.forEach(function(str, i){ | |
//update inline color style | |
d3.selectAll('[style*="' + str + '"]') | |
.style('fill', newColors[i]) | |
.style('background-color', newColors[i]) | |
//update fill attr | |
d3.selectAll('[fill*="' + str + '"]') | |
.attr('fill', newColors[i]) | |
}) | |
//save new pallet - press up arrow and enter to run again | |
oldColors = newColors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://bl.ocks.org/mbostock/raw/4341574/
http://bl.ocks.org/mbostock/raw/7881887/