Public
Edited
Jan 4
11 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
height = 850
Insert cell
Insert cell
path = d3.geoPath()
.projection(projection)
Insert cell
projection = d3
.geoAlbers()
.rotate([4.4, 0])
.translate([MAPWIDTH / 2, MAPHEIGHT / 2])
.fitSize([MAPWIDTH - padding, MAPHEIGHT - padding], wales)
Insert cell
Insert cell
scaleColor = d3.scaleLinear()
.domain(d3.extent(hexbin_data, bin => {
return bin.welsh/(bin.welsh+bin.english) //% share
}))
Insert cell
Insert cell
radius = d3.scaleSqrt([0, d3.max(hexbin_data, d => d.length)], [0, hexbin.radius() * Math.SQRT2])
Insert cell
hexbin = d3.hexbin().extent([[0, 0], [width, height]]).radius(hexRadius)
Insert cell
Insert cell
data = {
let data = [];
let arr;
if (dataset == "Primary") arr = primary;
else if (dataset == "Secondary") arr = secondary;
arr.features.map((f) => {data.push([projection(f.geometry.coordinates) [0],projection(f.geometry.coordinates)[1],f.properties.school_language_en])})
return data;
}
Insert cell
percentage = (per.welsh / (per.welsh + per.english)) * 100
Insert cell
Insert cell
hexbin_data = {
// hex by school language
//return hexbin(data);
return Object.assign(
hexbin(data).map(bin => {
let w = 0;
let e = 0;
bin.map(f => {
if (
(f[2] && f[2] == "Welsh medium") ||
f[2] == "Dual Stream" ||
f[2] == "Transitional" ||
f[2].includes("Bilingual")
) {
w++;
} else if (
f[2] == "English with significant Welsh" ||
f[2] == "English medium"
) {
e++;
}
});
bin.welsh = w;
per.welsh = per.welsh + w;
bin.english = e;
per.english = per.english + e;
return bin;
})
);
}
Insert cell
Insert cell
border = await FileAttachment("borders.json").json()
Insert cell
england = topojson.feature(await FileAttachment("england.json").json(), "eer")
Insert cell
wales = topojson.feature(await FileAttachment("wales_topo.json").json(), "lad")
Insert cell
primary = await FileAttachment("primary_4326.json").json()
Insert cell
secondary = await FileAttachment("secondary_4326.json").json()
Insert cell
Insert cell
Insert cell
d3 = require("d3@5", "d3-hexbin@0.2")
Insert cell
topojson = require("topojson-client@3")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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