Built with blockbuilder.org
Last active
May 1, 2017 21:39
-
-
Save sxywu/533cece25dffcf3744da1e2d29653673 to your computer and use it in GitHub Desktop.
Color scale
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
license: mit |
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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script> | |
<script src="https://npmcdn.com/babel-core@5.8.34/browser.min.js"></script> | |
<script type="text/javascript" src="https://cdn.rawgit.com/gka/chroma.js/master/chroma.min.js"></script> | |
<style> | |
svg { | |
width: 800px; | |
height: 800px; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
<script> | |
var blue = '#51aae8'; | |
var pink = '#e68fc3'; | |
var orange = '#f7cd83'; | |
var green = '#55e851'; | |
var violet = '#a651e8'; | |
var red = '#e85151'; | |
var yellow = '#f7e883'; | |
var red2 = '#e85178'; | |
var colors = chroma | |
.scale([red, orange, yellow, green, blue, violet, pink, red2]).colors(36); | |
var svg = d3.select('svg'); | |
var perRow = 6; | |
var size = 100; | |
var g = svg.selectAll('g') | |
.data(colors).enter().append('g') | |
.attr('transform', (d, i) => { | |
var x = (i % perRow + 1) * size; | |
var y = (Math.floor(i / perRow) + 1) * size; | |
return 'translate(' + [x, y] + ')'; | |
}).attr('fill', d => d); | |
g.append('circle') | |
.attr('r', size / 4); | |
g.append('text') | |
.attr('y', size / 4 + 15) | |
.attr('text-anchor', 'middle') | |
.attr('dy', '.35em') | |
.text((d, i) => d); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment