Public
Edited
Jun 4, 2023
1 fork
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
table[table.length - 1]
Insert cell
table = {
var our_parseInt = x => x == "" ? 0/0 : parseInt(x);
var n_prefix = commute_group == 'work' ? '' : 's';
var t = our_pop_data.map(x => ({
dep_score: parseInt(x.dep_score),
dep: our_parseInt(x.dep),
population: parseInt(x.population),
share: x[mode_to_display.key] * 1.0 / x[n_prefix + 'n'],
n:parseInt(x[n_prefix + 'n']),
n_share:our_parseInt(x[mode_to_display.key]),
name: x.name
}));
t = t.filter(x => !isNaN(x.dep_score) && !isNaN(x.n_share))
t = t.sort((x, y) => (x.dep_score - y.dep_score));
var c_pop = 0;
var c_n = 0;
var c_n_share = 0;
t.forEach(function(x)
{
x.c_pop = c_pop; c_pop += x.population;
x.c_n = c_n; c_n += (+x.n || 0);
x.c_n_share = c_n_share; c_n_share += (+x.n_share || 0);
});
return t;
}
Insert cell
table[400]
Insert cell
our_pop_data = commute_group == "work" ?
census_input_data.pop_data :
merge(census_input_data.pop_data_s, census_input_data.pop_data)
Insert cell
function merge(a, b)
{
var m = {};
var c = [];
a.forEach(x => m[x.ID] = x);
b.forEach(x => c.push({...x, ...m[x.ID]}));
return c;
}
Insert cell
small_table = {
var small_table = [];
for (var i = 0; i < 10; ++i) { small_table.push({dep: i+1, n:0, n_share:0, population:0, dep_x:0, amount:0}); }
table.forEach(x => {
if (!x.dep) return;
if (!(x.n > 0)) return;
var y = small_table[x.dep - 1];
y.n += x.n;
y.amount += 1;
y.n_share += (x.n_share || 0);
y.population += x.population;
y.dep_x += x.dep_score;
})
var c_pop = 0;
var pop_margin = 1000;
small_table.forEach(x => {
x.share = x.n_share * 1.0 / x.n;
x.pop_x1 = c_pop + pop_margin;
x.pop_xmid = c_pop + x.population * .5;
x.pop_x2 = c_pop + x.population;
c_pop += x.population;
x.dep_x /= x.amount
})
return small_table;
}
Insert cell
import { census_input_data, mode_choices, param }
with {sa_type as sa_type, commute_group as commute_group}
from "@roelandschoukens/mode-share-map"
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