Skip to content

Instantly share code, notes, and snippets.

@levvsha
Created June 21, 2018 07:33
Show Gist options
  • Select an option

  • Save levvsha/65fa45eb9cc486a6710405ef5b94fc52 to your computer and use it in GitHub Desktop.

Select an option

Save levvsha/65fa45eb9cc486a6710405ef5b94fc52 to your computer and use it in GitHub Desktop.
const legendContainer = d3.select('.legend');
const legends = legendContainer
.append('svg')
.attr('width', 150)
.attr('height', 353)
.selectAll('g')
.data(regionsIds)
.enter()
.append('g')
.attr('class', 'legend-item')
.attr('transform', (regionId, index) => `translate(0,${ index * 20 })`)
.on('click', clickLegendHandler);
legends.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', 12)
.attr('height', 12)
.style('fill', regionId => colorScale(regionId))
.select(function() { return this.parentNode; })
.append('text')
.attr('x', 20)
.attr('y', 10)
.text(regionId => regionsNamesById[regionId])
.attr('class', 'textselected')
.style('text-anchor', 'start')
.style('font-size', 12);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment