barChart = data => {
const dim = {
width: 300,
height: 150,
top: 5,
left: 40,
bottom: 40,
right: 20,
}
const casesFieldName = 'New Cases Per Capita'
const timeScale = d3.scaleTime()
.domain([
d3.min(data, d => d.Date),
d3.max(data, d => d.Date)
])
.range([dim.left, dim.width - dim.right])
const caseScale = d3.scaleLinear()
.domain([
0,
Math.max(0.003, d3.max(data, d => d[casesFieldName]))
])
.range([dim.height - dim.bottom, dim.top])
const leftAxis = d3.axisLeft(caseScale)
.ticks(5)
.tickFormat(d => d3.format('d')(d * 100000))
const bottomAxis = d3.axisBottom(timeScale)
.tickFormat(d3.timeFormat('%b'))
const chart = d3.select(svg`<svg viewbox="0 0 ${dim.width} ${dim.height}"/>`)
chart.append('g')
.attr('transform', `translate(${dim.left}, 0)`)
.call(leftAxis)
chart.append('g')
.attr('transform', `translate(0, ${dim.height - dim.bottom})`)
.call(bottomAxis)
chart.append('g')
.selectAll('rect')
.data(data.filter(d => !isNaN(d[casesFieldName])))
.join('rect')
.attr('x', d => timeScale(d3.timeWeek.offset(d.Date, -1)) + 1)
.attr('y', d => caseScale(d[casesFieldName]))
.attr('width', d => timeScale(d.Date) - timeScale(d3.timeWeek.offset(d.Date, -1)) - 2)
.attr('height', d => dim.height - dim.bottom - caseScale(d[casesFieldName]))
.attr('fill', d => perCapitaColorScale(d[casesFieldName]))
const latest2 = data.slice(-2)
chart.append('line')
.attr('x1', )
return chart.node()
}