Public
Edited
Jul 30, 2024
1 star
Insert cell
Insert cell
focus
Insert cell
Insert cell
Insert cell
margin = ({ top: 4, right: 20, bottom: 30, left: 40 })
Insert cell
brusedAllDates = d3.timeMonth
.range(new Date(focus[0]), new Date(focus[1]))
.map((d) => d.toISOString().substring(0, 10))
Insert cell
Insert cell
d3.scaleDiverging((t) => d3.interpolateRdBu(1 - t))
Insert cell
sstaColors(0)
Insert cell
sstaColors = d3.scaleDiverging(d3.interpolateRdBu).domain([4, 0, -4])
Insert cell
x = d3
.scaleTime()
.domain(dateExtent)
.range([margin.left, width - margin.right])

Insert cell
brushedData = data.filter(
(d) => d.date > focus[0] && new Date(d.date) < new Date(focus[1])
)
Insert cell
x1 = d3
.scaleBand()
.range([margin.left, width - margin.right], 0.01)
.padding(0.1)
.domain(alldates)
Insert cell
dateExtent = [d3.min(data, (d) => d.date), d3.max(data, (d) => d.date)]
Insert cell
alldates = d3.timeMonth
.range(new Date(dateExtent[0]), new Date("2022-03-01"))
.map((d) => d.toISOString().substring(0, 10))
Insert cell
y = d3
.scaleLinear()
.domain([0, 1])
.range([focusHeight - margin.bottom, margin.top])
Insert cell
dataSsta = FileAttachment("monthly@6.json").json()
Insert cell
xAxis = (g, x, height) =>
g.attr("transform", `translate(0,${height - margin.bottom})`).call(
d3
.axisBottom(x)
.ticks(width / 80)
.tickSizeOuter(0)
)
Insert cell
yAxis = (g, y, title) => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".title").data([title]).join("text")
.attr("class", "title")
.attr("x", -margin.left)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.text(title))
Insert cell
height = 240
Insert cell
focusHeight = 100
Insert cell
d3 = require("d3@6")
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