From eb8ff183aa0f7daaf803a1f4c342105455c104e5 Mon Sep 17 00:00:00 2001 From: Qianru Zhang Date: Wed, 2 Aug 2023 10:34:25 -0400 Subject: [PATCH 1/2] Sample InequalityImpact --- src/api/language.js | 7 +++++++ src/pages/policy/output/InequalityImpact.jsx | 13 +++++-------- src/pages/policy/output/PovertyImpact.jsx | 13 +++++-------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/api/language.js b/src/api/language.js index e5c457b55..c6a62c393 100644 --- a/src/api/language.js +++ b/src/api/language.js @@ -41,6 +41,13 @@ export function percent(number) { ); } +export function formatPercentageChange(number) { + const changePercentage = (number * 100).toFixed(6); + const roundedPercentage = parseFloat(changePercentage); + const significantDigits = roundedPercentage.toPrecision(1); + return `${significantDigits}%`; +} + export function cardinal(number) { // E.g. 1 -> 'first', 2 -> 'second', 3 -> 'third' const suffixes = ["th", "st", "nd", "rd"]; diff --git a/src/pages/policy/output/InequalityImpact.jsx b/src/pages/policy/output/InequalityImpact.jsx index 979d4d827..9684e79c8 100644 --- a/src/pages/policy/output/InequalityImpact.jsx +++ b/src/pages/policy/output/InequalityImpact.jsx @@ -1,7 +1,7 @@ import { useContext } from "react"; import Plot from "react-plotly.js"; import { ChartLogo } from "../../../api/charts"; -import { percent } from "../../../api/language"; +import { percent, formatPercentageChange } from "../../../api/language"; import HoverCard, {HoverCardContext} from "../../../layout/HoverCard"; import useMobile from "../../../layout/Responsive"; import DownloadableScreenshottable from "./DownloadableScreenshottable"; @@ -39,12 +39,9 @@ export default function InequalityImpact(props) { value < 0 ? style.colors.DARK_GREEN : style.colors.DARK_GRAY ), }, - text: metricChanges.map( - (value) => - (value >= 0 ? "+" : "") + - (value * 100).toFixed(1).toString() + - "%" - ), + text: metricChanges.map((value) => { + return formatPercentageChange(value); + }), textangle: 0, hoverinfo: "none", }, @@ -58,7 +55,7 @@ export default function InequalityImpact(props) { tickformat: ",.1%", }, uniformtext: { - mode: "hide", + mode: "show", minsize: 12, }, ...ChartLogo(mobile ? 0.97 : 0.97, mobile ? -0.25 : -0.15), diff --git a/src/pages/policy/output/PovertyImpact.jsx b/src/pages/policy/output/PovertyImpact.jsx index 5415e1d03..0629701a0 100644 --- a/src/pages/policy/output/PovertyImpact.jsx +++ b/src/pages/policy/output/PovertyImpact.jsx @@ -1,7 +1,7 @@ import { useContext, useEffect } from 'react'; import Plot from "react-plotly.js"; import { ChartLogo } from "../../../api/charts"; -import { percent } from "../../../api/language"; +import { percent, formatPercentageChange } from "../../../api/language"; import HoverCard, {HoverCardContext} from "../../../layout/HoverCard"; import useMobile from "../../../layout/Responsive"; import DownloadableScreenshottable from "./DownloadableScreenshottable"; @@ -61,12 +61,9 @@ export default function PovertyImpact(props) { value < 0 ? style.colors.DARK_GREEN : style.colors.DARK_GRAY ), }, - text: povertyChanges.map( - (value) => - (value >= 0 ? "+" : "") + - (value * 100).toFixed(1).toString() + - "%" - ), + text: povertyChanges.map((value) => { + return formatPercentageChange(value); + }), textangle: 0, hoverinfo: "none", }, @@ -134,7 +131,7 @@ export default function PovertyImpact(props) { ); } - const povertyRateChange = percent(Math.abs(totalPovertyChange)); + const povertyRateChange = formatPercentageChange(Math.abs(totalPovertyChange)); const percentagePointChange = Math.round( Math.abs( From 9e280caa312e40767c8a62a7023f88ea22712f91 Mon Sep 17 00:00:00 2001 From: Qianru Zhang Date: Wed, 9 Aug 2023 00:22:00 -0400 Subject: [PATCH 2/2] Add Federal to Tax revenues --- src/pages/policy/output/BudgetaryImpact.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/policy/output/BudgetaryImpact.jsx b/src/pages/policy/output/BudgetaryImpact.jsx index a7196a406..abbe9c525 100644 --- a/src/pages/policy/output/BudgetaryImpact.jsx +++ b/src/pages/policy/output/BudgetaryImpact.jsx @@ -29,7 +29,7 @@ export default function BudgetaryImpact(props) { "Net impact", ]; let mobileLabels = ["Federal taxes", "State taxes", "Benefits", "Net"]; - if (region !== "us" && region !== "ca") { + if (region == "us" || region == "ca") { desktopLabels[0] = "Tax revenues"; mobileLabels[0] = "Taxes"; }