Last active
October 14, 2018 11:05
-
-
Save ialarmedalien/e3157b48b3ef624d2574 to your computer and use it in GitHub Desktop.
d3.form.element.colorbrewer
This file contains hidden or 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
license: mit |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>d3.form.element.colorbrewer.js</title> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/colorbrewer@1/colorbrewer.min.css"> | |
<script src="https://cdn.jsdelivr.net/combine/npm/colorbrewer@1/colorbrewer.min.js,npm/d3@3"></script> | |
<script src="https://cdn.jsdelivr.net/npm/colorbrewer@1/colorbrewer.min.js"></script> | |
<script src="https://rawgit.com/ialarmedalien/d3.chart.img/master/src/d3.form.element.colorbrewer.js"></script> | |
<meta charset="UTF-8"> | |
<style> | |
#palette svg { | |
width: 100%; | |
height: 40px; | |
} | |
#palette rect { | |
width: 30px; | |
height: 30px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<p>A select element offering access to <a href="http://colorbrewer2.org">colorbrewer palettes</a> using the colorbrewer library shipped with <a href="https://github.com/mbostock/d3">d3.js</a>. For consistency, only colorbrewer schemes with nine variations or greater are included. Colours are added using css, rather than the customary fills.</p> | |
<div id="palette"></div> | |
<div id="select"></div> | |
</div> | |
<script> | |
var p = d3.select("#palette") | |
.append('svg') | |
.append('g') | |
.attr("transform", function(d) { return "translate(" + 5 + "," + 5 + ")"; }) | |
.classed('YlGn', true) | |
, cbc = new ColorBrewerControl(colorbrewer); | |
p.selectAll('rect') | |
.data( d3.range(9) ) | |
.enter().append("rect") | |
.attr("class", function(d){ return 'q' + d + '-9' }) | |
.attr('x', function(d,i){ return 30 * i }) | |
.text(function(d){ return d; } ); | |
cbc.add_colorbrewer_control({ el:'#select', id: "colors_select" }) | |
.on('change', function(){ | |
p.attr( 'class', this.value ); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment