vis12 = Plot.plot({
style: { fontSize: 14, background: "#f7f7f7" },
width: width > 650 ? 650 : 350,
color: { range: ["#b35806", "#998ec3", "#542788"] },
marginLeft: 130,
marginBottom: 45,
x: {
type: "linear",
tickFormat: (d) => d + "",
label: "Кількість ДТП з постраждалими і загиблими",
labelArrow: null
},
y: {
type: "band",
labelArrow: null,
grid: true,
label: null
},
marks: [
Plot.ruleY(
data,
Plot.groupY(
{ x1: "min", x2: "max" },
{ y: "region", x: "count", strokeWidth: 1, stroke: "#8073ac" }
)
),
Plot.text([{ region: "Дніпропетровська", text: "2021", count: 1970 }], {
frameAnchor: "middle",
y: "region",
x: "count",
text: "text",
dy: 0,
dx: width > 650 ? 0 : -10,
fill: "#998ec3",
fontSize: 11,
fontWeight: 600
}),
Plot.text([{ region: "Дніпропетровська", text: "2019", count: 2150 }], {
frameAnchor: "middle",
y: "region",
x: "count",
text: "text",
dy: -10,
dx: width > 650 ? 0 : -10,
fill: "#b35806",
fontSize: 11,
fontWeight: 600
}),
Plot.text([{ region: "Дніпропетровська", text: "2024", count: 2380 }], {
frameAnchor: "middle",
y: "region",
x: "count",
text: "text",
dy: -10,
fill: "#542788",
fontSize: 11,
fontWeight: 600
}),
Plot.dot(data, {
y: "region",
x: "count",
strokeWidth: 2,
tip: true,
title: (d) => `${d.count} ДТП з наслідками в ${d.year} році`,
fill: "year",
r: 4,
opacity: 0.9,
sort: { y: "-x" }
})
],
caption: html`<small style="color:grey; text-align: left;line-height: 1;">Дані: Статистичні дані НПУ <a target="_blank" href='https://patrolpolice.gov.ua/statystyka/'>https://patrolpolice.gov.ua/statystyka/</a></small>.`
})