chart = {
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const setValues = (sel, field = 'start') =>
sel
.attr("cx", d => d[field][0])
.attr("cy", d => d[field][1])
.attr("r", d => d[field][2])
.attr('stroke-width', d => d[field][3])
.attr('stroke', d => d[field][4])
.attr("fill", d => d[field][5])
const team = svg
.selectAll("circle.team")
.data(teams)
.join("circle")
.attr('class', 'elem team')
.call(setValues, 'start');
const stepVertical = ([x0, y0, x1, y1]) => `M${x0},${y0}V${(y0 + y1) / 2}H${x1}V${y1}`
const link = svg
.selectAll("path.link")
.data(links)
.join("path")
.attr('class', 'elem link')
.attr('stroke', '#000000')
.attr('stroke-width', 3)
.attr('d', (d) => stepVertical([d.start[0], d.start[1], d.finish[0], d.finish[1]]));
const role = svg
.selectAll("circle.role")
.data(roles)
.join("circle")
.attr('class', 'elem role')
.call(setValues, 'start');
const animate = (sel, field = 'start') => {
const t = selection.transition().duration(2000);
sel
.transition(t)
.call(setValues, field)
.on('end', () => sel.call(animate, field === 'start' ? 'finish' : 'start'))
}
const selection = svg.selectAll(".elem");
selection.call(animate);
return svg.node();
}