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

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