vis2 = {
const data2 = data.filter(
(d) =>
[
"Китай",
"ЄС-27",
"США",
"Туреччина",
"Китай",
"Казахстан",
"Індія",
"Південна Корея",
"Велика Британія"
].includes(d["country"]) && d.month != "12"
);
return width > 650
? Plot.plot({
subtitle: "Імпорт критичних товарів з основних регіонів і країн",
style: { fontSize: 14 },
width: 1150,
x: { ticks: 4 },
y: {
grid: true,
label: "млрд на рік",
tickFormat: (d) => "$" + d + "",
labelOffset: 45,
labelArrow: null,
labelAnchor: "center"
},
marginBottom: 60,
marks: [
Plot.axisFx({ label: null, fontSize: 15, fontWeight: 600 }),
Plot.axisX({ fontSize: 13, ticks: 3 }),
Plot.text(["↑\n24 лютого\n2022 року"], {
frameAnchor: "bottom",
lineWidth: 14,
x: new Date("2022-02-24"),
dy: 50,
fill: "#aaa",
stroke: "white",
strokeWidth: 4,
fontSize: 11
}),
Plot.text(
[
"В 2024 році Китай поставив машин і електроніки до РФ на рекордну суму"
],
{
textAnchor: "start",
fx: ["США"],
x: new Date("2020-01-01"),
y: 9,
lineWidth: 22,
fontSize: 14
}
),
Plot.arrow([0], {
x1: new Date("2023-06-01"),
x2: new Date("2020-01-01"),
y1: 10,
y2: 13,
bend: -30,
strokeWidth: 1,
dx: -20,
fx: ["США"]
}),
Plot.areaY(
data2,
Plot.binX(
{ y: "sum" },
{
interval: "12 months",
x: "date",
y: (d) => +d.bln,
z: "SITC category description",
fx: "country",
tip: true,
title: (d) => `"Категорія": ${d["SITC category description"]}`,
fill: "darkblue",
strokeWidth: 0.5,
stroke: "#fff",
sort: { x: "-y", fx: "-y" }
}
)
),
Plot.text(["Транспорт"], {
textAnchor: "start",
fx: ["Китай"],
x: new Date("2021-01-01"),
y: 13,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Інстр."], {
textAnchor: "start",
fx: ["Китай"],
x: new Date("2023-07-01"),
y: 12.3,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Електро\nніка"], {
textAnchor: "start",
fx: ["Китай"],
x: new Date("2022-06-01"),
y: 7,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Офісна\nтехніка"], {
textAnchor: "start",
fx: ["Китай"],
x: new Date("2022-11-01"),
y: 4,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Телеком\nобл."], {
textAnchor: "start",
fx: ["Китай"],
x: new Date("2022-06-01"),
y: 1,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
})
],
caption: html`<small style="color:grey">Дані за 11 місяців 2024 року (останні доступні). Джерела даних: агенство Bruegel.
</small>`
})
: Plot.plot({
subtitle: "Імпорт критичних товарів з основних регіонів і країн",
style: { fontSize: 14 },
width: 350,
height: 1450,
x: { ticks: 4 },
y: {
grid: true,
label: "млрд\nна рік",
tickFormat: (d) => "$" + d + "",
labelOffset: 40,
labelArrow: null
// domain: [0, 100]
},
fy: { padding: 0.2 },
marginBottom: 60,
// marginLeft: 40,
marks: [
Plot.axisFy({
lineWidth: 16,
label: null,
frameAnchor: "bottom",
textAnchor: "middle",
dy: 17,
fontWeight: 600,
fontSize: 15
}),
Plot.axisX({ anchor: "top", insetTop: -10 }),
Plot.axisX({ anchor: "bottom", insetBottom: -30 }),
Plot.areaY(
data2,
Plot.binX(
{ y: "sum" },
{
interval: "12 months",
x: "date",
y: (d) => +d.bln,
z: "SITC category description",
fy: "country",
// tip: true,
// title: (d) => `"Категорія": ${d["SITC category description"]}`,
fill: "darkblue",
strokeWidth: 0.5,
stroke: "#fff",
sort: { x: "-y", fy: "-y" }
}
)
),
Plot.text(["Транспорт"], {
textAnchor: "start",
fy: ["Китай"],
x: new Date("2023-01-01"),
y: 14,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Інстр."], {
textAnchor: "start",
fy: ["Китай"],
x: new Date("2023-07-01"),
y: 12.5,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Електро ніка"], {
textAnchor: "start",
fy: ["Китай"],
x: new Date("2023-01-01"),
y: 8,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Офісна техніка"], {
textAnchor: "start",
fy: ["Китай"],
x: new Date("2023-01-01"),
y: 4.4,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
}),
Plot.text(["Телеком обл."], {
textAnchor: "start",
fy: ["Китай"],
x: new Date("2023-01-01"),
y: 1,
lineWidth: 12,
fontSize: 11,
fill: "#aaa"
})
],
caption: html`<small style="color:grey">Дані за 11 місяців 2024 року (останні доступні). Джерела даних: агенство Bruegel.
</small>`
});
}