Published
Edited
Apr 30, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
average_value = good_rows.reduce((a, c) => a + c[2], 0) / good_rows.length
Insert cell
min_value = good_rows.reduce((a, c) => Math.min(a, c[2]), good_rows[0][2])
Insert cell
max_value = good_rows.reduce((a, c) => Math.max(a, c[2]), good_rows[0][2])
Insert cell
std_dev = Math.sqrt(
good_rows.reduce((a, c) => a + Math.pow(c[2] - average_value, 2), 0) /
good_rows.length
)
Insert cell
centered_rows = good_rows.map(r => {
r[2] = (r[2] - min_value) / (max_value - min_value);
return r;
})
Insert cell
centered_min = Math.min(...centered_rows.map(v => v[2]))
Insert cell
centered_max = Math.max(...centered_rows.map(v => v[2]))
Insert cell
centered_mean = centered_rows.reduce((a, c) => a + c[2], 0) /
centered_rows.length
Insert cell
Insert cell
forecast_data = await FileAttachment("all.data@3.json").json()
Insert cell
forecast_cells = (await FileAttachment("apparent.temp.csv").text())
.split(/\n/)
.filter(v => v != '')
.map(v => v.split(/,/))
Insert cell
h3 = require('h3-js')
Insert cell
L = require('leaflet@1.2.0')
Insert cell
html`<link href='${resolve(
'leaflet@1.2.0/dist/leaflet.css'
)}' rel='stylesheet' /><style>

.legend {
line-height: 18px;
color: #555;
border: 1px solid #000000;
border-radius: 4px;
padding: 8px;
background: rgba(255,255,255,0.8);
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}</style>`
Insert cell
import { slider } from "@jashkenas/inputs"
Insert cell
d3 = require("d3@5")
Insert cell
margin = ({ top: 20, right: 20, bottom: 30, left: 40 })
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(bins, d => d.length)]).nice()
.range([height - margin.bottom, margin.top])
Insert cell
data = centered_rows.map(r => r[2])
Insert cell
x = d3
.scaleLinear()
.domain(d3.extent(data))
.nice()
.range([margin.left, width - margin.right])
Insert cell
bins = d3
.histogram()
.domain(x.domain())
.thresholds(x.ticks(40))(data)
Insert cell
height = 300
Insert cell
yAxis = g =>
g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(height / 40))
.call(g => g.select(".domain").remove())
.call(g =>
g
.select(".tick:last-of-type text")
.clone()
.attr("x", 4)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(data.y)
)
Insert cell
xAxis = g =>
g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(
d3
.axisBottom(x)
.ticks(width / 80)
.tickSizeOuter(0)
)
.call(g =>
g
.append("text")
.attr("x", width - margin.right)
.attr("y", -4)
.attr("fill", "currentColor")
.attr("font-weight", "bold")
.attr("text-anchor", "end")
.text(data.x)
)
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