Published
Edited
Aug 10, 2021
4 forks
17 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
// Generate a simple point set for
Insert cell
hierarchy = {
let config = {
dataset: pointsRoutes,
// groupByFns: [d => d.continent, d => d.country, d => d.code],
groupByFns: [d => d.country, d => d.code],
reduceFn: v => d3.sum(v, d => d["routes"])
}
const defaultConfig = {
childrenAccessorFn: ([key, value]) => value.size && Array.from(value),
sumFn: ([key, value]) => value,
sortFn: (a, b) => b.value - a.value,
};
const { dataset, reduceFn, groupByFns, childrenAccessorFn, sumFn, sortFn } = { ...defaultConfig, ...config };
const rollupData = d3.rollup(dataset, reduceFn, ...groupByFns);
const hierarchyData = d3.hierarchy([null, rollupData], childrenAccessorFn)
.sum(sumFn)
.sort(sortFn);
return hierarchyData;
}
Insert cell
Insert cell
Insert cell
// Generate a lookup string for easier searching in the AutoSelect
Insert cell
Insert cell
// Pull the IATA code from the autoselect to use for filtering, this could be optimized but the existing autoselect input doesn't seem to work with value/label pairs
Insert cell
Insert cell
Insert cell
Insert cell
chartTip = d3.select("body").append("div").attr("class", "toolTip chartTip");
Insert cell
Insert cell
import { world } from "@benoldenburg/simple-globe"
Insert cell
import {select, autoSelect} from "@jashkenas/inputs"
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@6") // Load D3
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