Public
Edited
Aug 11, 2024
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
regionData
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
reducedCodes = [
"UA-05", // Vinnytsia
// "UA-30", // Kyiv city
"UA-32", // Kyiv oblast
"UA-74",
"UA-18",
"UA-71", // Cherkasy
"UA-53", // Poltava
]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
iso2dist = new Map(inclRegionData.map(d => [d.iso, +d.kyiv_dist]));
Insert cell
computeReceived("UA-32")
Insert cell
computeReceived("UA-53")
Insert cell
function computeReceived(isoCode) {
// First we get the amount *allocated*
var allocAmount = getAllocation(isoCode);
//return(allocAmount);
// Now we get distance
var kyivDist = iso2dist.get(isoCode);
//return(kyivDist);
// Now we decay based on distance
var fracRemaining = Math.exp(-kyivDist * globs.decayRate);
//return(fracRemaining);
// Ensure it doesn't go below 0
fracRemaining = Math.max(fracRemaining, 0.0);
//return(fracRemaining);
var amtRemaining = allocAmount * fracRemaining;
// And return
return(Math.round(amtRemaining * 100, 2) / 100);
}
Insert cell
function computeUnmet(isoCode) {
var totalDemand = getDemand(isoCode);
var received = computeReceived(isoCode);
return(totalDemand - received);
}
Insert cell
function resetAlloc() {
set(viewof kyiv, globs.defaultAlloc);
set(viewof cherkasy, globs.defaultAlloc);
set(viewof chernihiv, globs.defaultAlloc);
set(viewof poltava, globs.defaultAlloc);
set(viewof vinnytsia, globs.defaultAlloc);
set(viewof zhytomyr, globs.defaultAlloc);
}
Insert cell
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input"));
}
Insert cell
Insert cell
// Computes remaining *total* unmet demand
totalUnmet = {
var unmetRaw = inclCodes.map(d => computeUnmet(d)).reduce((a,b) => a + b);
return(Math.round(unmetRaw * 100, 2) / 100);
}
Insert cell
// Computes remaining *total* budget available
totalAllocated = inclCodes.map(d => getAllocation(d)).reduce((a,b) => a + b)
Insert cell
totalRemaining = globs.totalBudget - totalAllocated;
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
color = d3.scaleQuantize([0, 10], d3.schemeReds[9])
Insert cell
format = d => Math.round(`${d}`)
Insert cell
globs = ({
decayRate: 1.0/200.0,
totalBudget: 50,
defaultAlloc: 0,
gridCellWidth: '276px',
labelWidth: '145px',
sliderWidth: 80,
});
Insert cell
Insert cell
Insert cell
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
import {addTooltips} from "@mkfreeman/plot-tooltip"
Insert cell
feather = require("feather-icons") // https://www.npmjs.com/package/feather-icons
Insert cell
extIcon = md`${feather.icons['external-link'].toSvg({width: 16, height: 16})}`
Insert cell
Insert cell
Insert cell
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