plot = {
const hover = vl.selectPoint('hover')
.encodings('x')
.on('mouseover')
.toggle(false)
.nearest(true);
const hover2 = vl.selectPoint('hover2')
.encodings('x')
.on('mouseover')
.toggle(false)
.nearest(true);
const hover3 = vl.selectPoint('hover3')
.encodings('x')
.on('mouseover')
.toggle(false)
.nearest(true);
const isHovered = hover.empty(() => { console.log('!!!'); return false;} );
const line = vl.markLine().encode(
vl.x().fieldO('aspect_num'),
vl.y().fieldQ('SOP')
);
const line2 = vl.markLine().encode(
vl.x().fieldO('aspect_num'),
vl.y().fieldQ('GOE+'),
);
const line3 = vl.markLine().encode(
vl.x().fieldO('aspect_num'),
vl.y().fieldQ('GOE-')
);
// define our area chart of GOE
const area = vl.markArea({ color: "darkseagreen", opacity: 0.5 })
.encode(
vl.x().fieldO("aspect_num"),
vl.y2().fieldQ("GOE+"),
vl.y().fieldQ("GOE-")
)
// shared base for new layers, filtered to hover selection
const base = line.transform(vl.filter(isHovered));
// mark properties for text label layers
const label = {align: 'left', dx: 5, dy: -5};
const white = {stroke: 'white', strokeWidth: 2};
return vl.data(bv)
.layer(
line, line2, line3,
area,
// add a rule mark to serve as a guide line
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldO('aspect_num')),
// add circle marks for selected time points, hide unselected points
line.markCircle()
.params(hover) // use as anchor points for selection
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
line2.markCircle()
.params(hover2) // use as anchor points for selection
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
line3.markCircle()
.params(hover3) // use as anchor points for selection
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
// add white stroked text to provide a legible background for SOP
base.markText(label, white).encode(vl.text().fieldQ('SOP')),
// add text labels for SOP
base.markText(label).encode(vl.text().fieldQ('SOP')),
// add white stroked text to provide a legible background for GOE+
base.markText(label, white).encode(vl.text().fieldQ('GOE+'), vl.y().fieldQ("GOE+")),
// add text labels for GOE+
base.markText(label).encode(vl.text().fieldQ('GOE+'), vl.y().fieldQ("GOE+")),
// add white stroked text to provide a legible background for GOE-
base.markText(label, white).encode(vl.text().fieldQ('GOE-'), vl.y().fieldQ("GOE-")),
// add text labels for GOE-
base.markText(label).encode(vl.text().fieldQ('GOE-'), vl.y().fieldQ("GOE-"))
)
.width(700)
.height(400)
.render();
}