Public
Edited
Nov 26, 2022
Insert cell
# Asylum Sankey Data Cleaning + Restructure
Insert cell
Insert cell
rawdata = d3.json('https://raw.githubusercontent.com/tkalainoff/major-studio/main/qual/data/AFG_2021.json').then(data => _.values(data));
Insert cell
data = rawdata[0]
Insert cell
totalSumofRec = parseInt(d3.sum(data, item => item['Recognized decisions']))
Insert cell
totalSumofALLDec = parseInt(d3.sum(data, item => item['Total decisions']))
Insert cell
data[14]['Total decisions']/parseInt(d3.sum(data, item => item['Total decisions']))*100
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
// need to figure out how to merge countries to dedeupe
function getNodes(array){
let nodes = []

for(let i=0; i<array.length; i++){
let newNode = {}

//newNode.nodeNum = i
newNode.nodeName = array[i]['Country of asylum']
nodes.push(newNode)
}

nodes.push(
{nodeName: "Afghanistan"},
{nodeName: "Other"},
{nodeName: "Recognized decisions"},
{nodeName: "Complementary protection"},
{nodeName: "Rejected decisions"},
{nodeName: "Otherwise closed"})

nodes = getUniqueListBy(nodes, 'nodeName')
return nodes
}
Insert cell
nodes = getNodes(data)
Insert cell
function getUniqueListBy(arr, key) {
return [...new Map(arr.map(item => [item[key], item])).values()]
}
Insert cell
Insert cell
wave1 = getLinks_wave1(data)
Insert cell
sigCountries = d3.group(wave1, d=> d.target)
Insert cell
sigCountries_sum = d3.flatRollup(wave1, v => d3.sum(v, d => d.value), d => d.target)
Insert cell
Insert cell
linksRecognized = getLinks_Rec(data)
Insert cell
Insert cell
linksProtected = getLinks_Pro(data)
Insert cell
Insert cell
linksRejected = getLinks_Rej(data)
Insert cell
Insert cell
linksClosed = getLinks_Clo(data)
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