@@ -77,14 +89,24 @@ const MapChart = ({
{practices.includes("Total") ? (
-
-
- Total Predicted Benefits:
- |
-
- ${ShortFormat(practicePayment, undefined, 2)}
- |
-
+
+
+
+ Total Predicted Benefits:
+ |
+
+ ${ShortFormat(practicePayment, undefined, 2)}
+ |
+
+
+
+ PCT. Nationwide:
+ |
+
+ {totalPaymentPercentageNationwide}%
+ |
+
+
) : (
{practices.length > 1 &&
@@ -164,6 +186,16 @@ const MapChart = ({
)}
+
+
+ {practices.length === 1
+ ? "PCT. Nationwide:"
+ : "PCT. Nationwide (All Practices):"}
+ |
+
+ {totalPaymentPercentageNationwide}%
+ |
+
)}
@@ -250,7 +282,8 @@ const IRAPredictedMap = ({
mapColor,
predictedPerformance,
stateCodes,
- allStates
+ allStates,
+ summary
}: {
subtitle: string;
practices: any;
@@ -260,6 +293,7 @@ const IRAPredictedMap = ({
predictedPerformance: any;
stateCodes: any;
allStates: any;
+ summary: any;
}): JSX.Element => {
const [content, setContent] = useState("");
const quantizeArray: number[] = [];
@@ -339,6 +373,7 @@ const IRAPredictedMap = ({
stateCodes={stateCodes}
allStates={allStates}
colorScale={colorScale}
+ summary={summary}
/>
diff --git a/src/components/ira/IRAPredictedPercentageTable.tsx b/src/components/ira/IRAPredictedPercentageTable.tsx
index d0a38a9..7f7e61a 100644
--- a/src/components/ira/IRAPredictedPercentageTable.tsx
+++ b/src/components/ira/IRAPredictedPercentageTable.tsx
@@ -35,7 +35,7 @@ function IRAPredictedPercentageTable({
hashmap[state][attribute] = attributeData;
// Calculate percentage nationwide
if (attribute === "predictedTotalPaymentInDollars") {
- hashmap[state][`${attribute}PercentageNationwide`] = `${(
+ hashmap[state][`${attribute}PredictedPercentageNationwide`] = `${(
(attributeData / summary[year].predictedTotalPaymentInDollars) *
100
).toFixed(2)}%`;
@@ -60,7 +60,7 @@ function IRAPredictedPercentageTable({
hashmap[state][new_key] = 0;
practices_total[state][attribute] += 0;
// Set percentage to 0 for missing practices
- hashmap[state][`${new_key}PercentageNationwide`] = "0.00%";
+ hashmap[state][`${new_key}PredictedPercentageNationwide`] = "0.00%";
});
} else {
const attributeData = practiceData[0];
@@ -75,7 +75,7 @@ function IRAPredictedPercentageTable({
? nationalPracticeData.predictedTotalPaymentInDollars
: nationalPracticeData.totalPracticeInstanceCount;
- hashmap[state][`${new_key}PercentageNationwide`] = `${(
+ hashmap[state][`${new_key}PredictedPercentageNationwide`] = `${(
(attributeData[attribute] / nationalTotal) *
100
).toFixed(2)}%`;
@@ -85,9 +85,7 @@ function IRAPredictedPercentageTable({
});
let totalStatePayments = 0;
- const totalStateInstances = 0;
let totalNationalPayments = 0;
- const totalNationalInstances = 0;
practices.forEach((practice) => {
const statePracticeData = stateData.practices.find((p) => p.practiceName === practice);
@@ -108,13 +106,13 @@ function IRAPredictedPercentageTable({
if (!practices_total[state] || practices_total[state][attribute] === undefined) {
if (!hashmap[state]) hashmap[state] = {};
hashmap[state][`All Practices: ${attribute}`] = 0;
- hashmap[state][`All Practices: ${attribute}PercentageNationwide`] = "0.00%";
+ hashmap[state][`All Practices: ${attribute}PredictedPercentageNationwide`] = "0.00%";
} else {
hashmap[state][`All Practices: ${attribute}`] = practices_total[state][attribute];
// Calculate percentage for all practices combined
if (attribute === "predictedTotalPaymentInDollars") {
- hashmap[state][`All Practices: ${attribute}PercentageNationwide`] = `${(
+ hashmap[state][`All Practices: ${attribute}PredictedPercentageNationwide`] = `${(
(totalStatePayments / totalNationalPayments) *
100
).toFixed(2)}%`;
@@ -128,14 +126,14 @@ function IRAPredictedPercentageTable({
Object.entries(hashmap[s]).forEach(([attr, value]) => {
if (value) {
if (attr.includes("Dollar")) {
- if (attr.includes("PercentageNationwide")) {
+ if (attr.includes("PredictedPercentageNationwide")) {
newRecord[attr] = value; // Keep as percentage
} else {
newRecord[attr] = `$${parseFloat(value).toLocaleString(undefined, {
minimumFractionDigits: 2
})}`;
}
- } else if (attr.includes("PercentageNationwide")) {
+ } else if (attr.includes("PredictedPercentageNationwide")) {
newRecord[attr] = value; // Keep as percentage
} else {
newRecord[attr] = parseFloat(value).toLocaleString(undefined, { minimumFractionDigits: 2 });
@@ -145,6 +143,7 @@ function IRAPredictedPercentageTable({
} else {
newRecord[attr] = "0";
}
+ newRecord[attr] = newRecord[attr].includes("NaN") ? "0.00%" : newRecord[attr];
});
resultData.push(newRecord);
});
@@ -152,7 +151,6 @@ function IRAPredictedPercentageTable({
const columnPrep = [];
columnPrep.push({ Header: "STATE", accessor: "state", sortType: compareWithAlphabetic });
// filter out all data attributes with the word "percentage" in them
-
resultData = resultData.map(
(item) =>
Object.keys(item)
diff --git a/src/components/ira/TabPanel.tsx b/src/components/ira/TabPanel.tsx
index 34b5fbf..319babb 100644
--- a/src/components/ira/TabPanel.tsx
+++ b/src/components/ira/TabPanel.tsx
@@ -20,7 +20,7 @@ import { styled } from "@mui/system";
import { CurrencyDollar, Percent } from "react-bootstrap-icons";
import useWindowSize from "../shared/WindowSizeHook";
-import IRAMap from "./IRAMap";
+import IRADollarMap from "./IRADollarMap";
import IRADollarTable from "./IRADollarTable";
import IRAPercentageTable from "./IRAPercentageTable";
import IRAPredictedMap from "./IRAPredictedMap";
@@ -55,13 +55,14 @@ function TabPanel({
const years = stateDistributionData ? Object.keys(stateDistributionData).map(Number) : [];
const [updatedData, setUpdatedData] = useState(stateDistributionData);
const [updatedPredictedData, setUpdatedPredictedData] = useState(predictedData);
- const minYear = Math.min(...years);
+ const minYear = Math.min(...years).toString();
const maxYear = Math.max(...years);
const [isPlaying, setIsPlaying] = useState(false);
const [intervalId, setIntervalId] = useState | null>(null);
- const [selectedYear, setSelectedYear] = useState(minYear);
+ const [selectedYear, setSelectedYear] = useState(minYear.toString());
const [selectedPredict, setSelectedPredict] = useState("Min");
- const [selectedPractices, setSelectedPractices] = useState([]);
+ const [selectedPractices, setSelectedPractices] = useState([]);
+ const [practices, setPractices] = useState([]);
const mapColor = ["#F0F9E8", "#BAE4BC", "#7BCCC4", "#43A2CA", "#0868AC"]; // title II color
const the = useTheme();
const isSmallScreen = useMediaQuery(the.breakpoints.down("sm"));
@@ -82,8 +83,16 @@ function TabPanel({
setTab(newTab);
}
};
- const handleSwitchChange = (event) => {
- setIsPredictionOn(event.target.checked);
+ const handleSwitchChange = (event: React.ChangeEvent) => {
+ const isOn = event.target.checked;
+ setIsPredictionOn(isOn);
+ const year = isOn ? predictedYear : minYear;
+ setSelectedYear(year);
+ const currentPractices = practiceNames[year].slice().sort((a, b) => a.localeCompare(b));
+ const newPractices = ["Total", ...currentPractices];
+ setPractices(newPractices);
+ const overlapped_practices: string[] = newPractices.filter((element) => selectedPractices.includes(element));
+ setSelectedPractices(overlapped_practices.length === 0 ? ["Total"] : overlapped_practices);
};
const handleYearChange = (event) => {
@@ -93,8 +102,6 @@ function TabPanel({
value: year,
label: year.toString()
}));
- const currentPractices = practiceNames[selectedYear].sort((a, b) => a.localeCompare(b)); // sort the practice list from a to z
- const practices: any[] = ["Total", ...currentPractices];
const handlePracticeChange = (event) => {
const {
target: { value }
@@ -157,14 +164,20 @@ function TabPanel({
if (years.length) {
setSelectedYear(minYear);
}
- if (selectedPractices.length === 0) {
- setSelectedPractices(["Total"]);
+ if (Object.keys(practiceNames).length > 0) {
+ const currentPractices = isPredictionOn
+ ? practiceNames[predictedYear].sort((a, b) => a.localeCompare(b))
+ : practiceNames[minYear].sort((a, b) => a.localeCompare(b));
+ setPractices(["Total", ...currentPractices]);
+ if (selectedPractices.length === 0) {
+ setSelectedPractices(["Total"]);
+ }
}
- }, [minYear, selectedPractices]);
+ }, [minYear, selectedYear, selectedPractices, practiceNames]);
React.useEffect(() => {
updateData();
+ updatePredictedData();
}, [selectedPractices, selectedYear, isPredictionOn]);
-
return (
{v === index && (
@@ -199,16 +212,19 @@ function TabPanel({
position: "relative"
}}
>
-
+ {Object.keys(updatedPredictedData).length > 0 && (
+
+ )}
)}
@@ -249,7 +265,7 @@ function TabPanel({
position: "relative"
}}
>
-
)}
@@ -435,18 +452,20 @@ function TabPanel({
className="offset-sm-1"
sx={{ display: tab !== 0 ? "none" : "div" }}
>
-
+ {Object.keys(updatedPredictedData).length > 0 && (
+
+ )}
-
+ {Object.keys(updatedPredictedData).length > 0 && (
+
+ )}
)}