{
const highlightSelection = vl.selectSingle()
.on('mouseover')
.clear('mouseout')
.encodings(['color'])
.init(null);
const expenditureByState = new Map(SchoolExpenditure.map(d => [d.State, +d["Per pupil current spending (whole dollars)"]]));
const enrichedGeoJSON = usStatesGeoJSON.features.map(feature => {
const expenditure = expenditureByState.get(feature.properties.NAME);
return {
...feature,
properties: {
...feature.properties,
expenditure: expenditure
}
};
});
return vl.markGeoshape()
.data({ values: enrichedGeoJSON })
.params(highlightSelection)
.encode(
vl.color().fieldQ('properties.expenditure').title('Per Pupil Spending ($)'),
vl.stroke().value('gray'),
vl.strokeWidth().if(highlightSelection, vl.value(3)).value(0),
vl.tooltip([
{ field: 'properties.NAME', type: 'nominal', title: 'State' },
{ field: 'properties.expenditure', type: 'quantitative', title: 'Per Pupil Spending ($)' }
])
)
.project(vl.projection('albersUsa'))
.width(800)
.height(500)
.render();
}