{ const selectedCountry = vl.selectSingle('select')
.fields(`properties.${year}`)
.bind(input)
.on('click')
.clear('dblclick')
const choropleth = vl
.markGeoshape({ stroke: 'grey', 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.color().fieldQ(`properties.${year}`).scale({scheme: 'spectral'})).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: "black" }
})
const countryBarPlot = vl.markBar({align: 'left', dx: 3})
.data(choroplethData)
.params(selectedCountry)
.encode(
vl.x().fieldO('Year').scale({domain: [2005, 2020]}),
vl.y().fieldQ(`properties.${year}`).title("Happiness Score").scale({domain: [0, 10]})
).width(width - 300);
return vl.vconcat(choropleth, countryBarPlot).render()
}