function SpaghettiChart(
data,
{
x = (d) => d,
label = (d) => d,
r = 20,
space = 6,
turns = 4,
width = 600,
height = 400,
marginTop = 10,
marginBottom = 10,
marginLeft = 10,
marginRight = 10
}
) {
const chartWidth = width - marginLeft - marginRight;
const chartHeight = height - marginTop - marginBottom;
const total = d3.sum(data, x);
const lineLength = turns * chartWidth;
const xScale = d3.scaleLinear().domain([0, total]).range([0, lineLength]);
const { path: pathString } = curvedLine(chartWidth, r, lineLength);
const dasharray = data.map((d) => xScale(x(d))).join(` ${space} `);
console.log(dasharray);
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height]);
svg
.append("rect")
.attr("width", width)
.attr("height", height)
.attr("fill", "#f8bbd0");
const group = svg
.append("g")
.attr("transform", `translate(${marginLeft}, ${marginTop})`);
const path = group
.append("path")
.attr("d", pathString)
.attr("stroke", "#d81b60")
.attr("stroke-dasharray", dasharray)
.attr("stroke-width", 6)
.attr("fill", "none");
return svg.node();
}