Skip to content

Commit

Permalink
Merge pull request #30 from pehovorka/feat/ui-fixes
Browse files Browse the repository at this point in the history
Feat/UI fixes
  • Loading branch information
pehovorka authored Nov 9, 2022
2 parents f8d42ef + 410862f commit c8d15cc
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 37 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

<a name="3.9.3"></a>
## 3.9.3 (2022-11-09)

### Added

- ✨ Group minor vaccine types [889aba2]

### Changed

- 📱 Move legend under vaccine types chart on mobile [073ad7a]


<a name="3.9.2"></a>
## 3.9.2 (2022-08-01)

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "covidvobcich-web",
"version": "3.9.2",
"version": "3.9.3",
"private": true,
"homepage": "https://covidvobcich.cz",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<ResponsiveContainer width="100%" height={260}>
<ResponsiveContainer width="100%" height={320}>
<PieChart>
<Pie data={data} dataKey={"value"}>
{data.map((entry, index) => (
Expand All @@ -24,18 +27,28 @@ export default function VaccineTypesChart({ data }) {
</Pie>
{/* TODO: keep an eye on https://github.com/recharts/recharts/issues/2704
and then update ReCharts after the issue is fixed. */}
<Legend
verticalAlign="middle"
align="right"
layout="vertical"
wrapperStyle={{ width: "40%" }}
/>
{isDesktop ? (
<Legend
verticalAlign="middle"
align="right"
layout="vertical"
wrapperStyle={{ width: "40%" }}
/>
) : (
<Legend align="left" />
)}

<Tooltip content={<VaccineTypesChartTooltip data={data} />} />
</PieChart>
</ResponsiveContainer>
);
}

VaccineTypesChart.propTypes = {
data: PropTypes.array,
data: PropTypes.arrayOf(
PropTypes.shape({
value: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
})
).isRequired,
};
58 changes: 33 additions & 25 deletions src/components/card/OrpVaccinations/orpVaccinationsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit c8d15cc

Please sign in to comment.