chart = {
const marginTop = 20;
const marginRight = 30;
const marginBottom = 30;
const marginLeft = 40;
const stack = d3.stack().keys(categories);
const chartData = stack(dataset);
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width", width)
.attr("height", height)
.attr("style", "max-width: 100%; height: auto;");
const rc = rough.svg(svg.node());
const groups = svg
.append("g")
.selectAll("g")
.data(chartData)
.join("g")
.style("fill", (d, i) => colors(d.key));
console.log(groups)
groups
.selectAll("rect")
.data((d) => d)
.join("rect")
.each(function (d) {
const parentData = d3.select(this.parentNode).datum();
console.log(parentData)
const y = yScale(d.data.population_name);
const x = xScale(d[0]) + gapSize / 2;
const height = yScale.bandwidth();
const widthValue = xScale(d[1]) - xScale(d[0]);
const adjustedGapSize = Math.min(gapSize, widthValue / 2);
const width = widthValue - adjustedGapSize;
const fillColor = colors(parentData.key);
const node = rc.rectangle(x, y, width, height, {
roughness: roughness,
fill: fillColor,
stroke: fillColor == nonHighlightedColor ? "black" : fillColor,
strokeWidth: strokeWidth,
hachureGap: hachureGap,
hachureAngle: hachureAngle,
fillWeight: fillWeight,
fillStyle: fillStyle,
bowing: bowing,
disableMultiStroke,
disableMultiStrokeFill: true
});
this.parentNode.insertBefore(node, this);
d3.select(this).remove();
});
return svg.node();
}