progressBar = {
const progress = 0.65;
const duration = 1000;
const svg = d3.create("svg")
.attr("width", 900)
.attr("height", 50);
const backgroundBar = svg.append("rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", "#ddd");
const progressBar = svg.append("rect")
.attr("width", 0)
.attr("height", "100%")
.attr("fill", "purple");
const percentageText = svg.append("text")
.attr("x", "50%")
.attr("y", "50%")
.attr("dy", ".3em")
.attr("text-anchor", "middle")
.attr("font-size", "20px")
.attr("fill", "white");
progressBar.transition()
.duration(duration)
.attr("width", `${progress * 100}%`);
percentageText.transition()
.duration(duration)
.tween("text", function() {
const interpolator = d3.interpolate(0, progress);
return function(t) {
const value = interpolator(t);
percentageText.text(`${Math.round(value * 100)}%`);
};
});
return svg.node();
}