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
| const regionsNamesById = {}; | |
| nestByRegionId.forEach(item => { | |
| regionsNamesById[item.key] = item.values[0].regionName; | |
| }); | |
| const regions = {}; | |
| d3.map(data, d => d.regionId) | |
| .keys() |
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
| const legendContainer = d3.select('.legend'); | |
| const chunkedRegionsIds = chunkHelper(regionsIds, 3); | |
| const legends = legendContainer.selectAll('div.legend-column') | |
| .data(chunkedRegionsIds) | |
| .enter() | |
| .append('div') | |
| .attr('class', 'legend-column') | |
| .selectAll('div.legend-item') | |
| .data(d => d) |
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
| function clickLegendHandler(regionId) { | |
| regions[regionId].enabled = !regions[regionId].enabled; | |
| redrawChart(); | |
| } |
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
| function redrawChart() { | |
| const enabledRegionsIds = regionsIds.filter(regionId => regions[regionId].enabled); | |
| const paths = svg | |
| .selectAll('.line') | |
| .data(enabledRegionsIds); | |
| paths.exit().remove(); | |
| paths |
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
| const voronoi = d3.voronoi() | |
| .x(d => x(d.date)) | |
| .y(d => y(d.percent)) | |
| .extent([[0, 0], [width, height]]); | |
| const voronoiGroup = svg.append('g') | |
| .attr('class', 'voronoi-parent') | |
| .append('g') | |
| .attr('class', 'voronoi'); |
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
| const filteredData = data.filter(dataItem => enabledRegionsIds.indexOf(dataItem.regionId) >= 0); | |
| const voronoiPaths = voronoiGroup.selectAll('path') | |
| .data(voronoi.polygons(filteredData)); | |
| voronoiPaths.exit().remove(); | |
| voronoiPaths | |
| .enter() | |
| .append('path') |
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
| function voronoiMouseover(d) { | |
| d3.select(`#region-${ d.data.regionId }`).classed('region-hover', true); | |
| } | |
| function voronoiMouseout(d) { | |
| d3.select(`#region-${ d.data.regionId }`).classed('region-hover', false); | |
| } | |
| function voronoiClick(d) { | |
| if (singleLineSelected) { |
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
| const legendsValues = legends.append('div') | |
| .attr('class', 'legend-value'); | |
| const legendsDate = d3.selectAll('.legend-column') | |
| .append('div') | |
| .attr('class', 'legend-date'); |
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
| const nestByDate = d3.nest() | |
| .key(d => d.date) | |
| .entries(data); | |
| const percentsByDate = {}; | |
| nestByDate.forEach(dateItem => { | |
| percentsByDate[dateItem.key] = {}; | |
| dateItem.values.forEach(item => { |
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
| function voronoiMouseover(d) { | |
| legendsDate.text(timeFormatter(d.data.date)); | |
| legendsValues.text(dataItem => { | |
| const value = percentsByDate[d.data.date][dataItem]; | |
| return value ? value + '%' : 'Н/Д'; | |
| }); | |
| d3.select(`#region-${ d.data.regionId }`).classed('region-hover', true); |