Public
Edited
Mar 18
Insert cell
Insert cell
Insert cell
Insert cell
melbourne = FileAttachment("acornsat-long-annual-melbourne@1.csv").csv({ typed: true })
Insert cell
viewof field = Inputs.select(new Map([
["Daytime temperatures", "tmax"],
["Nighttime temperatures", "tmin"]]))
Insert cell
Insert cell
mutable filteredTemps = melbourne
Insert cell
Insert cell
updateTemps = {
document.startViewTransition(() => {
mutable filteredTemps = melbourne.filter(d => d.name == field)
})
}
Insert cell
tmaxPlot = Plot.plot({
marks: [
Plot.line(filteredTemps, {
x: "year",
y: "value",
stroke: field == "tmax" ? "orangered" : "royalblue"
}),
Plot.dot(filteredTemps, {
x: "year",
y: "value",
fill: field == "tmax" ? "orangered" : "royalblue",
})
],
className: "testplot"
})
Insert cell
Insert cell
Insert cell
Insert cell
mutable myDiv = html`<div></div>`
Insert cell
viewof field2 = Inputs.select(new Map([
["Daytime temperatures", "tmax"],
["Nighttime temperatures", "tmin"]]))
Insert cell
Insert cell
updateDivTemps = {
document.startViewTransition(() => {
mutable myDiv = html`<div class="myblock ${field2 == "tmax" ? "hot" : "cold"}"><p>${field2}</p></div>`
})
}
Insert cell
Insert cell
mutable mySVG = svg`<svg></svg>`
Insert cell
viewof field3 = Inputs.select(new Map([
["Daytime temperatures", "tmax"],
["Nighttime temperatures", "tmin"]]))
Insert cell
updateSVGTemps = {
document.startViewTransition(() => {
mutable mySVG = svg`<svg class="mysvg ${field3 == "tmax" ? "hot" : "cold"}">
<circle
cx="${field3 == "tmax" ? 100 : 50}"
cy=50
r=50
fill=${field3 == "tmax" ? "orangered" : "royalblue"}>
</circle>
</svg>`
})
}
Insert cell
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