vis1 = {
d3.timeFormatDefaultLocale({
dateTime: "%A, %e %B %Y р. %X",
date: "%d.%m.%Y",
time: "%H:%M:%S",
periods: ["дп", "пп"],
days: [
"неділя",
"понеділок",
"вівторок",
"середа",
"четвер",
"п'ятниця",
"субота"
],
shortDays: ["нд", "пн", "вт", "ср", "чт", "пт", "сб"],
months: [
"січня",
"лютого",
"березня",
"квітня",
"травня",
"червня",
"липня",
"серпня",
"вересня",
"жовтня",
"листопада",
"грудня"
],
shortMonths: [
"січ",
"лют",
"бер",
"квіт",
"трав",
"черв",
"лип",
"серп",
"вер",
"жов",
"лист",
"груд"
]
});
return Plot.plot({
subtitle: "Як змінилися ціни на 100 популярних ліків",
style: { fontSize: 14, fontWeight: 400 },
marginTop: 40,
marginBottom: 40,
marginRight: 100,
marginLeft: 45,
y: {
percent: true,
tickFormat: (d) => d - 100 + "%",
label: null,
labelArrow: false,
ticks: 8,
grid: true,
nice: true
},
x: { nice: true, ticks: width > 650 ? 8 : 4 },
width: width > 650 ? 750 : 350,
// marginLeft: 80,
marks: [
Plot.text(
[
`В січні середня ціна на сотню популярних ліків підскочила одразу на 15%.`
],
{
x: new Date("2024-10-09"),
y: 1.3,
textAnchor: "end",
bend: true,
dx: width > 650 ? 0 : 0,
lineWidth: 10,
fill: "#333"
}
),
Plot.text(
[
`Президент зібрав "лікарське" РНБО. Після цього ринок пообіцяв знизити ціни на 30%.`
],
{
x: new Date("2025-03-29"),
y: 1.14,
textAnchor: "end",
bend: true,
dx: width > 650 ? 70 : 100,
lineWidth: 10,
fill: "#333"
}
),
Plot.lineY(
data2,
Plot.normalizeY("first", {
x: "date",
y: "value",
z: "name",
stroke: "#ddd",
tip: true,
title: (d) => `${d.drug}`,
opacity: 0.7
})
),
Plot.dot(
data2,
Plot.normalizeY(
"first",
Plot.pointerX({
x: "date",
y: "value",
z: "name",
stroke: "#333",
opacity: 0.6
})
)
),
Plot.ruleY([1], { strokeDasharray: "2 2" }),
Plot.lineY(
data2,
Plot.normalizeY(
"first",
Plot.binX(
{ y: "mean" },
{
x: "date",
y: "value",
// z: "name",
interval: "months",
stroke: "red",
strokeWidth: 2.5,
dx: width > 650 ? 25 : 10
}
)
)
),
Plot.dot(
data2,
Plot.normalizeY(
"first",
Plot.binX(
{ y: "mean" },
{
x: "date",
y: "value",
// z: "name",
interval: "months",
stroke: "red",
strokeWidth: 2.5,
dx: width > 650 ? 25 : 10,
r: 2
}
)
)
),
Plot.text([`Середня`], {
x: new Date("2024-12-01"),
y: width > 650 ? 1.07 : 1.05,
dx: width > 650 ? 0 : -10,
textAnchor: "start",
bend: true,
lineWidth: 6,
fill: "red",
lineWidth: 9,
rotate: width > 650 ? -55 : -73
}),
Plot.text(
[
`В березні ціни впали на 15% порівняно з лютим, і на 25% – порівняно з січнем`
],
{
x: new Date("2025-03-10"),
y: 0.87,
dx: width > 650 ? 0 : 5,
textAnchor: "start",
bend: true,
lineWidth: 6,
fill: "#333",
lineWidth: 9
}
),
Plot.arrow([0], {
x1: new Date("2024-10-15"),
x2: new Date("2025-01-01"),
y1: 1.3,
y2: 1.17,
bend: 30,
dx: width > 650 ? 0 : 0,
strokeWidth: 1
}),
Plot.arrow([0], {
x1: new Date("2025-02-21"),
x2: new Date("2025-02-05"),
y1: 1.1,
y2: 1.07,
bend: width > 650 ? -20 : 20,
dx: width > 650 ? 0 : 5,
strokeWidth: 1
})
],
caption: html`<small style="color:grey">Дані: Сайт https://tabletki.ua</small>`
});
}