Public
Edited
May 16, 2024
1 star
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
buildingsDataset = new gridviz.MultiResolutionDataset(
[1000, 2000, 5000, 10000, 20000, 50000, 100000],
(resolution) =>
new gridviz.TiledGrid(
map,
"https://raw.githubusercontent.com/joewdavies/tiled-grids/main/buildings/" +
resolution +
"m/"
)
)
Insert cell
Insert cell
colors = [
"#FFEB99",
"#D1E9B0",
"#8DD6B9",
"#58C1C0",
"#3792B6",
"#134891",
"#17256B",
]
Insert cell
colorFunction = (cell) => {
if (cell.value > 1000) return colors[6]
if (cell.value > 900) return colors[5]
if (cell.value > 800) return colors[4]
if (cell.value > 600) return colors[3]
if (cell.value > 400) return colors[2]
if (cell.value > 300) return colors[1]
if (cell.value > 100) return colors[0]
}
Insert cell
colorScale = d3.interpolateCividis
Insert cell
Insert cell
colorStyle = new gridviz.ShapeColorSizeStyle({
color: (c, r, z, viewScale) => viewScale(c.value),
viewScale: gridviz.viewScaleColor({
valueFunction: (c) => +c.value,
colorScale: colorScale,
stretching: gridviz.logarithmicScale(-7)
})
})
Insert cell
joyplotStyle = new gridviz.JoyPlotStyle({
height: (c) => Math.sqrt(c.value) * 100,
lineColor: () => "white",
lineWidth: (y, ys, r, z) => (z < 599 ? 2 * z : 1 * z),
fillColor: () => "black"
})
Insert cell
pillarStyle = new gridviz.PillarStyle({
viewScale: (cells) => d3.max(cells, (cell) => +cell.value),
height: (cell, resolution, z, max) => (300 * z * cell.value) / max,
simple: () => true,
color: () => "#FF3D12aa",
viewHeightFactor: 5,
width: (cell, resolution) => 0.3 * resolution,
viewSX: -0.7,
viewSY: -3,
shadowDirection: (21 * Math.PI) / 180.0,
shadowFactor: 0.5
})
Insert cell
tanakaStyle = gridviz.TanakaStyle.get(
(cell) => cell.value,
[100, 200, 500, 1000, 2000],
["#ffffd4", "#fee391", "#fec44f", "#fe9929", "#d95f0e", "#993404"]
)
Insert cell
Insert cell
//define legend
legend = new gridviz.ColorLegend({
title: "Number of buildings per km",
colorScale: colorScale,
ticks: 4,
textScale: (t, vs) => Math.floor(vs?.invert(t))
})
Insert cell
Insert cell
colorStyle.legends = [legend]
Insert cell
Insert cell
buildingsLayer = new gridviz.GridLayer(buildingsDataset, [], {
cellInfoHTML: (cell, r) =>
`<strong>${cell.value}</strong> buildings / ${r / 1000}km²`
})
Insert cell
(map.layers = [buildingsLayer, boundariesLayer, labelLayer])
Insert cell
Insert cell
{
// thank you Julien!
buildingsLayer.styles = [style];
map.redraw();
}
Insert cell
Insert cell
gridviz = require("gridviz")
Insert cell
gridvizEurostat = require("gridviz-eurostat")
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