Skip to content

Commit

Permalink
Merge pull request #335 from policy-design-lab/release-1.3.0
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
pengyin-shan authored Nov 4, 2024
2 parents dc9152c + b69f044 commit 32203e4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.3.0] - 2024-11-04

### Changed
- Updated the front-end code to fit the new landing page data from database [#334](https://github.com/policy-design-lab/pdl-frontend/issues/334)

## [1.2.0] - 2024-10-24

### Added
Expand Down Expand Up @@ -299,6 +304,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Map data json [#12](https://github.com/policy-design-lab/pdl-frontend/issues/12)
- Final landing page changes for initial milestone [#15](https://github.com/policy-design-lab/pdl-frontend/issues/15)

[1.3.0]: https://github.com/policy-design-lab/pdl-frontend/compare/1.2.0...1.3.0
[1.2.0]: https://github.com/policy-design-lab/pdl-frontend/compare/1.1.0...1.2.0
[1.1.0]: https://github.com/policy-design-lab/pdl-frontend/compare/1.0.5...1.1.0
[1.0.5]: https://github.com/policy-design-lab/pdl-frontend/compare/1.0.4...1.0.5
Expand Down
2 changes: 1 addition & 1 deletion 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": "policy-design-lab",
"version": "1.2.0",
"version": "1.3.0",
"description": "the front end of policy design lab",
"repository": "https://github.com/policy-design-lab/pdl-frontend",
"main": "src/app.tsx",
Expand Down
58 changes: 26 additions & 32 deletions src/components/LandingPageTotalMap.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-nested-ternary */
import React, { useEffect, useMemo, useState } from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { geoCentroid } from "d3-geo";
import { ComposableMap, Geographies, Geography, Marker, Annotation } from "react-simple-maps";
import ReactTooltip from "react-tooltip";
Expand All @@ -8,9 +8,7 @@ import PropTypes from "prop-types";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { FormControl, Select, Chip, MenuItem, Button, FormLabel } from "@mui/material";
import { inherits } from "util";
import DrawLegend from "./shared/DrawLegend";
import legendConfig from "../utils/legendConfig.json";
import { CurrencyFormat } from "./shared/ConvertionFormats";
import { useStyles, tooltipBkgColor } from "./shared/MapTooltip";
import "../styles/map.css";
Expand Down Expand Up @@ -257,40 +255,32 @@ const LandingPageTotalMap = ({
const uniquePrograms = [...new Set(summary.map((item) => item.Title))];
return ["All Programs", ...uniquePrograms];
}, [summary]);
const calculateTotal = (state) => {
if (selectedPrograms.includes("All Programs")) {
if (allPrograms.find((s) => s.State === state)) {
return allPrograms.find((s) => s.State === state)["18-22 All Programs Total"];
const calculateTotal = useCallback(
(state) => {
if (selectedPrograms.includes("All Programs")) {
const stateProgram = allPrograms.find((s) => s.State === state);
return stateProgram ? stateProgram["18-22 All Programs Total"] : 0;
}
return 0;
}
const newTotal = selectedPrograms.reduce((total, program) => {
const programTotal = summary
.filter((item) => item.State === state && item.Title === program)
.reduce((sum, item) => sum + item.Amount, 0);
return total + programTotal;
}, 0);
return newTotal;
};
const calculateNationwideTotal = () => {
return selectedPrograms.reduce((total, program) => {
const programTotal = summary
.filter((item) => item.State === state && item.Title === program)
.reduce((sum, item) => sum + item.Amount, 0);
return total + programTotal;
}, 0);
},
[selectedPrograms, allPrograms, summary]
);
const calculateNationwideTotal = useCallback(() => {
if (selectedPrograms.includes("All Programs")) {
// Sum all state totals for "All Programs"
return allStates.reduce((total, state) => {
return total + (allPrograms.find((s) => s.State === state.id)?.["18-22 All Programs Total"] || 0);
const stateProgram = allPrograms.find((s) => s.State === state.id);
return total + (stateProgram?.["18-22 All Programs Total"] || 0);
}, 0);
}
return allStates.reduce((total, state) => {
return (
total +
selectedPrograms.reduce((stateTotal, program) => {
const programTotal = summary
.filter((item) => item.State === state.id && item.Title === program)
.reduce((sum, item) => sum + item.Amount, 0);
return stateTotal + programTotal;
}, 0)
);
return total + calculateTotal(state.id);
}, 0);
};
}, [selectedPrograms, allStates, allPrograms, calculateTotal]);
const colorScale = useMemo(() => {
const allTotals = allStates.map((state) => calculateTotal(state.id)).sort((a, b) => a - b);
const nonZeroData = allTotals.filter((value) => value > 0);
Expand All @@ -304,7 +294,7 @@ const LandingPageTotalMap = ({
}
const customScale = d3.scaleThreshold().domain(thresholds).range(mapColor);
return customScale;
}, [allStates, selectedPrograms, summary]);
}, [[allStates, calculateTotal, mapColor]]);

const handleProgramChange = (event) => {
const {
Expand Down Expand Up @@ -343,7 +333,11 @@ const LandingPageTotalMap = ({
};
}, []);
useEffect(() => {
// console.log(selectedPrograms);
// force trigger the color scale to update
setSelectedPrograms((prev) => [...prev]);
}, []);
useEffect(() => {
// console.log("selectedPrograms", selectedPrograms);
}, [selectedPrograms]);
return (
<div>
Expand Down

0 comments on commit 32203e4

Please sign in to comment.