Public
Edited
Mar 28, 2024
Insert cell
Insert cell
Insert cell
<svg width="1100" height="1100">
<style>
/* edit these styles as you need */
rect {stroke: white; stroke-width: 2px;}
text {fill: white; font-family: 'Rajdhani', sans-serif;}
.maintitle {font-size: 39px; fill: black;}
.mainsubtitle {font-size: 18px; fill: black;}
.title1 {text-anchor: end; font-size: 32px;}
.title2 {font-size: 32px;}
.subtext1 {text-anchor: end; font-size: 17px;}
.subtext2 {text-anchor: end; font-size: 17px;}
.subtext3 {text-anchor: end; font-size: 17px;}
.footprint1 {font-size: 17px;}
.footprint2 {font-size: 17px;}
.footprint3 {font-size: 17px;}
line {stroke: white; stroke-width: 1px;}
</style>

<text x="0" y="27" class="maintitle">Land guzzlers</text>
<text x="0" y="49" class="mainsubtitle">The ecological footprints of our pets can make SUVs look positively eco-friendly</text>
</svg>
Insert cell
Insert cell
Insert cell
{
let landguzzlersViz = d3.select(svgContainer)
landguzzlersViz.selectAll("rect")
.data(land_guzzlers)
.join("rect")
.attr("width", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.attr("height", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.attr("x", 0)
.attr("y", d => 1100 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.style("fill", (d,i) => colors[i]);
landguzzlersViz.selectAll(".title")
.data(land_guzzlers.filter(d => d.title !== "HAMSTER"))
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 4)
.attr("y", d => 1130 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.text(d => d["title"])
.attr("class", "title1");

landguzzlersViz.selectAll(".footprint")
.data(land_guzzlers.filter(d => d.title !== "HAMSTER" & d.footprint !== 0.18))
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 16)
.attr("y", d => 1136 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.text(d => "Eco-footprint: " + d["footprint"] + " hectares")
.attr("transform", (d,i,nodes) => "rotate(90 " + nodes[i].getAttribute("x") + " " + nodes[i].getAttribute("y") + ")")
.attr("class", "footprint1");

landguzzlersViz.selectAll(".title")
.data(land_guzzlers.filter(d => d.title == "HAMSTER"))
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) + 5)
.attr("y", d => 1130 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.text(d => d["title"])
.attr("class", "title2");

landguzzlersViz.selectAll(".footprint")
.data(land_guzzlers.filter(d => d.title == "HAMSTER"))
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) + 6)
.attr("y", d => 1152 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.text(d => "Eco-footprint: ")
.attr("class", "footprint2");

landguzzlersViz.selectAll(".footprint")
.data(land_guzzlers.filter(d => d.title == "HAMSTER"))
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) + 6)
.attr("y", d => 1172 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.text(d => d["footprint"] + " hectares")
.attr("class", "footprint3");

landguzzlersViz.selectAll(".subtext")
.data(land_guzzlers)
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 30)
.attr("y", d => 1160 - Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 3)
.text(d => d["subtitle"])
.attr("class", "subtext1");

landguzzlersViz.selectAll(".subtext")
.data(land_guzzlers)
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 30)
.attr("y", d => 1163 - Math.sqrt(d["footprint"]/1.1 * 1099981.44) + 13)
.text(d => d["subtitle2"])
.attr("class", "subtext2");

landguzzlersViz.selectAll(".subtext")
.data(land_guzzlers)
.join("text")
.attr("x", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 30)
.attr("y", d => 1166 - Math.sqrt(d["footprint"]/1.1 * 1099981.44) + 29)
.text(d => d["subtitle3"])
.attr("class", "subtext3");

landguzzlersViz.selectAll("line1")
.data(land_guzzlers.filter(d => d.subtitle !== ""))
.join("line")
.attr("x1", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 339)
.attr("y1", d => 1139 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.attr("x2", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 23)
.attr("y2", d => 1139 - Math.sqrt(d["footprint"]/1.1 * 1099981.44));

landguzzlersViz.selectAll("line2")
.data(land_guzzlers.filter(d => d["subtitle"] !== ""))
.join("line")
.attr("x1", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 23)
.attr("y1", d => 1139 - Math.sqrt(d["footprint"]/1.1 * 1099981.44))
.attr("x2", d => Math.sqrt(d["footprint"]/1.1 * 1099981.44) - 23)
.attr("y2", d => 1210 - Math.sqrt(d["footprint"]/1.1 * 1099981.44));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
colors = ["#a5620b","#c29657","#cc1f5e","#a71949","#f7991d","#231f20"]; // in order Large Dog to Hamster. Reference as colors[i]
Insert cell
land_guzzlers.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
<link href="https://fonts.googleapis.com/css?family=Rajdhani" rel="stylesheet">
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more