viewof crimeCharts = V({
width: 400,
height:300,
data: {values: vanCrime2},
transform: [
{filter: {field: "NEIGHBOURHOOD", oneOf: mapSelection}}
],
config: {
background: "white"
},
hconcat: [{
transform: [
{filter: {selection: "timeBrush"}}
],
mark: "rect",
selection: {
offenseSelect: {fields: ["Offense"], on: "click", type: "multi"}
},
encoding: {
y: {field: "Offense", type: "nominal"},
x: {field: "*", type: "quantitative", aggregate: "count"},
color: {
condition: {
field: "Offense Category",
type: "nominal",
selection: "offenseSelect",
scale: {
domain: Array.from(new Set(vanCrime2.map(d => d['Offense Category']))),
range: ["#4e79a7","#f28e2c","#e15759","#76b7b2"]}},
value: "lightgrey"
}
}
}, {
transform: [
{filter: {selection: "offenseSelect"}}
],
width: 400,
mark: "line",
selection: {
timeBrush: {type: "interval", encodings: ["x"]}
},
encoding: {
x: {field: "Date", type: "temporal"},
y: {field: "*", type: "quantitative", aggregate: "count"},
color: {field: "Offense Category", type: "nominal", scale: {domain: Array.from(new Set(vanCrime2.map(d => d['Offense Category']))), range: ["#4e79a7","#f28e2c","#e15759","#76b7b2"]}}
}
}]
})