chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
svg.append("rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("class", "svgBackground");
svg.append("image")
.attr("width", "100%")
.attr("height", mapHeight)
.attr("xlink:href", await FileAttachment("worldMap.JPG").url());
svg.append("rect")
.attr("class", "cartogram")
.attr("width", "100%")
.attr("height", mapHeight)
.attr("fill","#bbe4ed");
svg.append("g")
.selectAll("rect#land")
.data(mapData)
.join("rect")
.attr("id", "land")
.attr("class", "cartogram")
.attr("fill","#daccbc")
.attr("stroke","#eadccc")
.attr("height", rowScale(1))
.attr("width", colScale(1))
.attr("x", d => colScale(d.Y) - colScale(0.5))
.attr("y", d => rowScale(d.X) - rowScale(0.5));
svg.append("g")
.selectAll("rect#boxes")
.data(countryData)
.join("rect")
.attr("id", "boxes")
.attr("class", "cartogram")
.attr("fill", "white")
.attr("width", colScale(1)-4)
.attr("height", rowScale(1)-4)
.attr("x", d => colScale(d.Col)-colScale(.5) + 2)
.attr("y", d => rowScale(d.Row)-rowScale(.5) + 2);
let labels = svg.append("g")
.attr("font-size", "12px")
.attr("text-anchor", "middle")
.attr("font-family", "Roboto")
.selectAll("text")
.data(countryData)
.join("text")
.attr("id", "label")
.attr("x", d => colScale(d.Col) + 1)
.attr("y", d => rowScale(d.Row) + 4)
.attr("transform-origin", d => (colScale(d.Col) + 1) + " " + (rowScale(d.Row) + 4))
.attr("transform", d => `skewX(${inflationScale(d.Inflation)})`)
.attr("font-weight", d => gdpFontScale(d.GDPperCapita))
.attr("letter-spacing", d => gdpPctScale(d.PctGDPgrowth))
.attr("fill", d => regionScale(d.Continent))
.text(d => d.CountryCode)
.append("title").text(d => d.CountryCode + " " + d.ShortName +
"\n " + numberWithCommas(d.GDPperCapita.toFixed(0)) + " GDP per capita (USD)" +
"\n " + d.Inflation.toFixed(1) + " Inflation (%) " +
"\n " + d.PctGDPgrowth.toFixed(1) + " GDP growth (%) " );
yield svg.node();
const dataSourceTag = svg.append("a")
.attr("href", "https://data.worldbank.org")
.append("text")
.attr("class", "other")
.attr("x", 680)
.attr("y", mapHeight + 20)
.style("font-size", "14px")
.text("Data source: data.worldbank.org, Aug. 2013")
const legend1 = svg.append("g")
.attr("transform", `translate(10, ${mapHeight + 20})`)
.attr("class", "other")
.style("font-size", "16px");
legend1.append("text")
.text("GDP per Capita (USD)")
.attr("font-weight", 700);
legend1.selectAll("text#legend1")
.data(gdpLegend)
.join("text")
.text(d => d.text)
.attr("font-family","Roboto")
.attr("y", (d, i) => `${i * 1.5 + 1.75}em`)
.attr("font-weight", d => d.value)
const legend2 = svg.append("g")
.attr("transform", `translate(210, ${mapHeight + 20})`)
.attr("class", "other")
.style("font-size", "16px");
legend2.append("text")
.text("Percent GDP Growth")
.attr("font-weight", 700);
legend2.selectAll("text#legend2")
.data(gdpPctLegend)
.join("text")
.text(d => d.text)
.attr("y", (d, i) => `${i * 1.5 + 1.75}em`)
.attr("letter-spacing", d => d.value)
const legend3 = svg.append("g")
.attr("transform", `translate(500, ${mapHeight + 20})`)
.attr("class", "other")
.style("font-size", "16px");
legend3.append("text")
.text("Inflation")
.attr("font-weight", 700);
legend3.selectAll("text#legend3")
.data(inflationLegend)
.join("text")
.text(d => d.text)
.attr("y", (d, i) => `${i * 1.2 + 1.75}em`)
.attr("transform-origin", (d, i) => `10 ${i * 22.5 + 1.75}`)
.attr("transform", d => `skewX(${d.value})`)
}