Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes PHRMA Brffs frontend income sorting and unknown handling #3624

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 11 additions & 148 deletions frontend/package-lock.json

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

2 changes: 0 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"biome": "^0.3.3",
"d3": "^7.8.5",
"data-forge": "^1.10.2",
"dataframe-js": "^1.4.4",
"env-cmd": "^10.1.0",
"history": "^5.3.0",
"html2canvas": "^1.4.1",
Expand Down Expand Up @@ -61,7 +60,6 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^16.0.1",
"@types/d3": "^7.4.0",
"@types/dataframe-js": "^1.4.3",
"@types/lodash": "^4.17.7",
"@types/node": "^22.5.2",
"@types/react": "^18.3.5",
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/cards/AgeAdjustedTableCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ export default function AgeAdjustedTableCard(props: AgeAdjustedTableCardProps) {
RACE,
)

const isWrongDemographicType = props.demographicType === SEX
const demosShowingAgeAdjusted: DemographicType[] = [
'age',
'race_and_ethnicity',
]

const isWrongDemographicType = !demosShowingAgeAdjusted.includes(
props.demographicType,
)
const noRatios = knownRaceData.every(
(row) => row[ratioId] === undefined,
)
Expand Down Expand Up @@ -182,7 +189,7 @@ export default function AgeAdjustedTableCard(props: AgeAdjustedTableCardProps) {
{/* values are present or partially null, implying we have at least some age-adjustments */}
{!raceQueryResponse.dataIsMissing() &&
!noRatios &&
props.demographicType !== SEX && (
!isWrongDemographicType && (
<AgeAdjustedTableChart
data={knownRaceData}
metricConfigs={ratioConfigs}
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/cards/MapCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { dataSourceMetadataMap } from '../data/config/MetadataMap'
import type { DatasetId } from '../data/config/DatasetMetadata'
import HetNotice from '../styles/HetComponents/HetNotice'
import HetTerm from '../styles/HetComponents/HetTerm'
import { getSortArgs } from '../data/sorting/sortingUtils'

const SIZE_OF_HIGHEST_LOWEST_GEOS_RATES_LIST = 5
const HASH_ID: ScrollableHashId = 'rate-map'
Expand Down Expand Up @@ -321,10 +322,7 @@ function MapCardWithKey(props: MapCardProps) {
)

const sviQueryResponse: MetricQueryResponse = queryResponses[3] || null
const sortArgs =
demographicType === AGE
? ([new AgeSorterStrategy([ALL]).compareFn] as any)
: []
const sortArgs = getSortArgs(demographicType)

const fieldValues = mapQueryResponse.getFieldValues(
/* fieldName: DemographicType */ demographicType,
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/cards/SimpleBarChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ function SimpleBarChartCardWithKey(props: SimpleBarChartCardProps) {
elementsToHide={elementsToHide}
>
{([queryResponse], metadata) => {
const data = queryResponse.getValidRowsForField(metricConfig.metricId)
// for consistency, filter out any 'Unknown' rows that might have rates (like PHRMA)
const data = queryResponse
.getValidRowsForField(metricConfig.metricId)
.filter((row) => row[props.demographicType] !== 'Unknown')

const hideChart =
data.length === 0 ||
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/cards/TableCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { CountColsMap } from '../charts/mapGlobals'
import HetNotice from '../styles/HetComponents/HetNotice'
import { generateSubtitle } from '../charts/utils'
import HetDivider from '../styles/HetComponents/HetDivider'
import { sortForVegaByIncome } from '../data/sorting/IncomeSorterStrategy'

// We need to get this property, but we want to show it as
// part of the "population_pct" column, and not as its own column
Expand Down Expand Up @@ -164,6 +165,10 @@ export default function TableCard(props: TableCardProps) {
queryResponse.shouldShowMissingDataMessage(normalMetricIds) ||
data.length <= 0

if (props.demographicType === 'income') {
data = sortForVegaByIncome(data)
}

return (
<>
{!queryResponse.dataIsMissing() && data.length > 0 && (
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/charts/AgeAdjustedTableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ export function AgeAdjustedTableChart(props: AgeAdjustedTableChartProps) {

/** Component for the table's header row **/
function TableHeaderRow({ group }: { group: HeaderGroup<any> }) {
const { key, ...restHeaderGroupProps } = group.getHeaderGroupProps()
return (
<TableRow {...group.getHeaderGroupProps()}>
{group.headers.map((col, index) => (
<TableRow key={key} {...restHeaderGroupProps}>
{group.headers.map((col) => (
<TableCell key={col.id} style={headerCellStyle}>
{col.render('Header')}
</TableCell>
Expand All @@ -107,8 +108,10 @@ export function AgeAdjustedTableChart(props: AgeAdjustedTableChartProps) {
/** Component for the table's data rows **/
function TableDataRow({ row }: { row: Row<any> }) {
prepareRow(row)
const { key, ...restRowProps } = row.getRowProps()

return (
<TableRow {...row.getRowProps()}>
<TableRow key={key} {...restRowProps}>
{row.cells.map((cell, index) =>
cell.value == null ? (
<TableCell
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/charts/SimpleHorizontalBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from './utils'
import { createBarLabel } from './mapHelperFunctions'
import { het, ThemeZIndexValues } from '../styles/DesignTokens'
import { sortForVegaByIncome } from '../data/sorting/IncomeSorterStrategy'

// determine where (out of 100) to flip labels inside/outside the bar
const LABEL_SWAP_CUTOFF_PERCENT = 66
Expand Down Expand Up @@ -283,12 +284,16 @@ export function SimpleHorizontalBarChart(props: SimpleHorizontalBarChartProps) {
const [dataWithDisplayCol, barMetricDisplayColumnName] =
addMetricDisplayColumn(props.metric, dataWithLineBreakDelimiter)
// Omit the % symbol for the tooltip because it's included in shortLabel.
const [data, tooltipMetricDisplayColumnName] = addMetricDisplayColumn(
let [data, tooltipMetricDisplayColumnName] = addMetricDisplayColumn(
props.metric,
dataWithDisplayCol,
/* omitPctSymbol= */ true,
)

if (props.demographicType === 'income') {
data = sortForVegaByIncome(data)
}

const barLabelBreakpoint =
Math.max(...props.data.map((row) => row[props.metric.metricId])) *
(LABEL_SWAP_CUTOFF_PERCENT / 100)
Expand Down
Loading
Loading