Public
Edited
Dec 5
Importers
30 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viz.circle({ data: world, fill: "#38896F" })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
let svg = viz.create({
projection: d3.geoNaturalEarth1()
});
svg.plot({ type: "graticule", stroke: "#38896F" }); // 1st way to write
svg.plot({ type: "path", data: world, fill: "#38896F", tip: true }); // 2nd way to write
return svg.render();
}
Insert cell
Insert cell
{
let svg = viz.create({ domain: world, projection: d3.geoNaturalEarth1() });
svg.plot({ type: "path", data: world, fill: "#38896F", tip: true });
svg
.append("text")
.attr("x", 330)
.attr("y", 170)
.attr("fill", "#38896F")
.text("Text with d3js");
return svg.render();
}
Insert cell
Insert cell
{
let svg = viz.create({
zoomable: true,
projection: d3.geoNaturalEarth1(),
background: "#bddbf0",
width: 600,
margin: 20
});
svg.path({ datum: world, fill: "#38896F" });
return svg.render();
}
Insert cell
Insert cell
Insert cell
{
let svg = viz.create({
zoomable: true,
projection: d3.geoNaturalEarth1()
});
svg.plot({ type: "outline" });
svg.plot({ type: "graticule", stroke: "white" });
svg.plot({ type: "path", datum: world, fill: "white", fillOpacity: 0.4 });
svg.plot({ type: "header", text: "Hello Geoviz" });
return svg.render();
}
Insert cell
Insert cell
Insert cell
Insert cell
{
let svg = viz.container.create({
zoomable: true,
projection: d3.geoEqualEarth()
});
svg.outline();
svg.path({
datum: world,
fill: "white",
fillOpacity: 0.4
});

svg.circle({
data: world,
r: "pop",
fill: "#38896F",
k,
tip: `$name
$pop inh.`
});

svg.legend.circles_nested({
pos: [20, 220],
title: "Population in the country",
subtitle: "(inhabitants)",
data: world.features.map((d) => d.properties.pop),
values_round: 0,
k
});

return svg.render();
}
Insert cell
Insert cell
Insert cell
choro = viz.tool.choro(world.features.map((d) => d.properties.gdppc))
Insert cell
Insert cell
{
let svg = viz.container.create({
zoomable: true,
projection: await require("d3-geo-projection").then((d) => d.geoHill())
});
svg.outline();
svg.path({
data: world,
fill: (d) => choro.colorize(d.properties.gdppc),
strokeWidth: 0.3,
tip: `$name
Wealth: $gdppc$ per inh.`
});
svg.legend.choro_horizontal({
pos: [380, 452],
title: "GDP per capita",
subtitle: "($ per inh.)",
note: "Source: worldbank, 2020",
values_round: 0,
breaks: choro.breaks,
colors: choro.colors
});
return svg.render();
}
Insert cell
Insert cell
Insert cell
typo = viz.tool.typo(world.features.map((d) => d.properties.region))
Insert cell
{
let svg = viz.create({
width: 700,
margin: [20, 0, 0, 0],
zoomable: true,
projection: d3.geoAzimuthalEqualArea()
});
svg.outline();
svg.path({
data: world,
fill: (d) => typo.colorize(d.properties.region),
tip: (d) => `${d.properties.name} (${d.properties.region})`
});
svg.legend.typo_vertical({
pos: [280, 400],
title: null,
alphabetical: true,
values_fill: "black",
colors: typo.colors,
types: typo.types,
missing: false
});
return svg.render();
}
Insert cell
Insert cell
Insert cell
{
// Data
let africa = viz.tool.featurecollection(
world.features.filter((d) => d.properties.region == "Africa")
);

// Font
viz.tool.addfonts([
{
fontFamily: "Pacifico",
url: await FileAttachment("Pacifico-Regular.ttf").url()
}
]);

// main map
let svg = viz.create({
domain: africa,
width: 800,
margin: [20, 20, 20, 20],
background: "#C9EAFE",
fontFamily: "Pacifico"
});
svg.path({
datum: world,
fill: "grey",
fillOpacity: 0.1
});

svg.path({
datum: africa,
fill: "black",
transform: "translate(4,7)",
fillOpacity: 0.2
});

svg.path({
datum: africa,
fill: "#F7E3A1",
stroke: "white"
});

svg.header({
text: "The African continent",
fill: "#6b6969",
background_fill: "#F7E3A1",
fontSize: 60
});

let k = 50;
let scale = d3.scaleSqrt(
[0, d3.max(africa.features.map((d) => +d.properties.pop))],
[0, k * 0.6]
);

svg.text({
data: africa,
text: "NAMEen",
fill: "#6b6969",
strokeWidth: 5,
stroke: "white",
strokeOpacity: 0.7,
fontSize: (d) => scale(d.properties.pop)
});

// inset
let inset = viz.container.create({
parent: svg,
pos: [15, 510],
width: 340,
projection: await require("d3-geo-polygon").then((d) => d.geoAirocean())
});
inset.outline({
fill: "white",
strokeWidth: 1,
stroke: "#7499d6"
});
inset.graticule({
step: 30,
strokeDasharray: "none",
strokeOpacity: 0.5,
stroke: "#7499d6"
});
inset.path({
datum: world,
fill: "#a1acc2",
stroke: "none"
});
inset.path({
datum: africa,
fill: "#7499d6",
stroke: "#7499d6"
});

return svg.render();
}
Insert cell
Insert cell
Insert cell
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