function drawPlot(index_druckzonenInGemeindeSelect) {
let data = plotDataByDruckzone[index_druckzonenInGemeindeSelect];
let druckzone = [
...new Set(
d3.map(
plotDataByDruckzone[index_druckzonenInGemeindeSelect],
(d) => d.druckzone
)
)
];
let source = [
...new Set(
d3.map(
plotDataByDruckzone[index_druckzonenInGemeindeSelect],
(d) => d.quelle
)
)
];
const initDate = new Date(
d3.min(plotDataByDruckzone[index_druckzonenInGemeindeSelect], (d) => d.date)
);
const hover = vl
.selectSingle("hover")
.on("mouseover")
.encodings("x")
.nearest(true)
.clear("moouseout")
.init({
x: {
year: +d3.timeFormat("%Y")(initDate),
month: +d3.timeFormat("%m")(initDate),
date: +d3.timeFormat("%d")(initDate)
}
});
// predicate to test if a point is hover-selected
// return false if the selection is empty
const isHovered = hover.empty(false);
// The line and point marks. Notice how we filter the points on hover
const lineAndPoint = vl
.data(data)
.layer(
vl
.markPoint({
size: 100,
filled: false,
legend: null,
color: { value: "#949494" }
})
.transform(vl.filter(hover)),
// .encode(
// vl
// .color()
// .field("quelle")
// .scale({
// domain: colorDomainPlot,
// range: colorRangePlot,
// nice: true
// })
// .legend("top")
// .title("Quelle")
// ),
vl.markCircle({ size: 75, stroke: "white", strokeWidth: 1.5 }).encode(
vl
.color()
.field("quelle")
.scale({
domain: colorDomainPlot,
range: colorRangePlot,
nice: true
})
.legend("top")
.title("Quelle"),
vl.tooltip([
{ field: "tipDatum", title: "Datum" },
{ field: "messwert_kategorie", title: "Messwert" },
{ field: "quelle", title: "Quelle" }
])
)
)
.encode(
vl.x().fieldT("date").scale({ domain: xDomain }),
vl
.y()
.fieldN("messwert_kategorie")
.scale({ domain: yDomain, reverse: true })
);
// The rule helps as a proxy for the hover. We draw rules all over the chart
// so we can easily find the nearest one. We then hide them using opacity 0
const rule = vl
.markRule({
stroke: "#666666",
strokeWidth: 1,
tooltip: true,
strokeDash: [8, 8]
})
.data(data)
.encode(
vl.x().fieldT("date").scale({ domain: xDomain }),
vl.opacity().value(0).if(hover, vl.value(1)).value(0),
vl.tooltip([
{ field: "tipDatum", title: "Datum" },
{ field: "messwert_kategorie", title: "Messwert" },
{ field: "quelle", title: "Quelle" }
])
)
.select(hover);
let plot = vl
.layer(lineAndPoint, rule)
.title({
// adding facette title
text: `Verteilzone: ${druckzone}`,
subtitle: `Quelle: ${source}`,
anchor: "start",
color: "black",
fontSize: 14
})
.width(widthNow * 0.825)
.height(height);
return plot;
}