Public
Edited
Feb 25, 2024
Importers
Insert cell
md`# Toolbelt / Imports`
Insert cell
luxon = require('luxon@3/build/global/luxon.min.js').catch(
() => window["luxon"]
)
Insert cell
moment_timezone = require('https://bundle.run/moment-timezone@0.5.33')
Insert cell
DateTime = luxon.DateTime
Insert cell
isoDate = d3.utcFormat("%Y-%m-%d")
Insert cell
axios = require('axios')
Insert cell
<style>
/* fix tip text color on mobile */
@media screen and (max-width: 520px) {
[aria-label=tip] text {color: steelblue; font-size: 120%;}
}
</style>
Insert cell
formatDecimal = d3.format(".2f")
Insert cell
formatCurrency = d3.format(",.2f")
Insert cell
formatEur = d => (d).toLocaleString('en-US', {style:"currency", currency: "EUR"}) // €33.00
Insert cell
formatPct = d3.format(".2%")
Insert cell
formatSignedPct = d3.format("+.2%")
Insert cell
// de-duplicate an array of objects
function deduplicateArray(arr, key) {
return [...arr.reduce((map, d) => map.set(key(d), d), new Map()).values()];
}
Insert cell
import {download} from '@oluckyman/toolbelt' // Download to csv file
Insert cell
download(cars, 'cars.csv', true)
Insert cell
// split up an array into chunks of approximate length
import { chunks } from "@tophtucker/scrapbook"
Insert cell
function proxifyUrl(url) {
return "https://corsproxy.io/?" + encodeURIComponent(url);
}
Insert cell
import {scaleFreeY} from '@mayagans/from-ggplot2-to-plot'
Insert cell
scaleFreeX = (options) =>
Plot.initializer(options, (data, facets, channels, scales, dimensions) => {
const {x: { value: X, scale }} = channels;
debugger
for (const index of facets) {
const x = d3.scaleBand(d3.sort(Array.from(index, (i) => X[i])), [
dimensions.marginTop,
dimensions.height - dimensions.marginBottom
])
.padding(0.5);
for (const i of index) X[i] = x(X[i]);
}
return { data, facets, channels: { x: { value: X } } };
})
Insert cell
import {Copier as pbcopy} from "@mbostock/copier"
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