Skip to content

Instantly share code, notes, and snippets.

@levvsha
Last active February 4, 2018 14:00
Show Gist options
  • Save levvsha/22271fe3d5ab8a79114dbe099a28ae54 to your computer and use it in GitHub Desktop.
Save levvsha/22271fe3d5ab8a79114dbe099a28ae54 to your computer and use it in GitHub Desktop.
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