{
let landguzzlersViz = d3.select(svgContainer)
landguzzlersViz.selectAll("rect")
.data(land_guzzlers)
.join("rect")
.attr("width", d => Math.sqrt(d.footprint) * 1000)
.attr("height", d => Math.sqrt(d.footprint) * 1000)
.attr("x", 0)
.attr("y", (d, i) => 1100 - Math.sqrt(d.footprint) * 1000)
.style("fill", (d, i) => colors[i]);
landguzzlersViz.selectAll(".title")
.data(land_guzzlers)
.join("text")
.attr("x", d => {
if (d['title'] === "HAMSTER")
{return Math.sqrt(d.footprint) * 1000 + 125}
else
{return Math.sqrt(d.footprint) * 1000-5}})
.attr("y", d => 1100 - Math.sqrt(d.footprint) * 1000 + 30)
.text(d => d['title'])
.attr("class", "title");
landguzzlersViz.selectAll(".footprint")
.data(land_guzzlers)
.join("text")
.attr("x", d => {
if (d['title'] === "HAMSTER")
{return Math.sqrt(d.footprint) * 1000}
else {return Math.sqrt(d.footprint) * 1000- 15}})
.attr("y", d => 1100 - Math.sqrt(d.footprint) * 1000 + 45)
.text((d, i) => (i !== 3) ? "Eco-footprint: " + d['footprint'] + " hectores" : "") // hides text from VOLKSWAGEN sq.
.attr("transform", (d,i,nodes) => {
if (d['title'] === "HAMSTER")
{return } //dont want to rotate for HAMSTER
else
{return "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", "footprint"); // tag it with the style class 'footprint'
// ... what other objects do we need and how do we get them. Use the same approaches.
// My code to add the subtitiles
landguzzlersViz.selectAll(".subtitle")
.data(land_guzzlers)
.join("text")
.attr("x", d => Math.sqrt(d.footprint) * 1000 - 20)
.attr("y", d => 1100 - Math.sqrt(d.footprint) * 1000+ 50)
.text(d => d['subtitle'])
.attr("text-anchor", "end")
.attr("class", "subtitle");
landguzzlersViz.selectAll(".subtitle2")
.data(land_guzzlers)
.join("text")
.attr("x", d => Math.sqrt(d.footprint) * 1000-20)
.attr("y", d => 1100 - Math.sqrt(d.footprint) * 1000+ 70)
.text(d => d['subtitle2'])
.attr("text-anchor", "end")
.attr("class", "subtitle2");
landguzzlersViz.selectAll(".subtitle3")
.data(land_guzzlers)
.join("text")
.attr("x", d => Math.sqrt(d.footprint) * 1000-20)
.attr("y", d => 1100 - Math.sqrt(d.footprint) * 1000+ 90)
.text(d => d['subtitle3'])
.attr("text-anchor", "end")
.attr("class", "subtitle3");
}
//Things that got me stuck: splitting up the line of the eco-footprint for HAMSTER. Drawing the white lines under MEDIUM-SIZE CRUISER and MEDIUM SIZED DOG