Published
Edited
Sep 14, 2021
Insert cell
Insert cell
import {helloDataset} from "@zachpino/week-2-intro-to-javascript-for-visualization"
Insert cell
d3 = require("d3@7")
Insert cell
helloDataset
Insert cell
helloWorld = {
//svg Earth dimensions
const width = 720;
const height = 360;

//create SVG artboard
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
//create color background
const bg = svg
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height)
.attr("fill", "#ffc68f");
//loop through countries and draw circles for each
for(let i = 0; i < helloDataset.length; i++) {
svg
.append("circle")
.attr("cx", (parseFloat(helloDataset[i].long) + 180) * 2)
.attr("cy", (-parseFloat(helloDataset[i].lat) + 90) * 2)
.attr("r", 5)
.attr("fill", "#73c49c");
//help from Hugo
svg
.append("text")
.attr("x", (parseFloat(helloDataset[i].long) + 180) * 2)
.attr("y", (-parseFloat(helloDataset[i].lat) + 90) * 2)
.attr("fill", "#FFF")
.style("text-anchor", "middle")
.attr("font-family", "Neuzeit Grotesk", "sans-serif")
.style("alignment-baseline", "middle")
.text(helloDataset[i].hello);

}

//show visualization
return svg.node();
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more