chart = {
const height = 500;
const margin = { top: 30, bottom: 30, left: 60, right: 30 };
const svg = d3.select(DOM.svg(width, height));
const xScale = d3
.scaleTime()
.domain([parseDate("1990"), parseDate("2021")])
.range([0 + margin.left, width - margin.right]);
const yScale = d3
.scaleLinear()
.domain([0, dataExtent[1]])
.range([height - margin.top, margin.bottom]);
const xAxis = (g) =>
g
.call(d3.axisBottom(xScale).ticks(10))
.call((g) => g.select(".domain").remove())
.call((g) => g.selectAll(".tick line").remove())
.call((g) =>
g
.selectAll(".tick text")
.style("font", "14px sans-serif")
.attr("fill", "black")
);
const yAxis = (g) =>
g
.call(
d3
.axisLeft(yScale)
.ticks(5)
.tickFormat((d) => d3.format(".1s")(d).toLowerCase())
)
.call((g) => g.select(".domain").remove())
.call((g) =>
g
.selectAll(".tick line")
.attr("x2", width - margin.right - margin.left)
.attr("stroke", "lightgray")
)
.call((g) =>
g
.append("text")
.attr("fill", "black")
.attr("x", 2)
.attr("y", margin.top / 2)
.attr("dy", "0.0em")
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.style("font", "20px sans-serif")
.text(`Sheep population over time in ${selectedValue}`)
)
.call((g) =>
g
.selectAll(".tick text")
.style("font", "14px sans-serif")
.attr("fill", "black")
);
svg
.append("g")
.attr("class", "x axis")
.attr("transform", `translate(0, ${height - margin.bottom})`)
.call(xAxis)
.selectAll("text")
.style("text-anchor", "middle")
.attr("dx", width / sheepProcessed.length / 2);
svg
.append("g")
.attr("class", "y axis")
.attr("transform", `translate(${margin.left},0)`)
.call(yAxis)
.selectAll("text");
svg
.append("g")
.selectAll("rect")
.data(sheepProcessed)
.enter()
.append("rect")
.attr("fill", "#E75A36")
.attr("stroke", "#FED69E")
.attr("x", (d) => xScale(d.date))
.attr("y", (d) => yScale(d.value))
.attr("height", (d) => yScale(0) - yScale(d.value))
.attr("width", width / (sheepProcessed.length + 3))
.attr("opacity", 1);
return svg.node();
}