{
const hover = vl.selectPoint('hover')
.encodings('x')
.on('mouseover')
.toggle(false)
.nearest(true);
const w = width/2-70;
const h = 200;
const isHovered = hover.empty(false);
const label = {align: 'left', dx: 5, dy: -5};
const line_co2 = vl.markLine({strokeWidth: 3, interpolate: 'monotone'})
.title('CO2')
.encode(
vl.x().fieldQ('year').axis({gridOpacity: 0.4, tickBand: "center"})
.scale({type:'quantitative', domain: [year_min, 2022]}).title(""),
vl.y().sum('co2').axis({gridOpacity: 0.4}).scale({type:'quantitative'}).title(""),
vl.color().fieldN('continent').title("Continents").legend(false)
).width(w).height(h);
const base1 = line_co2.transform(vl.filter(isHovered));
const ln1 = vl.layer(
line_co2,
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldQ('year')),
line_co2.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base1.markText(label).encode(vl.text().fieldQ('co2').aggregate("sum").format('0.0f'))
);
//------------------------//
const line_methane = vl.markLine({strokeWidth: 3, interpolate: 'monotone'})
.title('Methane')
.encode(
vl.x().fieldQ('year').axis({gridOpacity: 0.4, tickBand: "center"})
.scale({type:'quantitative', domain: [year_min, 2022]}).title("Year"),
vl.y().sum('methane').axis({gridOpacity: 0.4}).scale({type:'quantitative'}).title("Million Tonnes"),
vl.color().fieldN('continent').title("Continents").legend(false)
).width(w).height(h);
const base2 = line_methane.transform(vl.filter(isHovered));
const ln2 = vl.layer(
line_methane,
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldQ('year')),
line_methane.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base2.markText(label).encode(vl.text().fieldQ('methane').aggregate("sum").format('0.0f'))
);
//------------------------//
const line_nit_ox = vl.markLine({strokeWidth: 3, interpolate: 'monotone'})
.title('Nitrous Oxide')
.encode(
vl.x().fieldQ('year').axis({gridOpacity: 0.4, tickBand: "center"})
.scale({type:'quantitative', domain: [year_min, 2022]}).title("Year"),
vl.y().sum('nitrous_oxide').axis({gridOpacity: 0.4}).scale({type:'quantitative'}).title(""),
vl.color().fieldN('continent').title("Continents").legend(false)
).width(w).height(h);
const base3 = line_nit_ox.transform(vl.filter(isHovered));
const ln3 = vl.layer(
line_nit_ox,
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldQ('year')),
line_nit_ox.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base3.markText(label).encode(vl.text().fieldQ('nitrous_oxide').aggregate("sum").format('0.0f'))
);
const line_ghg = vl.markLine({strokeWidth: 3, interpolate: 'monotone'})
.title('Greenhouse Gasses')
.encode(
vl.x().fieldQ('year').axis({gridOpacity: 0.4, tickBand: "center"})
.scale({type:'quantitative', domain: [year_min, 2022]}).title(""),
vl.y().sum('total_ghg').axis({gridOpacity: 0.4}).scale({type:'quantitative'}).title("Million Tonnes"),
vl.color().fieldN('continent').title("Continents").legend({orient: 'top', titleOrient: 'left'})
).width(w).height(h);
const base4 = line_ghg.transform(vl.filter(isHovered));
const ln4 = vl.layer(
line_ghg,
vl.markRule({color: '#aaa'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldQ('year')),
line_ghg.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base4.markText(label).encode(vl.text().fieldQ('total_ghg').aggregate("sum").format('0.0f'))
);
const h1 = vl.hconcat(ln4,ln1)
.resolve({
axis: { x: 'independent' },
scale: { y: state_scale_type }
});
const h2 = vl.hconcat(ln2,ln3)
.resolve({
axis: { x: 'independent' },
scale: { y: state_scale_type }
});
const v1 = vl.vconcat(h1, h2);
return vl.data(emissions_data.filter(d=> d.continent !== undefined)
.filter(d=> d.continent !== "" )
.filter(d=> d.paris_agreement_signed !== par_agrmnt))
.vconcat(v1)
.config({
style: { cell: { stroke: 'transparent' } },
header: { labelFontSize: 14, labelPadding: 0 },
padding: { top: 5, right: 0, bottom: 5, left: 0 },
})
.title({
text: "Chart 1: Gasses Emissions by Year",
aling: 'center'
})
.render();
}