viewof draw_plot = {
const svg = d3.select(DOM.svg(width, height));
let output;
const draw_target = svg.append('rect')
.attr('width', width)
.attr('height', height)
.attr('opacity', 0);
const x = d3.scaleLinear()
.domain([0,1])
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain([0,1])
.range([height - margin.bottom, margin.top]);
svg.append("g")
.attr("transform", "translate(0," + (height - margin.bottom)+ ")")
.call(d3.axisBottom(x));
svg.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y));
const drawingSel = svg.append('path')
.attr('class', 'draw_line')
.style('fill', 'none')
.style('stroke', 'back')
.style('stroke-width', 3);
const line = d3.area()
.x(d => x(d.x))
.y(d => y(d.y));
const step_size = 0.01
const data = d3.range(0, 10, step_size)
.map(d => ({x:d, y:null, defined:0}));
const drag = d3.drag()
.on('drag', function(){
const pos = d3.mouse(this),
x_val = clamp(0, 1, x.invert(pos[0])),
y_val = clamp(0, 1, y.invert(pos[1]));
data.forEach(d => {
if (Math.abs(d.x - x_val) < step_size/2){
d.y = y_val;
d.defined = true;
}
});
drawingSel.attr('d', line.defined(d => d.defined)(data));
})
svg.call(drag);
const to_return = svg.node()
to_return.value = data;
return to_return
}