Skip to content

Commit

Permalink
add chart labels to content blob
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Mar 5, 2021
1 parent dc4af9d commit d7908ff
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 28 deletions.
12 changes: 12 additions & 0 deletions spotlight-client/src/contentApi/sources/us_nd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,18 @@ const content: TenantContent = {
topology: programRegionsTopology,
},
},
racialDisparitiesNarrative: {
chartLabels: {
totalPopulation: "Proportions of races in the state",
totalSentenced: "Proportions of races sentenced and under DOCR control",
paroleGrant: "People released on parole",
incarceratedPopulation: "Overall prison population",
otherGroups: "All other racial/ethnic groups",
programmingParticipants: "Free Through Recovery active participants",
supervisionPopulation: "People subject to supervision",
totalPopulationSentences: "All people sentenced and under DOCR control",
},
},
};

export default content;
16 changes: 16 additions & 0 deletions spotlight-client/src/contentApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type TenantContent = NamedEntity & {
topologies?: {
ProgramRegions: MapData;
};
racialDisparitiesNarrative?: RacialDisparitiesNarrativeContent;
};

// ============================
Expand Down Expand Up @@ -139,3 +140,18 @@ export type SystemNarrativeContent = {
introduction: string;
sections: SystemNarrativeSection[];
};

export type RacialDisparitiesChartLabels = {
totalPopulation: string;
totalSentenced: string;
paroleGrant: string;
incarceratedPopulation: string;
otherGroups: string;
programmingParticipants: string;
supervisionPopulation: string;
totalPopulationSentences: string;
};

export type RacialDisparitiesNarrativeContent = {
chartLabels: RacialDisparitiesChartLabels;
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ import { fromPromise } from "mobx-utils";
import { RaceIdentifier } from "../demographics";
import { reactImmediately } from "../testUtils";
import RacialDisparitiesNarrative from "./RacialDisparitiesNarrative";
import contentFixture from "./__fixtures__/tenant_content_exhaustive";

let narrative: RacialDisparitiesNarrative;
const testTenantId = "US_ND";

beforeEach(() => {
narrative = RacialDisparitiesNarrative.build({ tenantId: testTenantId });
narrative = RacialDisparitiesNarrative.build({
tenantId: testTenantId,
content: contentFixture.racialDisparitiesNarrative,
});
});

test("file loading state", (done) => {
Expand Down
32 changes: 9 additions & 23 deletions spotlight-client/src/contentModels/RacialDisparitiesNarrative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import mapValues from "lodash.mapvalues";
import { makeAutoObservable, observable, runInAction } from "mobx";
import { upperCaseFirst } from "upper-case-first";
import { REVOCATION_TYPE_LABELS, SENTENCE_TYPE_LABELS } from "../constants";
import { TenantId } from "../contentApi/types";
import {
RacialDisparitiesChartLabels,
RacialDisparitiesNarrativeContent,
TenantId,
} from "../contentApi/types";
import { getDemographicCategories, RaceIdentifier } from "../demographics";
import { fetchAndTransformMetric } from "../metricsApi";
import {
Expand Down Expand Up @@ -92,21 +96,11 @@ function getSentencingMetrics(
};
}

type ChartLabels = {
totalPopulation: string;
totalSentenced: string;
paroleGrant: string;
incarceratedPopulation: string;
otherGroups: string;
programmingParticipants: string;
supervisionPopulation: string;
totalPopulationSentences: string;
};

type ConstructorOpts = {
tenantId: TenantId;
defaultCategory?: RaceIdentifier;
defaultSupervisionType?: SupervisionType;
content: RacialDisparitiesNarrativeContent;
};

/**
Expand All @@ -123,17 +117,7 @@ export default class RacialDisparitiesNarrative {
// metadata
readonly title = "Racial Disparities";

// TODO: customize text?
readonly chartLabels: ChartLabels = {
totalPopulation: "Proportions of races in the state",
totalSentenced: "Proportions of races sentenced and under DOCR control",
paroleGrant: "People released on parole",
incarceratedPopulation: "Overall prison population",
otherGroups: "All other racial/ethnic groups",
programmingParticipants: "Free Through Recovery active participants",
supervisionPopulation: "People subject to supervision",
totalPopulationSentences: "All people sentenced and under DOCR control",
};
readonly chartLabels: RacialDisparitiesChartLabels;

readonly tenantId: TenantId;

Expand Down Expand Up @@ -162,10 +146,12 @@ export default class RacialDisparitiesNarrative {
tenantId,
defaultCategory,
defaultSupervisionType,
content,
}: ConstructorOpts) {
this.tenantId = tenantId;
this.selectedCategory = defaultCategory || "BLACK";
this.supervisionType = defaultSupervisionType || "supervision";
this.chartLabels = content.chartLabels;

makeAutoObservable<RacialDisparitiesNarrative, "records">(this, {
records: observable.ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ const content: ExhaustiveTenantContent = {
topology: programRegionsTopology,
},
},
racialDisparitiesNarrative: {
chartLabels: {
totalPopulation: "Proportions of races in the state",
totalSentenced: "Proportions of races sentenced and under DOCR control",
paroleGrant: "People released on parole",
incarceratedPopulation: "Overall prison population",
otherGroups: "All other racial/ethnic groups",
programmingParticipants: "Active program participants",
supervisionPopulation: "People subject to supervision",
totalPopulationSentences: "All people sentenced and under DOCR control",
},
},
};

export default content;
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Object {
exports[`AMERICAN_INDIAN_ALASKAN_NATIVE data for programming data series 1`] = `
Array [
Object {
"label": "Free Through Recovery active participants",
"label": "Active program participants",
"records": Array [
Object {
"color": "#25636F",
Expand Down Expand Up @@ -661,7 +661,7 @@ Object {
exports[`BLACK data for programming data series 1`] = `
Array [
Object {
"label": "Free Through Recovery active participants",
"label": "Active program participants",
"records": Array [
Object {
"color": "#25636F",
Expand Down Expand Up @@ -1079,7 +1079,7 @@ Object {
exports[`HISPANIC data for programming data series 1`] = `
Array [
Object {
"label": "Free Through Recovery active participants",
"label": "Active program participants",
"records": Array [
Object {
"color": "#25636F",
Expand Down Expand Up @@ -1497,7 +1497,7 @@ Object {
exports[`OTHER data for programming data series 1`] = `
Array [
Object {
"label": "Free Through Recovery active participants",
"label": "Active program participants",
"records": Array [
Object {
"color": "#25636F",
Expand Down

0 comments on commit d7908ff

Please sign in to comment.