vis = {
const width = 800;
const height = 200;
const margin = { top: 0, right: 20, bottom: 20, left: 40 };
const axisColor = "#404040";
const svg = d3
.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
const x = d3
.scaleBand()
.domain(df.map((d) => d.year))
.range([margin.left, width])
.padding(0.2);
const y = d3
.scaleLinear()
.domain([0, d3.max(df, (d) => d.population)])
.range([height, margin.top]);
const xAxisGroup = svg
.append("g")
.attr("transform", `translate(0, ${height})`)
.call(d3.axisBottom(x).tickSize(0));
const yAxisGroup = svg
.append("g")
.attr("transform", `translate(${margin.left}, 0)`)
.call(d3.axisLeft(y).tickSize(0));
const dur = 450
svg
.append("g")
.attr("id", "bars")
.selectAll("rect")
.data(df)
.join("rect")
.attr("width", x.bandwidth())
.attr("height", (d) => height - y(d.population))
.attr("y", (d) => y(d.population))
.attr("x", (d) => x(d.year))
.attr("fill", "lightgray")
.transition()
.duration(dur)
.delay((d, i) => i * dur)
.ease(d3.easeBounceOut)
.attr("y", d => barY(d.population))
.attr("height", d => barHeight - barY(d.population));
xAxisGroup
.append("text")
.attr("x", (width - margin.left) / 2)
.attr("y", margin.bottom - 0)
.attr("text-anchor", "middle")
.attr("font-size", 10)
.attr("font-family", "sans-serif")
.attr("fill", axisColor)
.text("Year");
return svg.node();
}