Public
Edited
Feb 25, 2023
2 stars
Insert cell
Insert cell
function macrotile(key, size = 2, parents = 2) {
let [z, x, y] = key.split("/").map((d) => parseInt(d));
let moves = 0;
while (!(moves >= parents && z % size == 0)) {
x = Math.floor(x / 2);
y = Math.floor(y / 2);
z = z - 1;
moves++;
}
return `${z}/${x}/${y}`;
}
Insert cell
viewof test = Inputs.radio(
["0/0/0", "1/1/1", "2/1/1", "2/3/3", "3/2/2", "4/10/10", "5/6/7"],
{
value: "1/1/1"
}
)
Insert cell
[...children("0/0/0").map((d) => children(d))].flat()
Insert cell
macrotile(test)
Insert cell
macrotile("4/1/1")
Insert cell
macrotile_siblings(test)
Insert cell
function children(tile) {
const [z, x, y] = tile.split("/").map((d) => parseInt(d));
if (z < 0) {
return [`${z + 1}/0/0`];
}
const children = [];
for (let i = 0; i < 4; i++) {
children.push(`${z + 1}/${x * 2 + (i % 2)}/${y * 2 + Math.floor(i / 2)}`);
}
return children;
}
Insert cell
function macrotile_siblings(key, size = 2, parents = 2) {
return macrotile_descendants(macrotile(key, size, parents), size, parents);
}
Insert cell
function macrotile_descendants(macrokey, size = 2, parents = 2) {
if (descendant_cache.has(macrokey)) {
return descendant_cache.get(macrokey);
}
const parent_tiles = [[macrokey]];
while (parent_tiles.length < parents) {
parent_tiles.unshift(parent_tiles[0].map(children).flat());
}
const sibling_tiles = [parent_tiles[0].map(children).flat()];
while (sibling_tiles.length < size) {
sibling_tiles.unshift(sibling_tiles[0].map(children).flat());
}
sibling_tiles.reverse();
const descendants = sibling_tiles.flat();
descendant_cache.set(macrokey, descendants);
return descendants;
}
Insert cell
descendant_cache = new Map()
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