Skip to content

Commit

Permalink
Add department name for pie chart downloads (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
Afani97 authored Aug 8, 2023
1 parent f9af6fb commit 9e3705d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions frontend/src/Components/Charts/TrafficStops/TrafficStops.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,20 @@ function TrafficStops(props) {
);
};

const pieChartTitle = (download = false) => {
let subject = stopsChartState.data[AGENCY_DETAILS].name;
if (subjectObserving() === 'officer') {
subject = `Officer ${officerId}`;
}
let title = `Traffic Stops By Percentage for ${subject} ${
year === YEARS_DEFAULT ? `since ${stopsChartState.yearRange[0]}` : `during ${year}`
}`;
if (download) {
title = `${title.split(' ').join('_').toLowerCase()}.png`;
}
return title;
};

return (
<TrafficStopsStyled>
{/* Traffic Stops by Percentage */}
Expand Down Expand Up @@ -567,11 +581,13 @@ function TrafficStops(props) {
isOpen={showZoomedPieChart}
closeModal={() => setShowZoomedPieChart(false)}
chartToPrintRef={zoomedPieCharRef}
fileName={pieChartTitle(true)}
>
<S.PieSection zoomed>
<S.PieWrapper zoomed>
<PieChart
data={byPercentagePieData}
title={pieChartTitle()}
displayTitle
displayLegend
displayOutlabels
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Components/NewCharts/ChartModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function ChartModal({
isOpen,
closeModal,
chartToPrintRef,
fileName = 'chart.png',
children,
}) {
const theme = useTheme();
Expand All @@ -41,7 +42,7 @@ export default function ChartModal({

const downloadChart = useCallback(() => {
const link = document.createElement('a');
link.download = 'chart.png';
link.download = fileName;
link.href = chartToPrintRef.current.toBase64Image();
link.click();
});
Expand Down

0 comments on commit 9e3705d

Please sign in to comment.