Public
Edited
Apr 2, 2021
12 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
Insert cell
Insert cell
test = {
for (let i=1981; i<=2017; i++) {
let bla = await Promises.delay(3000)
yield i
}
}
Insert cell
globalPercentBelowThreshold = processedData.rollup({sum: d => op.sum(d.WeightedPopulationHeadcount)}).get("sum", 0)/summedPopulation

Insert cell
Insert cell
mutable year = 2015
Insert cell
mutable povertyThreshold = 30
Insert cell
belowColor = "#F0B8B6"
Insert cell
aboveColor = "#C2E2ED"
Insert cell
{
let clearPreviousSelector = ""
if (visitedStates.length > 0) {
clearPreviousSelector = ".countryFinder:not(" + visitedStates.map(item => ".country-" + item).toString() + ")"
d3.selectAll(visitedStates.map(item => ".country-" + item).toString()).classed("countryFinder", true)
}
else {
clearPreviousSelector = ".countryFinder"
}
d3.selectAll(clearPreviousSelector).classed("countryFinder", false)
}
Insert cell
processedData =
data
.filter(d => d.CoverageType === "N" || d.CoverageType === "A") // China, India and Indonesia have Rural and City level data as well, use only National or Aggregated to avoid double counting
.lookup(arqueroCountryCodeContinents, ["CountryCode", "iso_code"], "continent")
.orderby(aq.desc("HeadCount"))
.derive({WeightedPopulationHeadcount: aq.rolling( d => d.ReqYearPopulation * d.HeadCount)})
.derive({PopulationCumSum : aq.rolling(d => op.lag(d.ReqYearPopulation, 1, 0)) })
.derive({PopulationCumSum : aq.rolling(d => op.sum(d.PopulationCumSum)) })
Insert cell
processedData.objects()[0]
Insert cell
all = `PovertyLine=${povertyThreshold}&Countries=all&YearSelected=${year}`
Insert cell
Insert cell
url = `https://povcalnet-cors-proxy.herokuapp.com/http://iresearch.worldbank.org/PovcalNet/PovcalNetAPI.ashx?${all}&display=C&format=csv`
Insert cell
Insert cell
data = aq.fromCSV(await fetch(url).then(res => res.text()), { header: true })
Insert cell
summedPopulation = processedData.rollup({ PopulationSum: op.sum('ReqYearPopulation') }).get("PopulationSum", 0)
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).tickSizeOuter(0))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(null, "%"))
.call(g => g.select(".domain").remove())
Insert cell
x = d3.scaleLinear()
.domain([0, 7500])
.rangeRound([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(processedData.columnArray("HeadCount"))])
.range([height - margin.bottom, margin.top])
Insert cell
height = 500
Insert cell
margin = ({top: 100, right: 0, bottom: 40, left: 50})
Insert cell
countryFetchArgs = ({
"columns": ["iso_code", "continent", "date"],
"condition": {
"and": [
{
"eq": [
{
"column": [
"date"
]
},
"2021-03-01"
]
}
]
},
"includeAggregations": true,
"aggregationFilters": [],
"offset": 0,
"limit": null,
"orderBy":
[]
})
Insert cell
getDataFiltered = function(query) {
const encodedQuery = JSON.stringify(query)
let url = new URL("https://api.edelweissdata.com/datasets/b55b229d-6338-4e41-a507-0cf4d3297b54/versions/315/data")
url.searchParams.append('query', encodedQuery);
return fetch(url).then(response => response.json()).then(data => data.results.map(row => row.data))
}
Insert cell
countryCodeContinents = getDataFiltered(countryFetchArgs)
Insert cell
arqueroCountryCodeContinents = aq.from(countryCodeContinents)
Insert cell
arqueroCountryCodeContinents.view()

Insert cell
new Set(arqueroCountryCodeContinents.columnArray("continent"))
Insert cell
Insert cell
import {Range, Table, Select, Toggle} from "@observablehq/inputs"
Insert cell
import {debounce} from "@mbostock/debouncing-input"
Insert cell
d3 = require("d3@6")
Insert cell
import { aq, op, desc } from '@uwdata/arquero'
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