chart = {
var stage = 0
var turnstile_data_1 = turnstile_data.slice(0, 7);
var turnstile_data_2 = turnstile_data.slice(6,14);
var turnstile_data_3 = turnstile_data.slice(13,20);
var turnstile_data_4 = turnstile_data.slice(19,);
function transition(path) {
path.transition()
.duration(2500)
.attrTween("stroke-dasharray", tweenDash)
.on("end", () => {
d3.select(this).call(transition);
svg.selectAll('.text-box')
.text(setText(stage))
});
}
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("overflow", "visisble");
svg.append("g")
.attr("transform", "translate(0, " + (height - margin.top -10) + ")")
.call(d3.axisBottom(x_covid));
svg.append("g")
.attr("transform", "translate(" + (margin.left) + ",0)")
.attr('style', 'font-size: 7px')
.call(d3.axisLeft(y));
svg.append("image")
.attr("xlink:href", "https://cdn.onlinewebfonts.com/svg/img_70339.png")
.attr("width", 30)
.attr("height", 30)
.attr('x', height-350)
.attr('y', margin.top)
.on("click", function(d) {
stage += 1
var next_data;
if (stage == 1){
next_data = turnstile_data_1
}
if (stage == 2){
next_data = turnstile_data_2
}
if (stage == 3){
next_data = turnstile_data_3
}
if (stage == 4){
next_data = turnstile_data_4
}
svg.append('path')
.datum(next_data)
.attr("fill", "none")
.attr("stroke", "#7c1e84")
.attr("stroke-width", 1.5)
.attr("d", line)
.call(transition);
})
svg.append("text")
.attr('class', 'text-box')
.attr("x", height-310)
.attr("y", margin.top + 10)
.attr('style', 'font-size: 10px')
.append("tspan")
.text(setText(stage)[0])
.append("tspan")
.text(setText(stage)[1])
.attr("x", height-310)
.attr("dy", 22)
.append("tspan")
.text(setText(stage)[2])
.attr("x", height-310)
.attr("dy", 22)
return svg.node();
}