-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frontend: Refactors Rate bar chart to D3 (#3713)
# Description and Motivation <!--- bulleted, high level items. use keywords (eg "closes #144" or "fixes #4323") --> - create drop in replacement component for the rate chart using d3 rather than Vega - splits out sub components like Axes, Gridlines etc for smaller code files and mimicking pattern from Mia (d3 trend charts) and @eriwarr (stacked share vs population charts) - rename rate chart card component that wraps the chart - renames ambiguous prop `metric` to more specific `mertricConfig` - hides the demographic type label (like "race and ethnicity") vertically along the y axis on small screens to give more horizontal space to the chart - hide the bar label qualifier ` per 100k` from the smallest screens ## Has this been tested? How? - e2e tests updated and passing - passing unit tests added for rate bar chart helper functions ## Screenshots (if appropriate) ### Screen Reader Walk Through Demo (Captions) https://github.com/user-attachments/assets/9fd9ff56-df1e-441d-b545-c34dc80376aa ### Mobile, Compare Mode, Hover Tooltip <img width="927" alt="Screenshot 2024-10-11 at 8 37 30 AM" src="https://github.com/user-attachments/assets/0c2f7eb9-77f7-4da3-8df0-4e7d82f3bcd2"> <img width="927" alt="Screenshot 2024-10-11 at 8 37 41 AM" src="https://github.com/user-attachments/assets/8cdf4817-d975-4f12-8762-7015cae4c4f7"> <img width="927" alt="Screenshot 2024-10-11 at 8 37 51 AM" src="https://github.com/user-attachments/assets/5faedd6c-f7f1-4249-83c4-42ddb4dd7b72"> <img width="927" alt="Screenshot 2024-10-11 at 8 38 31 AM" src="https://github.com/user-attachments/assets/ff85245d-464b-4e8d-9865-7ae3844cc3d3"> <img width="927" alt="Screenshot 2024-10-11 at 8 38 34 AM" src="https://github.com/user-attachments/assets/9b33de81-ff17-4485-8fbb-896c179515d8"> <img width="927" alt="Screenshot 2024-10-11 at 8 39 08 AM" src="https://github.com/user-attachments/assets/ffaa00cf-67fe-4de3-a5db-064da92b3f1c"> ### Desktop Various Units ![HET RATE-CHART Investigate rates of Depression in United States Oct 2024 (1)](https://github.com/user-attachments/assets/3e047cb0-a4be-4ae8-81a6-d70ecdfdf2d0) ![HET RATE-CHART Investigate rates of Depression in United States Oct 2024](https://github.com/user-attachments/assets/32433d2c-396f-422b-8c01-1fab49a20d2b) ![HET RATE-CHART Investigate rates of Excessive Drinking in United States Oct 2024](https://github.com/user-attachments/assets/592d3b6c-2d64-445f-a1f2-5a931f195701) ![HET RATE-CHART Investigate rates of HIV Stigma in United States Oct 2024](https://github.com/user-attachments/assets/e4eec7dc-4675-4f29-b2a6-a4dede506d80) ![HET RATE-CHART Investigate rates of Linkage to HIV Care in United States Oct 2024](https://github.com/user-attachments/assets/be17c5ff-23f8-4e26-b791-f5a3f2d6daa3) ## Types of changes (leave all that apply) - New content or feature - Refactor / chore ## New frontend preview link is below in the Netlify comment 😎
- Loading branch information
1 parent
613b523
commit 6c02577
Showing
25 changed files
with
897 additions
and
481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export interface BarChartTooltipData { | ||
x: number | ||
y: number | ||
content: string | ||
} | ||
|
||
interface BarChartTooltipProps { | ||
data: BarChartTooltipData | null | ||
} | ||
|
||
export default function BarChartTooltip({ data }: BarChartTooltipProps) { | ||
if (!data) return null | ||
const clickIsLeftHalfOfScreen = data.x < window.innerWidth / 2 | ||
return ( | ||
<div | ||
className='bg-white text-altBlack rounded-sm p-3 text-title absolute cursor-help z-top shadow-raised opacity-95 smMd:whitespace-nowrap' | ||
style={{ | ||
left: `${data.x}px`, | ||
top: `${data.y}px`, | ||
transform: clickIsLeftHalfOfScreen | ||
? 'translate(0, 5%)' | ||
: 'translate(-100%, 5%)', | ||
}} | ||
> | ||
{data.content} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { ScaleBand } from 'd3' | ||
import type { MetricConfig } from '../../data/config/MetricConfigTypes' | ||
import { formatValue } from './helpers' | ||
|
||
interface EndOfBarLabelProps { | ||
metricConfig: MetricConfig | ||
d: Record<string, any> | ||
shouldLabelBeInside: boolean | ||
barWidth: number | ||
yScale: ScaleBand<string> | ||
barLabelColor: string | ||
isTinyAndUp: boolean | ||
} | ||
|
||
export default function EndOfBarLabel(props: EndOfBarLabelProps) { | ||
return ( | ||
<text | ||
x={props.shouldLabelBeInside ? props.barWidth - 5 : props.barWidth + 5} | ||
y={props.yScale.bandwidth() / 2} | ||
dy='1.3em' | ||
textAnchor={props.shouldLabelBeInside ? 'end' : 'start'} | ||
className={`text-smallest ${props.barLabelColor}`} | ||
aria-hidden='true' | ||
tabIndex={-1} | ||
> | ||
{formatValue( | ||
props.d[props.metricConfig.metricId], | ||
props.metricConfig, | ||
props.isTinyAndUp, | ||
)} | ||
</text> | ||
) | ||
} |
Oops, something went wrong.