{ const selectedCountry = vl.selectSingle('select')
.fields(`properties.${year}`)
.on('click')
.clear('dblclick')
const choropleth = vl
.markGeoshape({ stroke: 'white', tooltip: {content: 'data'} })
.data(choroplethData)
.params(selectedCountry)
.title({text: "Happiness by Country", subtitle: "Click to select a country | Use the slider to change year | Double click to deselect"})
.encode(
vl
.color().if(selectedCountry, vl.fieldQ(`properties.${year}`)).value("grey"),
vl.tooltip([
{
field: 'properties["Country"]',
type: 'nominal',
title: 'Country'
},
{
field: `properties.${year}`,
type: 'quantitative',
title: 'Happiness'
}
])
)
.project(
vl
.projection("naturalEarth1")
.translate([450, 300])
.rotate(0)
.scale(200)
)
.width(width - 10)
.height(500)
.config({
view: { stroke: null }
})
const countryBarPlot = vl.markBar({align: 'left', dx: 3})
.data(barChartData)
.transform(vl.filter(selectedCountry))
.encode(
vl.x().fieldQ('Year'),
vl.y().fieldQ('Happiness')
).width(width - 300);
return vl.vconcat(choropleth, countryBarPlot).render()
}