lines = svg => {
let chartG = svg
.append('g')
.attr('transform', `translate(${[height + 10, 300]})`);
let lineG = chartG.selectAll('path');
let pointG = chartG.selectAll('circle');
return idx => {
const filteredData = stackedLineData.map(d => ({
...d,
line: d.line.filter(t => t[0] <= idx),
point: d.line.find(t => t[0] == idx) || [0, 0]
}));
lineG = lineG
.data(filteredData, d => d.status)
.join(
enter =>
enter
.append('path')
.attr('test', d => console.log('enter:', d))
.attr('d', d => line(d.line))
.attr('fill', 'none')
.attr('stroke', d => statusToColor[d.status]),
update =>
update
.attr('test', d => console.log('update:', d))
.attr('d', d => line(d.line))
);
pointG = pointG
.data(filteredData, d => d.status)
.join(
enter =>
enter
.append('circle')
.attr('r', 2)
.attr('display', d => (d.point[1] ? null : 'none'))
.attr('fill', d => statusToColor[d.status])
.attr('cx', d => lineXScale(d.point[0]))
.attr('cy', d => lineYScale(d.point[1])),
update =>
update
.attr('display', d => (d.point[1] ? null : 'none'))
.attr('cx', d => lineXScale(d.point[0]))
.attr('cy', d => lineYScale(d.point[1]))
);
};
}