chart = {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height])
.attr("style", "max-width: 100%; height: auto; height: intrinsic;")
.attr("font-family", "sans-serif")
.attr("font-size", 10);
const startGroup = svg.append("g").attr("transform", `translate(300,0)`);
startGroup
.append("text")
.attr("text-anchor", "end")
.attr("y", height - 10)
.attr("font-weight", 700)
.text(d3.timeFormat("%B %d, %Y")(startDate));
for (var i = 0; i < connections.length; i++) {
const d = connections[i];
startGroup
.append("line")
.attr("stroke", "black")
.attr("opacity", d.name == "Croatia" ? 1 : 0.1)
.attr("x1", 0)
.attr("x2", 300)
.attr("y1", y(d.start))
.attr("y2", y(d.end));
}
for (var i = 0; i < start.length; i++) {
const d = start[i];
startGroup
.append("circle")
.attr("r", 3)
.attr("cx", 0)
.attr("opacity", d.name == "Croatia" ? 1 : 0.1)
.attr("cy", y(d.rate));
startGroup
.append("text")
.attr("alignment-baseline", "middle")
.attr("dx", -5)
.attr("y", y(d.rate))
.attr("stroke-linejoin", "round")
.attr("stroke-width", 5)
.attr("text-anchor", "end")
.attr("stroke", "white")
.text(`${d.name} ${d3.format(",.2r")(d.rate)}`);
startGroup
.append("text")
.attr("alignment-baseline", "middle")
.attr("dx", -5)
.attr("y", y(d.rate))
.attr("text-anchor", "end")
.attr("opacity", d.name == "Croatia" ? 1 : 0.2)
.text(`${d.name} ${d3.format(",.2r")(d.rate)}`);
}
const endGroup = svg.append("g").attr("transform", `translate(600,0)`);
endGroup
.append("text")
.attr("y", height - 10)
.attr("font-weight", 700)
.text(d3.timeFormat("%B %d, %Y")(new Date(2022, 0, 1)));
for (var i = 0; i < end.length; i++) {
const d = end[i];
endGroup
.append("circle")
.attr("r", 3)
.attr("cx", 0)
.attr("opacity", d.name == "Croatia" ? 1 : 0.1)
.attr("cy", y(d.rate));
endGroup
.append("text")
.attr("alignment-baseline", "middle")
.attr("dx", 5)
.attr("y", y(d.rate))
.attr("stroke-linejoin", "round")
.attr("stroke-width", 5)
.attr("stroke", "white")
.text(`${d.name} ${d3.format(",.2r")(d.rate)}`);
endGroup
.append("text")
.attr("alignment-baseline", "middle")
.attr("dx", 5)
.attr("y", y(d.rate))
.attr("opacity", d.name == "Croatia" ? 1 : 0.2)
.text(`${d.name} ${d3.format(",.2r")(d.rate)}`);
}
return svg.node();
}