{
const margin = {top: 0, right: 0, bottom: 0, left: 0};
const [svg_width, svg_height] = [width + margin.left + margin.right, height + margin.top + margin.bottom];
let mx, mouseX = 0;
const svg = d3.create("svg")
.attr("width", svg_width)
.attr("height", svg_height)
.attr("viewBox", [0, 0, svg_width, svg_height])
.attr("style", "max-width: 100%; height: auto; font: 10px sans-serif;");
svg.call(d3.drag()
.on("drag", dragged)
.on("start", dragStart)
.on("end", dragEnd)
);
const chart = svg.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
const line = d3.line()
.x(d => d.projected.x)
.y(d => d.projected.y);
update(getTriangles(0));
function update(data) {
chart.selectAll('path')
.data(data)
.join("path")
.attr("fill", toggleFill ? "lightblue" : "none")
.attr("fill-opacity", 0.2)
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("d", d => line(d));
}
function dragStart({x, y}){
mx = x;
}
function dragEnd({x, y}) {
mouseX = x - mx + mouseX;
}
function dragged(event) {
const beta = (event.x - mx + mouseX) * Math.PI / (-360);
update(getTriangles(beta));
}
return svg.node();
}