Public
Edited
Jul 12, 2023
2 forks
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formatTime = d3.utcFormat("%H:%M %B %d, %Y")
Insert cell
avgIntensity = intensityCalc()
Insert cell
intensityCalc = function() {
const [minX, maxX] = focus;
const meanIntensity = d3.mean(data, d => minX <= d.date && d.date <= maxX ? d.value : NaN);
return meanIntensity
}
Insert cell
update = {
const [minX, maxX] = focus;
const maxY = d3.max(data, d => minX <= d.date && d.date <= maxX ? d.value : NaN);
chart.update(x.copy().domain(focus), y.copy().domain([0, maxY]));
}
Insert cell
data = Object.assign(d3.csvParse(await FileAttachment("NL_2022_hourly.csv").text(), d3.autoType)).map(function(obj) { return {
date: new Date(obj['Datetime (UTC)']),
value: obj['Carbon Intensity gCO₂eq/kWh (direct)'],
}
})
Insert cell
area = (x, y) => d3.area()
.defined(d => !isNaN(d.value))
.x(d => x(d.date))
.y0(y(0))
.y1(d => y(d.value))
Insert cell
x = d3.scaleUtc()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.value)])
.range([height - margin.bottom, margin.top])
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
margin = ({top: 20, right: 20, bottom: 30, left: 40})
Insert cell
height = 440
Insert cell
focusHeight = 100
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