function timeSeries(width, height, data) {
const margin = { top: 20, right: 30, bottom: 30, left: 40 }
const viewportHeight = height;
const viewportWidth = width;
const xMapper = d3
.scaleUtc()
.domain(d3.extent(data, d => d.date))
.range([margin.left, viewportWidth - margin.right]);
const yMapper = d3
.scaleLinear()
.domain([32000, 34000])
.range([viewportHeight - margin.bottom, margin.top]);
const line = d3
.line()
.x(d => xMapper(d.date))
.y(d => yMapper(d.value));
const xAxis = function(g) {
return g.attr("transform", `translate(0,${height - margin.bottom})`).call(
d3
.axisBottom(xMapper)
.ticks(10)
.tickSizeOuter(0)
);
};
const yAxis = function(g) {
return g.attr("transform", `translate(${margin.left},0)`).call(
d3
.axisLeft(yMapper)
.ticks(5)
.tickSizeOuter(0)
);
};
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.attr("style", "border:1px solid black");
svg
.append("path")
.datum(data)
.attr("d", line)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-miterlimit", 1)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round");
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
return svg.node();
}