function render_chart(data, startDate, endDate, height) {
const x = d3
.scaleTime()
.domain([new Date(startDate), new Date(endDate)])
.range([margin.left, chartWidth - margin.right]);
const y = d3
.scaleLinear()
.domain([
0,
d3.max(
data.map(
d => d.receiptsByDay[d.receiptsByDay.length - 1].cumulative_amount
)
)
])
.nice()
.range([height - margin.bottom, margin.top]);
const line = d3
.line()
.curve(d3.curveStepAfter)
.x((d, i) => x(new Date(d.day)))
.y(d => y(d.cumulative_amount));
const xAxis = g =>
g.attr("transform", `translate(0,${height - margin.bottom})`).call(
d3
.axisBottom(x)
.ticks(width / 120)
.tickSizeOuter(0)
.tickFormat(d => d3.timeFormat("%b '%y")(d))
);
const yAxis = g =>
g
.attr("transform", `translate(${margin.left},0)`)
.call(
d3
.axisLeft(y)
.ticks(height / 50)
.tickFormat(d => d3.format("$~s")(d))
)
.call(g => g.select(".domain").remove());
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, chartWidth, height])
.attr("id", "chart")
.style("overflow", "hidden");
const path = svg
.append("g")
.attr("fill", "none")
.attr("stroke-width", 2)
.selectAll("path")
.data(data)
.join("path")
.style("mix-blend-mode", "multiply")
.attr("stroke", (d, i) => {
return nameScale(shortNames[d.id]);
})
.attr("d", d => line(d.receiptsByDay));
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
return svg;
}