Published
Edited
Oct 4, 2021
3 forks
Importers
40 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rawdata = FileAttachment("TexasEnergyDemandForecast@1.csv").csv({typed: true})
Insert cell
data = aq.from(rawdata) // https://observablehq.com/@observablehq/data-wrangler
.rename({demand: "actuals"}) // rename column from “demand” to “actuals”
.objects() // return an array of objects
Insert cell
Insert cell
event = ({
description: "Rolling Blackouts",
datetime: new Date("2021-02-15T07:25:00Z") // 7:25AM UTC is 1:25AM CST
})
Insert cell
Insert cell
zoom = {
const start = d3.isoParse("2021-02-07T07:25:00Z");
const end = d3.isoParse("2021-02-16T07:25:00Z");
return (d) => +d.date >= +start && +d.date <= +end;
}
Insert cell
zoomed = data.filter(zoom)
Insert cell
Insert cell
zoomedTicks = d3.utcDays(...d3.extent(zoomed, d => d.date)).map(d => d3.utcHour.offset(d, 6))
Insert cell
dataTicks = d3.utcWeeks(...d3.extent(data, d => d.date)).map(d => d3.utcHour.offset(d, 6))
Insert cell
Insert cell
colors = new Map([
["actuals", "#5b6187"],
["forecast", "#a2a5ba"],
["below", "#89119c"], // actuals below forecast
["above", "#ff6300"], // actuals above forecast
])
Insert cell
Insert cell
resp = {return width>500 ? 1: 2 }
Insert cell
demandBelowForecastAnnotation =
[
Plot.text([{value: "demand falls below forecast ➣"}], {
text: "value",
x: d3.utcHour.offset(event.datetime, -36),
y: -4000,
textAnchor: "end",
fontSize: resp*width/70,//16,
fontStyle: 'italic'
})
]
Insert cell
demandAboveForecastAnnotation =
[
Plot.text([{value: "demand rises above forecast ➣"}], {
text: "value",
x: d3.utcHour.offset(event.datetime, -134),
y: 6200,
textAnchor: "end",
fontSize: resp*width/70,//16,
fontStyle: 'italic'
})
]
Insert cell
// point out where the demand dropped below the forecast
didYouNoticeThis =
[
Plot.text([{value: "Did you notice demand drop below forecast here? ⇘"}], {
text: "value",
x: d3.utcHour.offset(event.datetime, -36),
y: 67000,
textAnchor: "end",
fontSize: 16,
fontStyle: 'italic'
})
]
Insert cell
// show when the rolling blackouts started on the difference chart
annotationsDeltas =
[
Plot.ruleX([event.datetime], {
stroke: "gray",
y1: 0,
y2: maxDelta
}),
// text describing the event of interest
Plot.text([event], {
text: "description",
x: "datetime",
y: maxDelta * 1.05,
textAnchor: "start"
}),
]
Insert cell
Insert cell
maxDelta = d3.max(data, d => d.actuals - d.forecast)
Insert cell
maxValue = Math.max(d3.max(data, d => d.actuals), d3.max(data, d => d.forecast))
Insert cell
Insert cell
import {textcolor} from "@observablehq/text-color-annotations-in-markdown"
Insert cell
import {authorship, navigation, workshop, altauthorship} from "@observablehq/timeseries-assets"
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