Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
covid = d3.csvParse(await FileAttachment("VDH-COVID-19-PublicUseDataset-Cases.csv").text(), function(d) {
return {
date: d3.timeParse("%x")(d["Report Date"]),
fips: d.FIPS,
locality: d.Locality,
district: d["VDH Health District"],
cases: +d["Total Cases"],
hospitalizations: +d.Hospitalizations,
deaths: +d.Deaths
};
});
Insert cell
Insert cell
covid.sort(function (a, b) {
return a.date - b.date;
});
Insert cell
Insert cell
printTable(covid.slice(0,5))
Insert cell
printTable(covid.slice(-5))
Insert cell
Insert cell
hr_districts = new Set(["Western Tidewater", "Chesapeake", "Virginia Beach", "Norfolk", "Portsmouth", "Hampton", "Peninsula"])
Insert cell
hr_covid = covid.filter(d => hr_districts.has(d.district))
Insert cell
Insert cell
Insert cell
last_date = covid[covid.length-1].date
Insert cell
covid_totals = covid.filter(d => d.date >= last_date)
Insert cell
hr_totals = covid_totals.filter(d => hr_districts.has(d.district))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
margin = ({top: 10, right: 10, bottom: 20, left: 60});
Insert cell
Insert cell
height = 400;
Insert cell
Insert cell
xscale = d3.scaleTime()
.domain([d3.min(covid_cases_objects, d => d.date), d3.max(covid_totals, d => d.date)])
.range([margin.left, width - margin.right]);
Insert cell
Insert cell
yscale = d3.scaleLinear()
.domain([0, d3.max(covid_cases_objects, d => d.cases)])
.range([height - margin.bottom, margin.top]);
Insert cell
Insert cell
container = d3.create('svg')
.attr('width', width)
.attr('height', height)
.style('border', '1px dotted #999');
Insert cell
Insert cell
Insert cell
single_district_covid = covid.filter(d => single_district.has(d.district))
Insert cell
Insert cell
covid_cases_rollup = d3.rollups(single_district_covid, v => d3.sum(v, d => d.cases), d => d.date);
Insert cell
Insert cell
covid_cases_objects = covid_cases_rollup.map(obj => { let rObj= {}; rObj["date"] = obj[0]; rObj["cases"] = obj[1]; return rObj;})
Insert cell
Insert cell
Insert cell
{
// Append the x axis
container.append('g')
.attr('transform', `translate(0, ${height - margin.bottom})`)
.call(d3.axisBottom(xscale));

// Append the y axis
container.append('g')
.attr('transform', `translate(${margin.left}, 0)`)
.call(d3.axisLeft(yscale));
const line = d3.line()
.x(d => xscale(d.date))
.y(d => yscale(d.cases))
container.append("path")
.datum(covid_cases_objects)
.style("fill", "none") // Line does not need fill
.style("stroke", "steelblue") // Set the line color
.style("stroke-width", 1.5) // Set the line width
.style('stroke-miterlimit', '1')
.attr("d", line);
return container.node();
}
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
import {printTable} from '@uwdata/data-utilities'
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