make_chart = (data, width, domain) => {
const rule_1 = vl
.markRule()
.data(
vl.json().values({
rally: '2020-05-30'
})
)
.encode(vl.x().fieldT('rally'));
const label_1 = vl
.markText({ xOffset: '-55', yOffset: "-150" })
.data(
vl.json().values({
label: 'First George Floyd Rally',
rally: '2020-05-30'
})
)
.encode(vl.text().fieldN('label'), vl.x().fieldT('rally'));
const bars = vl.markBar({ opacity: 0.1 }).encode(
vl
.x()
.fieldT('date')
.timeUnit('utcyearmonthday')
.scale({ domain: date_extent_two, paddingInner: 0.1, paddingOuter: 0 })
.axis({ tickCount: 'month', format: '%B', grid: false, tickSize: 6 })
.title(null),
vl
.y()
.fieldQ(type)
.scale({ domain, nice: false })
.axis({
tickCount: 4,
domain: false,
ticks: false,
labelAlign: 'left',
labelBaseline: 'bottom'
})
.title(null),
vl.color({ value: 'blue' }),
vl.tooltip([vl.fieldT('date'), 'cases', 'deaths'])
);
const xOffset =
width /
d3.timeDay.count(
new Date(date_extent_two[0]),
new Date(date_extent_two[1])
);
const line = bars
.markLine({ interpolate: 'monotone', xOffset })
.encode(vl.y().fieldQ('mean'));
const area = line.markArea({ opacity: 0.2, xOffset });
return vl
.layer(bars, area, line)
.data(data)
.transform(
vl.window({ op: 'mean', field: type, as: 'mean' }).frame([-3, 3])
)
.width(width)
.height(width / 3)
.autosize({ type: 'fit-x', contains: 'padding' })
.config({
style: { cell: { stroke: 'transparent' } },
axis: { labelColor: '#929292', gridColor: '#ececec', title: null },
padding: { top: 5, right: 5, bottom: 5, left: 5 }
})
.render();
}