{
let landguzzlersViz = d3.select(svgContainer)
let maxfp = Math.sqrt(d3.max(land_guzzlers, d => d.footprint))
let fp_guzzlers = land_guzzlers.filter((d, i, arr) => {
if (i === arr.length - 1) return true;
return d.footprint - arr[i + 1].footprint >= 0.05;
});
landguzzlersViz.selectAll("rect")
.data(land_guzzlers)
.join("rect")
.attr("width", d => (Math.sqrt(d.footprint)/maxfp)*1040)
.attr("height", d => (Math.sqrt(d.footprint)/maxfp)*1040)
.attr("x", 0)
.attr("y", d => 1100 - (Math.sqrt(d.footprint)/maxfp)*1040)
.style("fill", (d,i) => colors[i]);
landguzzlersViz.selectAll(".title1")
.data(land_guzzlers.filter(d => d.footprint >= 0.1))
.join("text")
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)-5)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+30)
.text(d => d.title)
.attr("class", "title1");
landguzzlersViz.selectAll(".footprint1") // selecting a .class of objects again.
.data(fp_guzzlers.filter(d => d.footprint >= 0.1))
.join("text")
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)-15)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+40)
.text(d => "Eco-footprint: " + d["footprint"] + " hectares")
.attr("transform", (d,i,nodes) => "rotate(90 " + nodes[i].getAttribute("x") + " " + nodes[i].getAttribute("y") + ")")
// // ^^ OK, so you would not have gotten this one on your own easily. See if you can figure it out.
// // transform is "rotate(angle xPivotPoint yPivotPoint)" This is an SVG transform.
.attr("class", "footprint1"); // tag it with the style class 'footprint'
landguzzlersViz.selectAll(".title2")
.data(land_guzzlers.filter(d => d.footprint < 0.1)) // same dataset used again
.join("text") // new object type created
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)+5)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+30)
.text(d => d.title) // this is the text contents, eg. LARGE DOG
.attr("class", "title2"); // tag it with the style class 'title' so the selectAll above works.
// // Now the rotated Eco-Footprint text and values. Note the rotation transform.
landguzzlersViz.selectAll(".footprint2-1") // selecting a .class of objects again.
.data(fp_guzzlers.filter(d => d.footprint < 0.1))
.join("text")
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)+5)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+50)
.text("Eco-footprint:")
.attr("class", "footprint2-1"); // tag it with the style class 'footprint'
landguzzlersViz.selectAll(".footprint2-2") // selecting a .class of objects again.
.data(fp_guzzlers.filter(d => d.footprint < 0.1))
.join("text")
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)+5)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+70)
.text(d => d["footprint"] + " hectares")
.attr("class", "footprint2-2");
// ... what other objects do we need and how do we get them. Use the same approaches.
landguzzlersViz.selectAll(".subtext1")
.data(land_guzzlers) // same dataset used again
.join("text") // new object type created
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)-25)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+55)
.text(d => d.subtitle)
.attr("class", "subtext1");
landguzzlersViz.selectAll(".subtext2")
.data(land_guzzlers) // same dataset used again
.join("text") // new object type created
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)-25)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+75)
.text(d => d.subtitle2)
.attr("class", "subtext2");
landguzzlersViz.selectAll(".subtext3")
.data(land_guzzlers) // same dataset used again
.join("text") // new object type created
.attr("x", d => ((Math.sqrt(d.footprint)/maxfp)*1040)-25)
.attr("y", d => 1100-((Math.sqrt(d.footprint)/maxfp)*1040)+95)
.text(d => d.subtitle3)
.attr("class", "subtext3");
landguzzlersViz.selectAll(".line1")
.data(land_guzzlers.filter(d => d.subtitle !== "")) // the name of the data object (see table below)
.join("line")
.attr("x1", (d) => ((Math.sqrt(d.footprint)/maxfp)*1040)-300)
.attr("y1", (d) => 1100 - ((Math.sqrt(d.footprint)/maxfp)*1040)+35)
.attr("x2", (d) => ((Math.sqrt(d.footprint)/maxfp)*1040)-20)
.attr("y2", (d) => 1100 -((Math.sqrt(d.footprint)/maxfp)*1040)+35)
.attr("class", "line1");
landguzzlersViz.selectAll(".line2")
.data(land_guzzlers.filter(d => d.subtitle !== "")) // the name of the data object (see table below)
.join("line")
.attr("x1", (d) => ((Math.sqrt(d.footprint)/maxfp)*1040)-20)
.attr("y1", (d) => 1100 - ((Math.sqrt(d.footprint)/maxfp)*1040)+35)
.attr("x2", (d) => ((Math.sqrt(d.footprint)/maxfp)*1040)-20)
.attr("y2", (d) => 1100 -((Math.sqrt(d.footprint)/maxfp)*1040)+235)
.attr("class", "line2");
}