short = {
const hover = vl.selectPoint('hover')
.encodings('x')
.on('mouseover')
.toggle(false)
.nearest(true);
const order = [
'< 1',
'1-3',
'3-5',
'5-10'
];
const isHovered = hover.empty(false);
const line = vl.markLine().encode(
vl.x().fieldT('Date'),
vl.y().fieldQ('Number of Trips'),
vl.color().fieldN('Miles').sort(order)
);
const base = line.transform(vl.filter(isHovered));
const label = {align: 'left', dx: 5, dy: -5};
const white = {stroke: 'white', strokeWidth: 2};
const black = {stroke: 'black', strokeWidth: 0.5};
return vl.data(data)
.layer(
line,
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldT('Date')),
line.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base.markText(label, white).encode(vl.text().fieldQ('Number of Trips')),
base.markText(label, black).encode(vl.text().fieldQ('Number of Trips'))
)
.transform(vl.filter('datum["Miles"] == "< 1" || datum["Miles"] == "1-3" || datum["Miles"] == "3-5" || datum["Miles"] == "5-10"'))
.title('How often does people travel in short distance during COVID')
.width(700)
.height(400)
.render();
}