Skip to content

Commit

Permalink
Added visual legend instead of caption
Browse files Browse the repository at this point in the history
  • Loading branch information
nasaownsky committed May 27, 2022
1 parent 5341753 commit 879c76c
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React from "react";
import createMetricMapping from "../contentModels/createMetricMapping";
import HistoricalPopulationBreakdownMetric from "../contentModels/HistoricalPopulationBreakdownMetric";
import contentFixture from "../contentModels/__fixtures__/tenant_content_exhaustive";
import { renderWithTheme } from "../testUtils";
import { renderWithStore } from "../testUtils";
import MetricVizControls from "./MetricVizControls";

const testTenantId = "US_ND";
Expand All @@ -42,7 +42,7 @@ test("download button", () => {
const metric = getTestMetric();
jest.spyOn(metric, "download").mockImplementation(() => Promise.resolve());

renderWithTheme(<MetricVizControls filters={[]} metric={metric} />);
renderWithStore(<MetricVizControls filters={[]} metric={metric} />);

const download = screen.getByRole("button", { name: "Download Data" });
expect(download).toBeVisible();
Expand All @@ -53,7 +53,7 @@ test("download button", () => {

test("methodology modal", () => {
const metric = getTestMetric();
renderWithTheme(<MetricVizControls filters={[]} metric={metric} />);
renderWithStore(<MetricVizControls filters={[]} metric={metric} />);

const methodology = screen.getByRole("button", { name: "Methodology" });

Expand Down
3 changes: 3 additions & 0 deletions spotlight-client/src/MetricVizControls/MetricVizControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ import VizControls, { VizControlsProps } from "../VizControls";
type MetricVizControlsProps = {
filters: VizControlsProps["filters"];
metric: Metric<MetricRecord>;
smallData?: boolean;
};

const MetricVizControls = ({
filters,
metric,
smallData,
}: MetricVizControlsProps): React.ReactElement => {
return (
<VizControls
filters={filters}
download={() => metric.download()}
methodology={metric.methodology}
smallData={smallData}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import styled from "styled-components/macro";
import { ItemToHighlight, ProportionalBar } from "../charts";
import { DemographicCategoryRecords } from "../contentModels/types";
import VizControls, { VizControlsProps } from "../VizControls";
import VizNotes from "../VizNotes";

const CHART_HEIGHT = 165;
const CHART_HEIGHT_MOBILE = 100;
Expand Down Expand Up @@ -90,6 +89,7 @@ export default function BarChartPair({
filters={filters}
methodology={methodology}
download={download}
smallData={!preview}
/>
)}
<ProportionalBar
Expand All @@ -106,7 +106,6 @@ export default function BarChartPair({
highlighted={highlightedCategory}
setHighlighted={setHighlightedCategory}
/>
{!preview && <VizNotes smallData />}
</Wrapper>
);
}
4 changes: 2 additions & 2 deletions spotlight-client/src/VizControls/VizControls.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import { fireEvent, screen, within } from "@testing-library/react";
import React from "react";
import { renderWithTheme } from "../testUtils";
import { renderWithStore } from "../testUtils";
import VizControls from "./VizControls";

const mockDownload = jest.fn();
const mockMethodology = "test methodology";

beforeEach(() => {
renderWithTheme(
renderWithStore(
<VizControls
filters={[]}
download={mockDownload}
Expand Down
15 changes: 12 additions & 3 deletions spotlight-client/src/VizControls/VizControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =============================================================================

import { TooltipTrigger, Icon, IconSVG } from "@recidiviz/design-system";
import HTMLReactParser from "html-react-parser";
import { rem } from "polished";
import React, { useState } from "react";
import styled from "styled-components/macro";
import downloadPath from "../assets/cloud-download.svg";
import machineLearningPath from "../assets/machine-learning.svg";
import { useDataStore } from "../StoreProvider";
import { colors, CopyBlock, Modal, ModalHeading, zIndex } from "../UiLibrary";

const Wrapper = styled.div`
Expand All @@ -29,16 +31,16 @@ const Wrapper = styled.div`
flex-wrap: wrap;
justify-content: space-between;
z-index: ${zIndex.control};
margin-bottom: ${rem(32)};
`;

const ControlsGroup = styled.div`
display: flex;
flex-wrap: wrap;
margin-bottom: ${rem(16)};
align-items: center;
`;

const FilterWrapper = styled.div`
margin-bottom: ${rem(16)};
margin-right: ${rem(32)};
&:last-child {
Expand All @@ -53,7 +55,6 @@ const Button = styled.button`
cursor: pointer;
font-size: ${rem(14)};
font-weight: 500;
margin-bottom: ${rem(16)};
padding: none;
`;

Expand All @@ -72,14 +73,17 @@ export interface VizControlsProps {
filters: React.ReactNode[];
download: () => void;
methodology: string;
smallData?: boolean;
}

const VizControls = ({
download,
filters,
methodology,
smallData,
}: VizControlsProps): React.ReactElement => {
const [showMethodology, setShowMethodology] = useState(false);
const { tenant } = useDataStore();

return (
<Wrapper>
Expand All @@ -91,6 +95,11 @@ const VizControls = ({
// eslint-disable-next-line react/no-array-index-key
filter && <FilterWrapper key={index}>{filter}</FilterWrapper>
)}
{smallData && (
<TooltipTrigger maxWidth={232} contents={tenant?.smallDataDisclaimer}>
<Icon kind={IconSVG.Info} width={16} height={16} />
</TooltipTrigger>
)}
</ControlsGroup>
<ControlsGroup>
<Button onClick={() => download()}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ const VizDemographicsByCategory: React.FC<VizDemographicsByCategoryProps> = ({
<MetricVizControls
filters={[<DemographicFilterSelect metric={metric} />]}
metric={metric}
smallData
/>
{viz}
<VizNotes smallData unknowns={unknowns} download={download} />
<VizNotes unknowns={unknowns} download={download} />
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const VizPopulationBreakdownByLocation: React.FC<VizPopulationBreakdownByLocatio
<MetricVizControls
filters={[<LocalityFilterSelect metric={metric} />]}
metric={metric}
smallData
/>
{viz}
<StatisticWrapper>
Expand All @@ -71,11 +72,7 @@ const VizPopulationBreakdownByLocation: React.FC<VizPopulationBreakdownByLocatio
}
/>
</StatisticWrapper>
<VizNotes
smallData
unknowns={metric.unknowns}
download={metric.download}
/>
<VizNotes unknowns={metric.unknowns} download={metric.download} />
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const VizPrisonStayLengths: React.FC<VizPrisonStayLengthsProps> = ({
<MetricVizControls
filters={[<DemographicFilterSelect metric={metric} />]}
metric={metric}
smallData
/>
<AutoHeightTransition initialHeight={singleChartHeight}>
<ChartsWrapper>
Expand All @@ -109,7 +110,7 @@ const VizPrisonStayLengths: React.FC<VizPrisonStayLengthsProps> = ({
))}
</ChartsWrapper>
</AutoHeightTransition>
<VizNotes smallData unknowns={unknowns} download={metric.download} />
<VizNotes unknowns={unknowns} download={metric.download} />
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const VizRecidivismRateCumulative: React.FC<VizRecidivismRateCumulativeProps> =
),
]}
metric={metric}
smallData
/>
<ChartWrapper>
{chartTransitions.map(({ item, props, key }) => (
Expand Down Expand Up @@ -99,7 +100,7 @@ const VizRecidivismRateCumulative: React.FC<VizRecidivismRateCumulativeProps> =
</animated.div>
))}
</ChartWrapper>
<VizNotes smallData unknowns={unknowns} download={metric.download} />
<VizNotes unknowns={unknowns} download={metric.download} />
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const VizRecidivismRateSingleFollowup: React.FC<VizRecidivismRateSingleFollowupP
),
]}
metric={metric}
smallData
/>
<AutoHeightTransition initialHeight={singleChartHeight}>
<ChartsWrapper ref={measureRef}>
Expand All @@ -147,11 +148,7 @@ const VizRecidivismRateSingleFollowup: React.FC<VizRecidivismRateSingleFollowupP
))}
</ChartsWrapper>
</AutoHeightTransition>
<VizNotes
smallData
unknowns={unknowns}
download={metric.download}
/>
<VizNotes unknowns={unknowns} download={metric.download} />
</>
)}
</Measure>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const VizSentenceTypeByLocation: React.FC<VizSentenceTypeByLocationProps> = ({
<DemographicFilterSelect metric={metric} />,
]}
metric={metric}
smallData
/>
<ChartWrapper>
{chartTransitions.map(
Expand All @@ -77,11 +78,7 @@ const VizSentenceTypeByLocation: React.FC<VizSentenceTypeByLocationProps> = ({
)
)}
</ChartWrapper>
<VizNotes
smallData
unknowns={metric.unknowns}
download={metric.download}
/>
<VizNotes unknowns={metric.unknowns} download={metric.download} />
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const VizSupervisionSuccessRate: React.FC<VizSupervisionSuccessRateProps> = ({
<DemographicFilterSelect metric={metric} />,
]}
metric={metric}
smallData
/>
<CohortChartWrapper>
{cohortTransitions.map(({ item, key, props }) => (
Expand Down Expand Up @@ -155,11 +156,7 @@ const VizSupervisionSuccessRate: React.FC<VizSupervisionSuccessRateProps> = ({
</animated.div>
)}
</Measure>
<VizNotes
smallData
unknowns={metric.unknowns}
download={metric.download}
/>
<VizNotes unknowns={metric.unknowns} download={metric.download} />
</>
);
}
Expand Down

0 comments on commit 879c76c

Please sign in to comment.