diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a81a2f..aa5a29a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog + +## 3.9.3 (2022-11-09) + +### Added + +- ✨ Group minor vaccine types [889aba2] + +### Changed + +- 📱 Move legend under vaccine types chart on mobile [073ad7a] + + ## 3.9.2 (2022-08-01) diff --git a/package-lock.json b/package-lock.json index 165bc21..f55f20a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "covidvobcich-web", - "version": "3.9.2", + "version": "3.9.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "covidvobcich-web", - "version": "3.9.2", + "version": "3.9.3", "dependencies": { "@apollo/client": "^3.3.13", "@emotion/react": "^11.7.1", diff --git a/package.json b/package.json index b83b5bd..a337e6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "covidvobcich-web", - "version": "3.9.2", + "version": "3.9.3", "private": true, "homepage": "https://covidvobcich.cz", "dependencies": { diff --git a/src/components/card/OrpVaccinations/VaccineTypesChart/VaccineTypesChart.js b/src/components/card/OrpVaccinations/VaccineTypesChart/VaccineTypesChart.js index 24c5540..e1ea785 100644 --- a/src/components/card/OrpVaccinations/VaccineTypesChart/VaccineTypesChart.js +++ b/src/components/card/OrpVaccinations/VaccineTypesChart/VaccineTypesChart.js @@ -1,4 +1,6 @@ import React from "react"; +import { useTheme } from "@mui/material/styles"; +import useMediaQuery from "@mui/material/useMediaQuery"; import PropTypes from "prop-types"; import { Cell, @@ -8,14 +10,15 @@ import { PieChart, Pie, } from "recharts"; -import { theme } from "../../../../theme"; import VaccineTypesChartTooltip from "./VaccineTypesChartTooltip"; export default function VaccineTypesChart({ data }) { + const theme = useTheme(); const colors = theme.palette.orpVaccinations; + const isDesktop = useMediaQuery(theme.breakpoints.up("md")); return ( - + {data.map((entry, index) => ( @@ -24,12 +27,17 @@ export default function VaccineTypesChart({ data }) { {/* TODO: keep an eye on https://github.com/recharts/recharts/issues/2704 and then update ReCharts after the issue is fixed. */} - + {isDesktop ? ( + + ) : ( + + )} + } /> @@ -37,5 +45,10 @@ export default function VaccineTypesChart({ data }) { } VaccineTypesChart.propTypes = { - data: PropTypes.array, + data: PropTypes.arrayOf( + PropTypes.shape({ + value: PropTypes.number.isRequired, + name: PropTypes.string.isRequired, + }) + ).isRequired, }; diff --git a/src/components/card/OrpVaccinations/orpVaccinationsUtils.js b/src/components/card/OrpVaccinations/orpVaccinationsUtils.js index df93205..9d511ce 100644 --- a/src/components/card/OrpVaccinations/orpVaccinationsUtils.js +++ b/src/components/card/OrpVaccinations/orpVaccinationsUtils.js @@ -37,37 +37,45 @@ export const convertToDoseOrderNewDosesData = (days, limit) => { }; export const convertToVaccineTypes = (data, vaccineNames) => { + const FEATURED_ITEMS_SIZE = 6; + if (!data) return null; const getVaccineName = (vaccineId) => vaccineNames.find((vaccine) => vaccine.vaccineId === vaccineId); - const vaccineManufacturers = [ - { vaccineName: "Comirnaty", vaccineManufacturer: "Pfizer–BioNTech" }, - { vaccineName: "SPIKEVAX", vaccineManufacturer: "Moderna" }, - { vaccineName: "VAXZEVRIA", vaccineManufacturer: "AstraZeneca" }, - { - vaccineName: "COVID-19 Vaccine Janssen", - vaccineManufacturer: "Johnson & Johnson", - }, - ]; - - const vaccineTypes = data + const vaccineManufacturers = { + Comirnaty: "Pfizer–BioNTech", + SPIKEVAX: "Moderna", + VAXZEVRIA: "AstraZeneca", + "COVID-19 Vaccine Janssen": "Johnson & Johnson", + }; + + const sortedData = data .filter((vaccine) => vaccine.td !== 0) - .map((vaccine) => { - const vaccineName = getVaccineName(vaccine.v).vaccineName || vaccine.v; - const vaccineManufacturer = vaccineManufacturers.find( - (vaccineManufacturer) => vaccineName === vaccineManufacturer.vaccineName - )?.vaccineManufacturer; - - const result = { - value: vaccine.td, - name: vaccineManufacturer - ? `${vaccineName} (${vaccineManufacturer})` - : vaccineName, - }; - - return result; + .sort((a, b) => b.td - a.td); + + const featuredItems = sortedData.slice(0, FEATURED_ITEMS_SIZE); + const itemsToGroup = sortedData.slice(FEATURED_ITEMS_SIZE, data.length); + const groupedTD = itemsToGroup.reduce((acc, obj) => acc + obj.td, 0); + + if (groupedTD > 0) { + featuredItems.push({ + v: "Ostatní", + td: groupedTD, }); + } + + const vaccineTypes = featuredItems.map((vaccine) => { + const vaccineName = getVaccineName(vaccine.v)?.vaccineName ?? vaccine.v; + const vaccineManufacturer = vaccineManufacturers[vaccineName] ?? null; + + return { + value: vaccine.td, + name: vaccineManufacturer + ? `${vaccineName} (${vaccineManufacturer})` + : vaccineName, + }; + }); return vaccineTypes; };