A quick visual reference to every ColorBrewer scale; colors by Cynthia Brewer. Available in CSS and JS format. Click on a palette to log the constituent colors in hexadecimal RGB to the console.
forked from mbostock's block: Every ColorBrewer Scale
xxxxxxxxxx
<meta charset="utf-8">
<style>
body {
background: #ccc;
width: 960px;
height: 500px;
}
.palette {
cursor: pointer;
display: inline-block;
vertical-align: bottom;
margin: 4px 0 4px 6px;
padding: 4px;
background: #fff;
border: solid 1px #aaa;
}
.swatch {
display: block;
vertical-align: middle;
width: 37px;
height: 22px;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="colorbrewer.min.js"></script>
<script>
d3.select("body")
.selectAll(".palette")
.data(d3.entries(colorbrewer))
.enter().append("span")
.attr("class", "palette")
.attr("title", function(d) { return d.key; })
.on("click", function(d) {
//console.log(d3.values(d.value).map(JSON.stringify).join("\n"));
console.log(d3.keys(d.value).map(Number).sort(d3.descending)[0])
})
.selectAll(".swatch")
.data(function(d) {
var array = d.value[d3.keys(d.value).map(Number).sort(d3.descending)[0]];
array.forEach(function(a,i) {
array[i] = {v: a, array: array }
})
array.dir = Math.floor(Math.random() * 2 - 1);
array.offset = Math.floor(Math.random() * array.length -1);
console.log("ARRAY", array)
return array; })
.enter().append("span")
.attr("class", "swatch")
.style("background-color", function(d,i) { return d.array[(i)%d.array.length].v; });
d3.timer(function(elapsed) {
var el = elapsed / 150;
d3.selectAll("span.swatch")
.style("background-color", function(d,i) {
//var dir = d.array.dir;
//if(!dir) dir = 1;
dir = 1;
var j = Math.floor((i+el*dir+d.array.offset)%d.array.length)
//if(j < 0) j = d.array.length - 1;
//console.log(d, i, j);
return d.array[j].v; });
return false;
})
</script>
https://d3js.org/d3.v3.min.js