Created
November 23, 2012 19:02
-
-
Save ejfox/4136856 to your computer and use it in GitHub Desktop.
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
# Color interpolation | |
A simple example of color interpolation. I personally prefer HSL, but RGB is commented out if you'd like to us it instead. |
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
n = 66 | |
var color = d3.scale.linear() | |
.domain([0, n]) | |
.interpolate(d3.interpolateRgb) | |
//.interpolate(d3.interpolateHsl) | |
.range(['#D40067', '#278ECA']) | |
// Example Code | |
height = 224 | |
data = d3.range(n); | |
var svg = tributary.g; | |
svg.selectAll("rect") | |
.data(data) | |
.enter() | |
.append("rect") | |
.attr({ | |
x: 0, | |
y: function(d,i){ | |
return i*((height/n)+1) | |
}, | |
width: 390, | |
height: height/n, | |
fill: function(d,i){ | |
return color(i) | |
}, | |
opacity: 1, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment