plot = {
const hover = vl.selectPoint('hover')
.encodings('x')
.on('mouseover')
.toggle(false)
.nearest(true);
const isHovered = hover.empty(false);
const line1 = vl.markLine().encode(
vl.x().fieldT('date').axis({title: 'Date'}),
vl.y().fieldQ('shooting_count').axis({title: 'Shooting Count'}).scale({"domain": [0,150]})
);
const line2 = vl.markLine().encode(
vl.x().fieldT('date').axis({title: 'Date'}),
vl.y().fieldQ('search_count').axis({title: 'Google Search Popularity Score'}).scale({"domain": [0,105]})
);
const base1 = line1.transform(vl.filter(isHovered));
const base2 = line2.transform(vl.filter(isHovered))
const label = {align: 'left', dx: 5, dy: -5};
const white = {stroke: 'white', strokeWidth: 2};
const plot1 = vl.data('https://raw.githubusercontent.com/cse412-21sp/fatal-police-shooting/main/data/search_history.csv')
.layer(
line1,
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldT('date')),
line1.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base1.markText(label, white).encode(vl.text().fieldQ('shooting_count')),
base1.markText(label).encode(vl.text().fieldQ('shooting_count'))
);
const plot2 = vl.data('https://raw.githubusercontent.com/cse412-21sp/fatal-police-shooting/main/data/search_history.csv')
.layer(
line2,
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldT('date')),
line2.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base2.markText(label, white).encode(vl.text().fieldQ('search_count')),
base2.markText(label).encode(vl.text().fieldQ('search_count'))
);
return vl.vconcat(plot1, plot2)
.padding({"left": 50, "top": 50, "right": 50, "bottom": 50})
.render();
}