chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg.node().update = currLabel => {
const labeled = chart_data.filter(d => d.label == currLabel);
const circles = svg
.selectAll("circle")
.data(chart_data, d => d.id)
.join(enter =>
enter
.append("circle")
.attr("cx", d => x(d.x))
.attr("cy", y.range()[0])
)
.transition()
.delay(d => x(d.x))
.attr("cx", d => x(d.x))
.attr("cy", d => y(d.y))
.attr("r", d => (d.label == currLabel || currLabel.length == 0 ? 2 : 0))
.style("fill", function(d) {
var content = d.label;
if (content === "neutral or dissatisfied") {
return "red";
} else {
return "green";
}
})
.style("opacity", 0.5);
};
svg
.append("text")
.attr(
"transform",
`translate(${margin.left + (x.range()[1] - x.range()[0]) / 2},${height})`
)
.style("text-anchor", "middle")
.text("title");
return svg.node();
}