Skip to content

Commit

Permalink
always show highlighted cohort (totals only)
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Nov 13, 2020
1 parent beceb67 commit 7e0217a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ function prependZero(records) {
* Otherwise (i.e., a single cohort and some dimensional breakdown is selected),
* will return one data series per demographic subgroup.
*/
function prepareChartData({ data, dimension, selectedCohorts }) {
function prepareChartData({
data,
dimension,
highlightedCohort,
selectedCohorts,
}) {
const showDemographics =
selectedCohorts &&
selectedCohorts.length === 1 &&
Expand Down Expand Up @@ -98,6 +103,10 @@ function prepareChartData({ data, dimension, selectedCohorts }) {
if (!selectedCohorts) {
return true;
}
// highlighted cohort is included even if it's not selected
if (highlightedCohort && highlightedCohort.label === record.label) {
return true;
}
return selectedCohorts.some(({ id }) => id === record.label);
})
);
Expand All @@ -109,6 +118,7 @@ export default function VizRecidivismRates({
const chartData = prepareChartData({
data: recidivismRates,
dimension,
highlightedCohort,
selectedCohorts,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ test("renders one line per cohort", () => {
expect(getMainByLabelText("7 lines in a line chart")).toBeVisible();
});

test("renders the highlighted cohort even if it's not selected", () => {
const dimension = DIMENSION_KEYS.total;

render(
<VizRecidivismRates
data={{
dimension,
highlightedCohort: allSelectedCohorts[8],
recidivismRates: recidivismRatesFixture,
selectedCohorts: allSelectedCohorts.slice(0, 5),
}}
/>
);
expect(getMainByLabelText("6 lines in a line chart")).toBeVisible();
});

test("renders one line per demographic subgroup", () => {
const dimension = DIMENSION_KEYS.race;
render(
Expand Down

0 comments on commit 7e0217a

Please sign in to comment.