chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg.append('text').call(xLabel);
svg.append('text').call(yLabel);
svg
.selectAll("circle")
.data(chart_data, d => d.id)
.join("circle")
.attr("r", d => {
return d.group === search_value ? 15 : 3;
})
.attr("cx", d => x(d.x))
.attr("cy", d => y(d.y))
.style("fill", d => {
return d.group === search_value ? "red" : "blue";
});
svg
.selectAll("path")
.data(line_data)
.join("path")
.attr('id', (d, i) => 'line-' + i)
.attr("d", d => lineGenerator(d.value))
.attr("stroke-dasharray", (d, i) => {
if (d3.select('#line-' + i).node() !== null) {
const length = d3
.select('#line-' + i)
.node()
.getTotalLength();
return length + " " + length;
}
})
.attr("stroke-dashoffset", (d, i) => {
if (d3.select('#line-' + i).node() !== null) {
const length = d3
.select('#line-' + i)
.node()
.getTotalLength();
return length;
}
return 1;
})
.style("fill", "none")
.attr("stroke-width", "1px")
.attr("stroke", "black")
.transition()
.delay((d, i) => i * 50)
.duration(3000)
.attr("stroke-dashoffset", 0);
return svg.node();
}