Last active
February 4, 2018 14:00
-
-
Save levvsha/22271fe3d5ab8a79114dbe099a28ae54 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
const nestByRegionId = d3.nest() | |
.key(d => d.regionId) | |
.sortKeys((v1, v2) => (parseInt(v1, 10) > parseInt(v2, 10) ? 1 : -1)) | |
.entries(data); | |
const regions = {}; | |
d3.map(data, d => d.regionId) | |
.keys() | |
.forEach((d, i) => { | |
regions[d] = nestByRegionId[i].values; | |
}); | |
const regionIds = Object.keys(regions); | |
const lineGenerator = d3.line() | |
.x(d => x(d.date)) | |
.y(d => y(d.percent)) | |
.curve(d3.curveCardinal); | |
svg | |
.selectAll('.line') | |
.data(regionIds) | |
.enter() | |
.append('path') | |
.attr('class', 'line') | |
.attr('id', regionId => `region-${ regionId }`) | |
.attr('d', regionId => lineGenerator(regions[regionId])) | |
.style('stroke', regionId => colorScale(regionId)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment