chart = {
const svg = d3.create('svg')
.attr('width', width)
.attr('height', height)
.attr('font-family', 'sans-serif')
.call(xAxis)
.call(labels);
return Object.assign(svg.node(), {
update(data) {
svg.selectAll('.date-bin')
.data(data, d => d[0])
.join('g')
.attr('class', 'date-bin')
.attr('transform', d => `translate(${xScale(new Date(d[0]))}, ${height / 2})`)
.selectAll('.date-bin-group')
.data(d => d[1], d => d[0])
.join('g')
.attr('class', 'date-bin-group')
.attr('transform', d => `translate(0, ${15 * (d[0] ? 1 : -1 )})`)
.selectAll('.event')
.data(d => d[1], d => d.uid)
.join(
enter => enter.append('circle')
.attr('fill', d => d3.schemeTableau10[d.category])
.attr('r', 4)
.attr('cx', 0)
.attr('cy', 0)
.attr('class', 'event')
.attr('transform', (d, i, nodes) => `translate(0, ${i * 10 * (d.position ? 1 : -1)})`)
.call(el => el.attr('opacity', 0)
.transition().duration(200)
.attr('opacity', 1)),
update => update
.call(els => els.transition().duration(200)
.attr('transform', (d, i, nodes) => `translate(0, ${i * 10 * (d.position ? 1 : -1)})`)),
exit => exit.remove());
}
});
}