chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg.append("g").call(grid);
svg.append("g").call(credit);
const data_init = dataAt(config.start_year);
const line_init = linedataAt(config.start_year);
const path = svg
.append("g")
.attrs({
fill: "none",
"stroke-width": 2,
"stroke-linejoin": "round",
"stroke-linecap": "round"
})
.selectAll("path")
.data(line_init, d => d[0])
.join("path")
.style("mix-blend-mode", "multiply")
.attr("stroke", d => color(d[1][0][columns.c]))
.attr("stroke-opacity", d => (config.line_ids.includes(d[0]) ? 0.5 : 0))
.attr("d", d => line(d[1]));
const circle = svg
.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(data_init, d => d[columns.id])
.join("circle")
.sort((a, b) => d3.descending(a[columns.r], b[columns.r]))
.attr("cx", d => x(d[columns.x]))
.attr("cy", d => y(d[columns.y]))
.attr("r", d => radius(d[columns.r]))
.attr("fill", d => color(d[columns.c]))
.attr("fill-opacity", d =>
config.highlightcircles ? (isHighlight(d) ? 1 : 0.65) : 1
)
.call(circle =>
circle
.append("title")
.text(d => [d[columns.a1], d[columns.a2]].join("\n"))
);
const labels = svg
.append("g")
.selectAll("text")
.data(data_init, d => d[columns.id])
.join("text")
.sort((a, b) => d3.descending(a[columns.r], b[columns.r]))
.attr("x", d => x(d[columns.x]))
.attr("y", d => y(d[columns.y]))
.text(d => (isHighlight(d) ? d[columns.a2] : d[columns.id]))
.attr("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("dy", "0.3em")
.attr("pointer-events", "none")
.attr("font-weight", d => (isHighlight(d) ? 'bold' : 'normal'))
.attr("font-size", d => config.label_size + (isHighlight(d) ? 2 : 0));
const year_text = svg
.append("g")
.attr(
"transform",
`translate(${width - margin.right}, ${height - margin.bottom})`
)
.attr("text-anchor", "end")
.append("text")
.attr("dy", -35)
.attr("dx", -10)
.attr("font-size", 88)
.attr("fill", "lightgray")
.attr("font-weight", 500)
.attr("font-family", "sans-serif");
return Object.assign(svg.node(), {
update(data, linedata) {
circle
.data(data, d => d[columns.id])
.sort((a, b) => d3.descending(a[columns.r], b[columns.r]))
.attr("cx", d => x(d[columns.x]))
.attr("cy", d => y(d[columns.y]))
.attr("r", d => radius(d[columns.r]));
labels
.data(data, d => d[columns.id])
.sort((a, b) => d3.descending(a[columns.r], b[columns.r]))
.attr("x", d => x(d[columns.x]))
.attr("y", d => y(d[columns.y]))
.text(d => (isHighlight(d) ? d[columns.a2] : d[columns.id]));
path.data(linedata, d => d[0]).attr("d", d => line(d[1]));
year_text.text(`${Math.floor(data[0].year)}`);
}
});
}