Public
Edited
Sep 22, 2023
Insert cell
Insert cell
import {zip, unzip} from "@notanaccent/zip-unzip"
Insert cell
zipped = (await zip(JSON.stringify(suda)))
Insert cell
JSON.stringify(suda).length
Insert cell
suda = {
const sudaRegions = ["region_andes", "region_gran_colombia", "region_brazil", "region_la_plata"];
const sudaMapSpec = {
layerProps: mapSpec.layerProps,
colorProps: Object.fromEntries(Object.entries(mapSpec.colorProps).filter(cp => sudaRegions.includes(cp[1].region)))
}
return sudaMapSpec
}
Insert cell
mapSpec = {
const mapSpec = {
layerProps: { states: "state", regions: "region", decentralized: "isDecentralized" },
colorProps: {}
};

const getOrCreateColorProps = (color) => (mapSpec.colorProps[color] ??= {})

for (let [stateId, state] of Object.entries(states)) {
for (let color of state.provinces) {
const colorProps = getOrCreateColorProps(color);
colorProps.state = stateId;
colorProps.region = state.region;
}
}
for (let [countryId, country] of Object.entries(countries)) {
for (let color of country.provinces) {
const colorProps = getOrCreateColorProps(color);
colorProps.country = countryId;
if (!country.isDecentralized) colorProps.isDecentralized = true;
}
}
return mapSpec
}
Insert cell
_mapSpec = {
const mapSpec = {};
mapSpec.regions = new Map(Object.entries(regions).map(([id, data]) => [id, data.states.flatMap(s => states[s].provinces)]));
mapSpec.states = new Map(Object.entries(states).map(([id, data]) => [id, data.provinces]));

const decentralizedProvinces = Object.values(countries).filter(c => c.isDecentralized).flatMap(c => c.provinces);
mapSpec.decentralized = new Map([[true, decentralizedProvinces]]);
return mapSpec;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
common.state_traits
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
c = new Color("srgb", [0.11, 0.46, 0.05])
// c = new Color("jmh", [80, 50, 0]);
Insert cell
c.to("srgb").toString({format: "hex"});
Insert cell
colorScaleBasis.green.get("j")
Insert cell
Inputs.color({label: "Fill", value: colorScaleBasis.yellow.to("srgb").toString({format: "hex"}) })
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
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