function init({ margin = 30, width = 400, height = 400 } = {}) {
let max = 100;
let y = d3
.scaleLinear()
.domain([0, max])
.range([height - 2 * margin, 0]);
let svg = d3.create("svg").attr("width", width).attr("height", height);
let g = svg.append("g");
g.attr("transform", `translate(${margin},${margin})`)
.call(d3.axisLeft(y))
.call((g) =>
g
.selectAll(".tick line")
.clone()
.attr("x2", width - 2 * margin)
.attr("class", "tick-line")
.attr("stroke-opacity", 0.2)
);
setInterval(function () {
let r = Math.random();
r = r > 0.5 ? r * 100 : r * -100;
max = max + r;
y.domain([0, max]);
g.transition().duration(2000).call(d3.axisLeft(y));
g.selectAll(".tick line:first-child ")
.clone()
.attr("x2", width - 2 * margin)
.transition()
.duration(2000)
.attr("class", "tick-line")
.attr("stroke-opacity", 0.2);
g.selectAll(".tick .tick-line")
.transition()
.duration(2000)
.style("stroke-opacity", 1e-6)
.remove();
}, 3000);
return svg
}