chart = {
let root = pack(dataPure);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("font-size", 10)
.attr("font-family", "sans-serif")
.attr("text-anchor", "middle");
const leaf = svg.selectAll("g")
.data(root.descendants())
.join("g")
.attr("transform", d => `translate(${d.x + 1},${d.y + 1})`);
leaf.append("circle")
.attr("r", d => d.r)
.attr("stroke", "none")
.attr("stroke-width", "0.2px")
.attr("fill-opacity", 1.0)
.attr("fill", d => {
let fill
if (d.children) {
fill = "none"
} else {
if (d.data.incomePerCapMon > highIncome) {
fill = d3.hsl(160, 0.25, 0.7)
} else if (d.data.incomePerCapMon > middleIncome) {
fill = d3.hsl(47, 1.0, 0.6)
} else {
fill = d3.hsl(10, 0.98, 0.8)
}
}
return fill
});
leaf.append("circle")
.attr("r", d => {
return Math.sqrt(lowIncome/d.data.incomePerCapMon)*d.r;
})
.attr("stroke", "white")
.attr("stroke-width", d => {
let width = 0.0
if (d.data.incomePerCapMon>lowIncome) {
width = 0.5
}
return width
})
.attr("fill-opacity", 0.0)
.attr("fill", "none");
leaf.append("circle")
.attr("r", d => {
return Math.sqrt(middleIncome/d.data.incomePerCapMon)*d.r;
})
.attr("stroke", "white")
.attr("stroke-width", d => {
let width = 0.0
if (d.data.incomePerCapMon>middleIncome) {
width = 0.5
}
return width
})
.attr("fill-opacity", 0.0)
.attr("fill", "none");
leaf.append("circle")
.attr("r", d => {
return Math.sqrt(highIncome/d.data.incomePerCapMon)*d.r;
})
.attr("stroke", "white")
.attr("stroke-width", d => {
let width = 0.0
if (d.data.incomePerCapMon>highIncome) {
width = 0.5
}
return width
})
.attr("fill-opacity", 0.0)
.attr("fill", "none");
leaf.append("circle")
.attr("r", d => {
return Math.sqrt(veryHighIncome/d.data.incomePerCapMon)*d.r;
})
.attr("stroke", "white")
.attr("stroke-width", d => {
let width = 0.0
if (d.data.incomePerCapMon>veryHighIncome) {
width = 0.5
}
return width
})
.attr("fill-opacity", 0.0)
.attr("fill", "none");
leaf.append("circle")
.attr("r", d => {
let scale = d3.scaleSqrt()
.domain([0, 146000000])
.range([0, 50]);
return scale(d.data.population)
})
.attr("fill", d3.hsl(360, 0, 0.3));
/*svg.selectAll(".categories")
.data(root.children)
.enter()
.append("g")
.attr("transform", d => `translate(${d.x + 1},${d.y + d.r + 1})`)
.append("text")
.text(d => d.data.name)
.attr("font-size", 12)
.attr("font-family", "sans-serif")
.attr("text-anchor", "middle");*/
return svg.node();
}