Skip to content

Commit

Permalink
Merge pull request #1161 from data-for-change/add_killed_and_injured_…
Browse files Browse the repository at this point in the history
…count_per_age_group_stacked

Add killed and injured count per age group stacked
  • Loading branch information
atalyaalon authored Nov 18, 2024
2 parents 4959db7 + 88c6a35 commit fcb99b4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/molecules/GenericBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface ISingleBarChartProps extends IBarChartBaseProps {}

interface IMultiBarChartProps extends IBarChartBaseProps {
isStacked: boolean;
customYLabels?: string[];
editorBarOptions?: Record<number, boolean>;
}

Expand Down Expand Up @@ -106,13 +107,15 @@ const MultiBarChart: FC<IMultiBarChartProps> = ({
isStacked,
textLabel,
subtitle,
customYLabels,
editorBarOptions,
}) => {
const theme = useTheme();
const colors = (theme.palette.primary as ColorScheme).barChartColors;

const yLabels = data ? Object.keys(data[0]) : [];
yLabels.splice(0, 1);
const defaultYLabels = data ? Object.keys(data[0]) : [];
const yLabels= customYLabels || defaultYLabels.slice(1);

const maxBarsNum = yLabels.length;
const filteredColors: Record<string, any> =
editorBarOptions && Object.keys(editorBarOptions).length !== 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { FC } from 'react';
import { IWidgetMultiBarData } from 'models/WidgetData';
import { createBarWidget } from 'utils/barChart.utils';
import { MultiBarChart } from '../GenericBarChart';


interface IProps {
data: IWidgetMultiBarData;
editorBarOptions: Record<number, boolean>;
}

const KilledAndInjuredCountPerAgeGroupStackedWidget: FC<IProps> = ({ data, editorBarOptions }) => {
const { text } = data;
const multiBarSeries = createBarWidget(data, editorBarOptions);
return <MultiBarChart isStacked={true} isPercentage={false} data={multiBarSeries}
textLabel={text.title}
customYLabels={Object.values(text.labels_map)}
subtitle={text.subtitle}
editorBarOptions={editorBarOptions} />;
};
export default KilledAndInjuredCountPerAgeGroupStackedWidget;
5 changes: 5 additions & 0 deletions src/components/molecules/widgets/WidgetWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { IPoint } from 'models/Point';
import { WidgetName } from 'models/WidgetName';
import KilledAndInjuredCountPerAgeGroupWidget from './KilledAndInjuredCountPerAgeGroupWidget';
import { getInjuredBySeverityVerbLabel } from 'utils/text.utils';
import KilledAndInjuredCountPerAgeGroupStackedWidget from './KilledAndInjuredCountPerAgeGroupStackedWidget';

interface IProps {
widget: IWidgetBase;
Expand Down Expand Up @@ -149,6 +150,10 @@ const WidgetWrapper: FC<IProps> = ({ widget, locationText, sizeOptions, editorBa
widgetComponent = <CountInjuredByYearBarWidget data={data as IWidgetMultiBarData} editorBarOptions={editorBarOptions} />;
break;
}
case WidgetName.killed_and_injured_count_per_age_group_stacked: {
widgetComponent = <KilledAndInjuredCountPerAgeGroupStackedWidget data={data as IWidgetMultiBarData} editorBarOptions={editorBarOptions} />;
break;
}
case WidgetName.accident_count_by_day_night: {
widgetComponent = <CountAccidentsByDayNightPieWidget data={data as IWidgetAccidentsByDayNightData} />;
break;
Expand Down
3 changes: 2 additions & 1 deletion src/const/cards.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const operationalCards: WidgetName[] = [
WidgetName.injured_count_by_accident_year,
// WidgetName.accident_count_by_driver_type,
WidgetName.killed_and_injured_count_per_age_group,
WidgetName.accident_count_by_day_night
WidgetName.accident_count_by_day_night,
WidgetName.killed_and_injured_count_per_age_group_stacked,
];

export type OrgLogoData = {key : string, path:string} ;
Expand Down
1 change: 1 addition & 0 deletions src/models/WidgetName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export enum WidgetName {
injured_accidents_with_pedestrians = 'injured_accidents_with_pedestrians',
injured_count_by_severity = 'injured_count_by_severity',
killed_and_injured_count_per_age_group = 'killed_and_injured_count_per_age_group',
killed_and_injured_count_per_age_group_stacked = 'killed_and_injured_count_per_age_group_stacked',
}
4 changes: 4 additions & 0 deletions src/services/data.verification/data.verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export const verifiedWidgetData = (widget: any) => {
isValid = items.every((item: any) => validNumber(item.label_key) && validDataSeries(item.series));
break;
}
case 'killed_and_injured_count_per_age_group_stacked': {
isValid = items.every((item: any) => validString(item.label_key) && validDataSeries(item.series));
break;
}
case 'accident_count_by_day_night': {
isValid = items.every((item: any) => validString(item.day_night) && validNumber(item.count));
break;
Expand Down
2 changes: 2 additions & 0 deletions src/services/widgets.style.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const widgetVariants: { [index: string]: CardVariant } = {
footer: FooterVariant.LogoWithRange,
},
[WidgetName.accidents_heat_map]: { header: HeaderVariant.Centered, footer: FooterVariant.LogoWithRange },
[WidgetName.killed_and_injured_count_per_age_group_stacked]: { header: HeaderVariant.Centered, footer: FooterVariant.LogoWithRange },

};

export function getWidgetVariant(widgetName: string) {
Expand Down

0 comments on commit fcb99b4

Please sign in to comment.