charts = {
const mode = 'offset';
const margin = { top: 50, right: 20, bottom: 30, left: 50 };
const width = 928 - margin.left - margin.right;
const height = 4850 - margin.top - margin.bottom;
const svg = d3.select(DOM.svg(width + margin.left + margin.right, height + margin.top + margin.bottom));
const xAxis = d3.axisBottom().scale(x);
modifiedReceiveData.forEach((countryData, index) => {
const g = svg.append("g").attr("transform", `translate(${margin.left}, ${index * 100 + margin.top})`);
g.append("clipPath")
.attr("id", `clipy-${index}`)
.append("rect")
.attr("width", width)
.attr("height", step);
g.append("defs").append("path")
.attr("id", `path-def-receive-${index}`)
.datum(countryData.data)
.attr("d", area);
g.append("g")
.attr("clip-path", `url(#clipy-${index})`)
.selectAll("use")
.data(overlaps)
.enter().append("use")
.attr("fill", 'steelblue')
.attr("transform", d => mode === "mirror" && d.index < 0
? `scale(1,-1) translate(0, ${d.index * step})`
: `translate(0,${(d.index + 1) * step})`)
.attr("href", `#path-def-receive-${index}`);
// Add country names
svg.append("text")
.attr("x", 0) // Adjust the x position for the country name
.attr("y", index * 100 + 80) // Adjust the y position for the country name
.text(countryData.country)
.style("font-size", "12px")
.style("font-family", "Calibri, sans-serif");
});
// Loop through the modifiedDonateData array to create charts for each country
modifiedDonateData.forEach((countryData, index) => {
const g = svg.append("g").attr("transform", `translate(${margin.left}, ${index * 100 + margin.top})`); // Adjust the positioning for donated data
g.append("clipPath")
.attr("id", `clipy-donate-${index}`)
.append("rect")
.attr("width", width)
.attr("height", step);
g.append("defs").append("path")
.attr("id", `path-def-donate-${index}`)
.datum(countryData.data)
.attr("d", area);
g.append("g")
.attr("clip-path", `url(#clipy-donate-${index})`)
.selectAll("use")
.data(overlaps)
.enter().append("use")
.attr("fill", 'orange')
.attr("transform", d => mode === "mirror" && d.index < 0 // Adjust the condition to match the receive data positioning
? `scale(1,-1) translate(0, ${d.index * step})`
: `translate(0,${(d.index + 1) * step})`)
.attr("href", `#path-def-donate-${index}`);
});
// Create a moving rule that follows the mouse.
const rule = svg.append("line")
.attr("stroke", "#000")
.attr("y1", margin.top - 6)
.attr("y2", height - margin.bottom - 1)
.attr("x1", 0.5)
.attr("x2", 0.5);
svg.on("mousemove touchmove", (event) => {
const x = d3.pointer(event, svg.node())[0] + 0.5;
rule.attr("x1", x).attr("x2", x);
});
// Append Axes last
svg.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`) // Translate the x-axis
.call(xAxis);
return svg.node();
}