Skip to content

Add killed and injured count per age group stacked #1161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading