Public
Edited
Sep 21, 2021
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
function pointMark(table, opacity)
{
return vl.markPoint()
.data(table)
.width(500)
.height(400)
.encode(
vl.x().fieldQ('ownership').axis({title: "cars per 20y+"}),
vl.y().fieldQ('share').axis({title: "Car mode share", format: "%"}),
vl.color().fieldQ('dep').title('NZiDep2018').scale({scheme: ["#06f", "#f30"]}),
vl.size().fieldQ('population').title('Population'),
vl.tooltip().fieldN('name'),
vl.opacity().value(opacity ? opacity : sa_type == 1 ? .15 : .5),
);
}
Insert cell
Insert cell
table[table.length - 1]
Insert cell
table = {
var n_prefix = commute_group == 'work' ? '' : 's';
var t = our_pop_data.map(function (x) {
var c = cars[x.ID];
var pop = parseInt(x.population);
var lb = parent_X[x.ID];
var n = x[n_prefix + 'n_car'];
if (sa_type == 1) lb = lb && parent_2[lb.parent];
lb = lb && lb.parent;
return {
dep: parseInt(x.dep),
population: pop,
share: n != "" ? n * 1.0 / x[n_prefix + 'n'] : 0.0/0.0,
ownership: Math.min(1.5, c.cars_count / (c.prop_20_plus * pop)), // clamp
cars_stated: c.cars_totalstated,
name: x.name,
waitemata: lb == WAITEMATA_ID
}
});
t = t.filter(x => !isNaN(x.dep) && !isNaN(x.ownership) && x.cars_stated > 0 && !isNaN(x.share))
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
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 = as_map(a);
var c = [];
b.forEach(x => c.push({...x, ...m[x.ID]}));
return c;
}
Insert cell
census_input_data = get_census_input_data({'pop_data':true, 'pop_data_s':commute_group=='study', 'car':true, 'parents':true}, sa_type)
Insert cell
parent_2 = as_map((await get_census_input_data({'parents':true}, 2)).parents)
Insert cell
parent_X = sa_type == 2 ? parent_2 : as_map(census_input_data.parents)
Insert cell
Insert cell
cars = as_map(census_input_data.car)
Insert cell
import { get_census_input_data, mode_share_header, param, as_map }
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