Created
February 6, 2014 23:48
-
-
Save oshikryu/8854900 to your computer and use it in GitHub Desktop.
renders a legend given a quantile scale of colors
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
@colorScale = d3.scale.quantile() | |
.domain([0, .01, .1, .2, .3, .5, .8, 1.3, 2.1, 3.3]) | |
.range(@colors) | |
_renderLegend: -> | |
# quantizes colors and adds an extra 0 | |
_legendData = [0].concat(@colorScale.quantiles()) | |
_legendData.unshift(0) | |
_legendGroup = @svg | |
.append('g') | |
.attr('class', 'legend') | |
.attr('transform', 'translate(' + (@margin/2) + ',' + (@gridHeight - @margin*2) + ')') | |
_legend = _legendGroup | |
.append('svg') | |
.attr('height', @margin * 2) | |
.attr('width', @gridWidth) | |
_key = _legend.selectAll('.key') | |
.data(_legendData) | |
.enter().append('g') | |
.attr('class', 'key') | |
_key.append('rect') | |
.attr('x', (d, i) => ((@gridSize * 3 * i) ) + @xTwiddle) | |
.attr('y', @margin) | |
.attr('width', @cellSize * 2) | |
.attr('height', 10) | |
.attr('class', 'hour') | |
.attr('class', (d, i) => return if i == 0 then 'invalid' else 'bordered' ) | |
.style('fill', (d, i) => return if i == 0 or i == 1 then "#ffffff" else @colors[i] ) | |
_key.append('text') | |
.attr('x', (d, i) => ((@gridSize * 3 * i) ) + @xTwiddle) | |
.attr('y', @margin - @yTwiddle) | |
.text( (d, i) -> return if i == 0 then 'NaN' else "≤#{ (d).toString().substring(0, 4)} " ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment