plotter = {
let data = JSON.parse(alpha.f)
viewof dataset.value = data;
const svg = d3.select(createSVG(width + margin.left + margin.right, height + margin.top + margin.bottom))
.style("border", "1px solid #000");
const g = svg.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`)
const rect = g.append("rect")
.attr("width", width)
.attr("height", height)
.style("fill", "#fff");
const clear = g.append("g")
.attr("transform",`translate(${width - 100}, 0)`)
clear.append("rect")
.attr("width", 100)
.attr("height", 30)
.style("fill", "lightgray")
.style("stroke", "#000")
clear.append("ellipse")
.attr("cx", -width/2)
.attr("cy", 200)
.attr("rx", 200)
.attr("ry", 200)
.style("fill", "lightgray")
.style("stroke-width", "0")
clear.append("ellipse")
.attr("cx", -width/2)
.attr("cy", 200)
.attr("rx", 180)
.attr("ry", 180)
.style("fill", "white")
.style("stroke-width", "0")
clear.append("text")
.style("fill", "#000")
.text("Clear Points")
.attr("dy", 19)
.attr("dx", 50)
.style("text-anchor", "middle")
.style("font", "14px sans-serif")
.style("pointer-events", "none")
const linePath = g.append("path")
.style("stroke", '#000')
.style("stroke-opacity", '0.5')
.style("stroke-width", 20)
.style("stroke-linejoin", "round")
.style("stroke-linecap", "round")
.style("fill", "none")
.datum(data)
.attr("d", line);
const circles = g.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", 5)
.on("mouseenter", mouseenter)
.on("mouseleave", mouseleave)
.call(d3.drag()
.on("drag", dragged));
rect.on("click",function() {
const container = d3.mouse(this)
data.push({x: container[0], y: container[1]});
viewof dataset.value = data;
g.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", 5)
.on("mouseenter", mouseenter)
.on("mouseleave", mouseleave)
.call(d3.drag()
.on("drag", dragged));
linePath.datum(data)
.attr("d", line);
})
clear.select("rect").on("click",function() {
data = [];
viewof dataset.value = data
svg.selectAll("circle").remove()
linePath.datum(data)
.attr("d", "none");
})
function mouseenter() {
d3.select(this).style("fill", "red")
}
function mouseleave() {
d3.select(this).style("fill", "#000")
}
function dragged() {
const thisDatum = data.filter(d => d.x == d3.select(this).attr("cx")
& d.y == d3.select(this).attr("cy"));
thisDatum[0].x = d3.event.x;
thisDatum[0].y = d3.event.y;
d3.select(this).attr("cx", d3.event.x).attr("cy", d3.event.y);
linePath.datum(data)
.attr("d", line);
viewof dataset.value = data;
}
return svg.node()
}