drawFinal = function(){
let width = 932;
let height = 932;
const svgHTML = html`<svg width="${width}" height="${height}"></svg>`;
let pack = d3.pack()
.size([width - 2, height - 2])
.padding(3)
const nodeHeirarchy = d3.hierarchy({
children: highest_data_grouped_as_json
})
.sum(d => d.Employment_High);
const svg = d3.select(svgHTML)
.style("width", "100%")
.style("height", "auto")
const root = pack.padding(7)(nodeHeirarchy)
const leaf = svg.selectAll("g")
.data(root.descendants())
.enter().append("g")
.attr("transform", d => `translate(${d.x + 1},${d.y + 1})`);
let circle = leaf.append("circle")
.attr("r", d => d.r)
.attr("fill", d => {
if(d.height !== 0){
return "none";
}
if(d.data.isGrowing){
return "#5cb85c";
}
else{
return "#d9534f";
}
});
let innerCircles = leaf.append("circle")
.attr("r", d => {
let scale = d3.scaleSqrt()
.domain([0, d.data.Employment_High])
.range([0,d.r]);
return scale(d.data.Employment_Low);
})
.attr("fill", "#d9edf7");
let current_circle = undefined;
let format = d3.format(",d")
function selectOccupation(d) {
// cleanup previous selected circle
if(current_circle !== undefined){
current_circle.attr("fill", d => "#d9edf7");
svg.selectAll("#details-popup").remove();
}
// select the circle
current_circle = d3.select(this);
current_circle.attr("fill","#b2e1f9");
let textblock = svg.selectAll("#details-popup")
.data([d])
.enter()
.append("g")
.attr("id", "details-popup")
.attr("font-size", 14)
.attr("font-family", "sans-serif")
.attr("text-anchor", "start")
.attr("transform", d => `translate(0, 20)`);
textblock.append("text")
.text("Occupation Details:")
.attr("font-weight", "bold");
textblock.append("text")
.text(d => "Description: " + d.data.Occupation_Name)
.attr("y", "16");
textblock.append("text")
.text(d => "Current Employment: " + format(d.data.Employment))
.attr("y", "32");
textblock.append("text")
.text(d => "Projected Growth: " + format(d.data.Employment_Growth))
.attr("y", "48");
textblock.append("text")
.text(d => "Recent Labour Market Conditions: " + d.data.Recent_Labour_Market_Conditions.toUpperCase())
.attr("y", "64");
textblock.append("text")
.text(d => "Projected Future Labour Market Conditionsh: " + d.data.Future_Labour_Market_Conditions.toUpperCase())
.attr("y", "80");
}
innerCircles.on("click", selectOccupation);
const categories = root.children;
svg.selectAll(".categories")
.data(categories)
.enter()
.append("g")
.attr("transform", d => `translate(${d.x + 1},${d.y + d.r + 1})`)
.append("text")
.text(d => d.data.Description)
.attr("font-size", 12)
.attr("font-family", "sans-serif")
.attr("text-anchor", "middle");
return svg.node()
}