Public
Edited
Dec 8, 2023
1 fork
7 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
textStyle = new g.TextStyle({
color: () => "#000",
fontFamily: () => fontFamily,
text: (cell, resolution) => {
const value = cell["2018"];
if (type == "emoji") {
// emojis
if (value < threshold * resolution * 0.25) {
return emojis[0];
} else if (value < threshold * resolution * 0.5) {
return emojis[1];
} else if (value < threshold * resolution * 0.75) {
return emojis[2];
} else if (value < threshold * resolution * 1) {
return emojis[3];
} else if (value >= threshold * resolution * 1) {
return emojis[4];
}
} else {
// text
if (value < threshold * resolution * 0.1) {
return characters[0];
} else if (value < threshold * resolution * 0.6) {
return characters[1];
} else if (value >= threshold * resolution * 0.6) {
return characters[2];
}
}
}
})
Insert cell
typeWriterStyles = [
new g.TextStyle({
color: () => "#000",
fontFamily: () => fontFamily,
text: (cell, resolution) => {
const value = cell["2018"];
// text
return "E";
}
}),
new g.TextStyle({
color: () => "#000",
fontFamily: () => fontFamily,
text: (cell, resolution) => {
const value = cell["2018"];
// text
if (
value > threshold * resolution * 0.25 &&
value < threshold * resolution * 1.25
) {
return "U";
}
}
}),
new g.TextStyle({
color: () => "#000",
fontFamily: () => fontFamily,
text: (cell, resolution) => {
const value = cell["2018"];
// text
if (value >= threshold * resolution * 1.25) {
return "R";
}
}
})
]
Insert cell
Insert cell
dataset = new g.MultiResolutionDataset(
[1000, 2000, 5000, 10000, 20000, 50000, 100000],
(resolution) =>
new g.TiledGrid(
map,
"https://raw.githubusercontent.com/jgaffuri/tiledgrids/main/data/europe/population/" +
resolution +
"m/"
)
)
Insert cell
Insert cell
gridLayer = new g.GridLayer(dataset, [], {
minPixelsPerCell: 5,
cellInfoHTML: (cell) => "<b>" + cell["2018"] + "</b> inhabitant(s)"
})
Insert cell
Insert cell
labelLayer = new g.LabelLayer(ges.getEuronymeLabelLayer())
Insert cell
Insert cell
map = new g.Map(document.getElementById("container-div"), { w: 600, h: 600 , x: 4000000, y: 2960000,z:2000 })
.addZoomButtons()
Insert cell
Insert cell
map.layers = [gridLayer, labelLayer]
Insert cell
Insert cell
{
gridLayer.styles = type == "typewriter" ? typeWriterStyles : [textStyle];
gridLayer.minPixelsPerCell = pixNb;
map.redraw();
}
Insert cell
Insert cell
{
labelLayer.visible = () => placenames;
map.redraw();
}
Insert cell
Insert cell
Insert cell
style = html`
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=${parseFont}:ital@0;1&display=swap">

<style>
body, svg {
font-family: '${fontFamily}', serif;
/* font-size: 48px; */
}
</style>
`
Insert cell
parseFont = fontFamily.split(" ").join("+")
Insert cell
Insert cell
/*function getFlagEmoji(countryCode) {
const codePoints = countryCode
.toUpperCase()
.split("")
.map((char) => 127397 + char.charCodeAt());
return String.fromCodePoint(...codePoints);
}*/
Insert cell
//getFlagEmoji("FR")
Insert cell
g = require("gridviz@3.0.0")
Insert cell
ges = require("gridviz-eurostat@2.0.0")
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