cookEvictionsChart = () => {
vl.markLine({ strokeWidth: 5 })
.config({
title: { fontSize: 16 },
legend: { titleFontSize: 14, labelFontSize: 12, symbolStrokeWidth: 5 },
axis: { labelFontSize: 12 },
style: { cell: { stroke: "transparent" } }
})
.title({ text: "Cook County Eviction Filings", dy: -16 })
.data(cookEvictionsCompare)
.transform(
vl.fold("cases19", "cases20").as("yearVal", "cases"),
vl.calculate("datum.yearVal === 'cases19' ? '2019' : '2020'").as("year")
)
.encode(
vl
.y()
.fieldQ("cases")
.axis({
domain: false,
ticks: false,
labelPadding: 10,
tickCount: { interval: 5 }
})
.title(null),
vl
.x()
.fieldT("month")
.axis({
format: "%b",
ticks: false,
tickCount: compareMonths.length + 1,
labelPadding: 10,
domain: false
})
.title(null),
vl
.color()
.field("year")
.title("Year")
.scale({ range: ["#9b9c9f", "#ed1651"] }),
vl.tooltip([
vl
.tooltip()
.fieldT("month")
.format("%B")
.title("Month"),
vl
.tooltip()
.fieldQ("cases")
.title("Cases")
])
)
.autosize({ type: "fit-x", contains: "padding" })
.render({ renderer: "svg" });
const hover = vl
.selectSingle("hover")
.fields(["month", "cases", "cases19", "cases20"])
.nearest(true)
.on("mouseover")
.empty("none")
.clear("mouseout");
const month = vl
.x()
.fieldT("month")
.axis({
format: "%b",
ticks: false,
tickCount: compareMonths.length,
labelPadding: 10,
domain: false
});
const cases = vl
.y()
.fieldQ("cases")
.axis({
domain: false,
ticks: false,
labelPadding: 10,
tickCount: { interval: 5 }
});
const transforms = [
vl.fold("cases19", "cases20").as("yearVal", "cases"),
vl.calculate("datum.yearVal === 'cases19' ? '2019' : '2020'").as("year")
];
const year = vl
.color()
.field("year")
.title("Year")
.scale({ range: ["#9b9c9f", "#ed1651"] });
const lines = vl
.markLine({ strokeWidth: 5 })
.width(width)
.height(400)
.title("Cook County Eviction Filings")
.width(width)
.transform(transforms)
.encode(cases.title(null), month.title(null), year);
const rule = vl
.markRule()
.width(width)
.height(400)
.encode(
month,
vl
.opacity()
.if(hover, vl.value(0.3))
.value(0),
vl.tooltip([
vl
.tooltip()
.fieldQ("cases19")
.format(",")
.title("2019 cases"),
vl
.tooltip()
.fieldQ("cases20")
.format(",")
.title("2020 cases")
])
)
.select(hover)
.transform(transforms);
return vl
.layer([lines, rule])
.config({
title: { fontSize: 16 },
legend: { titleFontSize: 14, labelFontSize: 12, symbolStrokeWidth: 5 },
axis: { labelFontSize: 12 },
style: { cell: { stroke: "transparent" } }
})
.data(cookEvictionsCompare)
.autosize({ type: "fit-x", contains: "padding" })
.render({ renderer: "svg" });
}