Published
Edited
Feb 25, 2021
17 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
diff = await d3.text(
`https://api.github.com/repos/iandees/usps-collection-boxes/compare/${startCommit}...${endCommit}`,
{
headers: {
Accept: "application/vnd.github.v3.diff"
}
}
)
Insert cell
Insert cell
changes = diff
.split("\n")
.filter(d => d.startsWith("+") || d.startsWith("-"))
.map(d => {
try {
const feature = JSON.parse(d.slice(1));
feature.properties.status = d.slice(0, 1) === "-" ? "removed" : "added";
return feature;
} catch (e) {
return null;
}
})
.filter(d => d)
Insert cell
Insert cell
grouped = d3.group(changes, d => d.properties.ref, d => d.properties.status)
Insert cell
data = changes.filter(d => grouped.get(d.properties.ref).size === 1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
import { table } from "@tmcw/tables/2"
Insert cell
import { tweet } from "@mbostock/tweet"
Insert cell
token = "pk.eyJ1Ijoia2Vycnlyb2RkZW4iLCJhIjoiY2tlYWJtNXdrMDNjazJybzdsdWR1MXQxNiJ9.201r3UVK3fORKawabrfkqw"
Insert cell
mapboxgl = {
const gl = await require("mapbox-gl@1");
if (!gl.accessToken) {
// https://www.mapbox.com/help/how-access-tokens-work/
gl.accessToken = token;
const href = await require.resolve("mapbox-gl@1/dist/mapbox-gl.css");
document.head.appendChild(html`<link href=${href} rel=stylesheet>`);
}
return gl;
}
Insert cell
lastChecked = new Date(
(await d3.text(
"https://raw.githubusercontent.com/iandees/usps-collection-boxes/master/data/last_updated.txt"
)).trim()
)
Insert cell
addedColor = "#3bb2d0"
Insert cell
removedColor = "#ff7f00"
Insert cell
inlineDot = color =>
html`<div style="display: inline-block; background: ${color};
border-radius: 50%; width: 12px; height: 12px;"></div>`
Insert cell
addressTable = (features, properties) =>
table(
features.map(d => ({
address: d.properties["addr:full"],
city: `${d.properties["addr:city"]}, ${d.properties["addr:state"]}`,
zip: d.properties["addr:postcode"]
})),
properties
)
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