{
const selectedInterval = vl.selectInterval('selected_interval');
const scatterPlot = vl.markCircle()
.data(seattleWeatherTyped)
.params(selectedInterval)
.title({text: "Seattle Daily Max Temperatures (2012-2015)",
subtitle: "Drag to select points | Click to deselect"})
.encode(
vl.x().fieldT("date"),
vl.y().fieldQ('temp_max').title('Max Temp'),
vl.color().if(selectedInterval, vl.fieldQ('temp_max')).value("grey"),
vl.opacity().if(selectedInterval, vl.value(0.7)).value(0.1)
);
const overallAvgLine = vl.markRule({color: 'firebrick'})
.data(seattleWeatherTyped)
.encode(
vl.y().fieldQ('temp_max').aggregate("mean")
);
const overallAvgText = vl.markText({color: 'firebrick', align: 'left', dx:2})
.data(seattleWeatherTyped)
.encode(
vl.x().fieldT('date').aggregate('max'),
vl.y().fieldQ('temp_max').aggregate("mean"),
vl.text().mean('temp_max').format('0.1f')
);
const avgLineForSelection = vl.markRule()
.data(seattleWeatherTyped)
.transform(vl.filter(selectedInterval.empty(false)))
.encode(
vl.y().fieldQ('temp_max').aggregate("mean"),
vl.color().value("#ff9632")
);
const avgTextForSelection = vl.markText({align:'left', x:'width', dx:2})
.data(seattleWeatherTyped)
.transform(vl.filter(selectedInterval.empty(false)))
.encode(
vl.y().mean('temp_max'),
vl.color().value("#ff9632"),
vl.text().mean('temp_max').format('0.1f')
);
return vl.layer(scatterPlot, overallAvgLine, overallAvgText,
avgLineForSelection, avgTextForSelection)
.config({"legend" : {"offset" : 35}})
.render();
}