Public
Edited
Mar 6, 2023
Insert cell
Insert cell
viewof dateFormat = Inputs.text({label: "Date Format", value: "%b %d %Y", submit: true})
Insert cell
TimeSearcher(data)
Insert cell
dataRaw = {
// let data = await (d3.csv("https://vega.github.io/vega-datasets/data/stocks.csv"))
// data.forEach(d => { d["price"] = ~~d["price"]})

let data = await FileAttachment("sp500_20-22.csv").csv({typed: true})

for (let d of data) {
d.price = +d.Close;
}
return data.filter(d => d.stock !== "BRK-A") // remove an outlier
}
Insert cell
fmt = d3.timeParse(dateFormat)
Insert cell
data = {
// Forces re- execution with dateFormat changes
// dateFormat;

if (dataNoFormat[0][xAttrRaw] instanceof Date ) {
dataNoFormat.forEach((d) => {
d[xAttr] = d[xAttrRaw];
});
} else {
dataNoFormat.forEach((d) => {
d[xAttr] = fmt(d[xAttrRaw]);
});
}
return dataNoFormat;
}
Insert cell
d3 = require("d3@7")
Insert cell
import {TimeSearcher} from "@ivelascog/time-searcher"
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