Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
d3.scale.category20() randomizer
//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
@1wheel

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment