Skip to content

Instantly share code, notes, and snippets.

@alyssaq
Forked from mbostock/.block
Last active October 20, 2015 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alyssaq/020ee317c6979fabb10a to your computer and use it in GitHub Desktop.
Save alyssaq/020ee317c6979fabb10a to your computer and use it in GitHub Desktop.
Spectual Color Scale
var colorbrewer =
{
Spectral:{
3:[
"#fc8d59",
"#ffffbf",
"#99d594"
],
4:[
"#d7191c",
"#fdae61",
"#abdda4",
"#2b83ba"
],
5:[
"#d7191c",
"#fdae61",
"#ffffbf",
"#abdda4",
"#2b83ba"
],
6:[
"#d53e4f",
"#fc8d59",
"#fee08b",
"#e6f598",
"#99d594",
"#3288bd"
],
7:[
"#d53e4f",
"#fc8d59",
"#fee08b",
"#ffffbf",
"#e6f598",
"#99d594",
"#3288bd"
],
8:[
"#d53e4f",
"#f46d43",
"#fdae61",
"#fee08b",
"#e6f598",
"#abdda4",
"#66c2a5",
"#3288bd"
],
9:[
"#d53e4f",
"#f46d43",
"#fdae61",
"#fee08b",
"#ffffbf",
"#e6f598",
"#abdda4",
"#66c2a5",
"#3288bd"
],
10:[
"#9e0142",
"#d53e4f",
"#f46d43",
"#fdae61",
"#fee08b",
"#e6f598",
"#abdda4",
"#66c2a5",
"#3288bd",
"#5e4fa2"
],
11:[
"#9e0142",
"#d53e4f",
"#f46d43",
"#fdae61",
"#fee08b",
"#ffffbf",
"#e6f598",
"#abdda4",
"#66c2a5",
"#3288bd",
"#5e4fa2"
]
}
};
<!DOCTYPE html>
<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="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.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")); })
.selectAll(".swatch")
.data(function(d) { return d.value[d3.keys(d.value).map(Number).sort(d3.descending)[0]]; })
.enter().append("span")
.attr("class", "swatch")
.style("background-color", function(d) { return d; });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment