Skip to content
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
13 changes: 11 additions & 2 deletions src/components/chart/CardChartByGroup1.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import { observer } from 'mobx-react';
import { useSelector } from 'react-redux';
import { useTranslation } from 'react-i18next';
import { formatComparePeriod, getComparisonEndMonth } from '../../utils/chartDataUtils';
import { useStore } from '../../stores/storeConfig';
import { RootState } from '../../stores/store';
import { useMemos } from '../../hooks/myUseMemo';
Expand Down Expand Up @@ -33,7 +35,13 @@ const CardChartByGroup1: React.FC<{}> = observer(() => {
// const { t } = useTranslation();
const [showModal, setShowModal] = useState(false);
const { filterStore } = useStore();
const { dataFilterd, getChartData, getCompareChartData } = filterStore;
const { t, i18n } = useTranslation();
const { dataFilterd, getChartData, getCompareChartData, compareEnabled, compareFromYear, compareToYear } = filterStore;
const dataUpdatedTo = useSelector((state: RootState) => state.appUi.dataUpdatedTo);
const comparePeriod = compareEnabled
? formatComparePeriod(compareFromYear, compareToYear, getComparisonEndMonth(dataUpdatedTo), i18n.language)
: '';
const header = comparePeriod ? `${t('compare_header')}: ${comparePeriod}` : undefined;
const chartId = EchartId.Group_1;
const dataFormated = getChartData(chartId);
const compareData = getCompareChartData(chartId);
Expand All @@ -50,12 +58,13 @@ const CardChartByGroup1: React.FC<{}> = observer(() => {
const memoSettingsIcon = useMemos([],
<SvgIconSettings color={'var(--onprimary-color)'} />
);

return (
<>
<SmallCard style={{ marginBottom: '0.5rem' }}>
<div className="chart-config">
<SelectGroupBy id="Graphs.Main.SelectGroupby" />
<span style={{ fontSize: 14, fontWeight: 'bold' }}>{header}</span>
<div className="chart-config-row">
<SelectSortBy id="Graphs.Main.SelectSort" />
<Button
Expand Down
7 changes: 4 additions & 3 deletions src/components/chart/CardChartGrpBy2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ const CardChartGrpBy2: FC<IProps> = observer(() => {
&nbsp;
<SelectGroupBy2 id="Graphs" />
{/* <RangeSlider id="Graphs" label="resize" value={80} onChange={onSizeSliderChange}/> */}
<div style={{ width: '250px', margin: '0 auto' }}>
<ChartDataFilterSlider id={chartId} data={dataGroupby2} />
</div>

</div>
<hr />
<div style={styles.divChart}>
<ChartBar data={dataFormated} metaData={metaDAta} chartType={chartType} dir={direction} />
</div>
<div style={{ width: '250px', margin: '0 auto' }}>
<ChartDataFilterSlider id={chartId} data={dataGroupby2} />
</div>
</SmallCard>
)}
</div>
Expand Down
14 changes: 12 additions & 2 deletions src/components/chart/CardChartYears.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@ import ChartBar from './ChartBar';
import { RootState } from '../../stores/store';
import ChartDataFilterSlider from '../organisms/ChartDataFilterSlider';
import { EchartId } from '../types';
import { formatComparePeriod, getComparisonEndMonth } from '../../utils/chartDataUtils';

const CardChartYears: React.FC<{}> = observer(() => {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const { filterStore } = useStore();
const { casualtiesNames, getChartData, getCompareChartData, compareYearsEnabled, setCompareYearsEnabled } = filterStore;
const chartId = EchartId.Years;
const dataFormated = getChartData(chartId);
const compareData = getCompareChartData(chartId);
const direction = useSelector((state: RootState) => state.appUi.direction);
const dataUpdatedTo = useSelector((state: RootState) => state.appUi.dataUpdatedTo);
const comparePeriod = compareYearsEnabled
? formatComparePeriod(
Number(filterStore.timeStore.startYear.queryValue),
Number(filterStore.timeStore.endYear.queryValue),
getComparisonEndMonth(dataUpdatedTo),
i18n.language)
: '';
const header = `${t(casualtiesNames)} ${t('by-years')}${comparePeriod ? ` | ${t('compare_header')}: ${comparePeriod}` : ''}`;
const styles = {
divChart: {
width: '100%',
height: '56vh',
},
};
return (
<SmallCard styleType={2} header={`${t(casualtiesNames)} ${t('by-years')}`}>
<SmallCard styleType={2} header={header}>
<div style={styles.divChart}>
<ChartBar data={dataFormated} compareData={compareData} fill="#FE9772" dir={direction} />
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/chart/GroupByGraphsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export const GroupByGraphsPanel: React.FC<IProps> = observer(() => {
const { injuriesCount } = filterStore;
if (injuriesCount > 0 || true) {
return (
<div style={styles.divCharts}>
<div style={styles.divCharts}>
<Row>
<Col md={4}>
<Col md={4}>
<CardChartYears />
</Col>
<Col md={8} >
Expand Down
1 change: 1 addition & 0 deletions src/lng/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
"SwitchUser": "Switch User",
"ContactForMoreDetails": "For more details contact us",
"outside_range": "Outside Range",
"compare_header": "Comparison",
"compare_to_period": "Compare to period",
"compare_period": "Comparison period",
"compare_to_last_update_month": "Show relative to last update month",
Expand Down
1 change: 1 addition & 0 deletions src/lng/he/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
"SwitchUser": "החלף משתמש",
"ContactForMoreDetails": "לפרטים נוספים צרו קשר",
"outside_range": "מחוץ לטווח",
"compare_header": "השוואה",
"compare_to_period": "השוואה לתקופה",
"compare_period": "תקופת השוואה",
"compare_to_last_update_month": "הצג ביחס לחודש עדכון אחרון",
Expand Down
12 changes: 12 additions & 0 deletions src/utils/chartDataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ export const getComparisonEndMonth = (updatedToSec: number | null | undefined):
return day === daysInMonth ? month : month - 1;
};

/**
* Text of the comparison range for a chart header, e.g. "2021-2025 (Jan-Sep)".
* Returns '' when the end month is unknown.
*/
export const formatComparePeriod = (fromYear: number, toYear: number, endMonth: number, locale?: string): string => {
if (endMonth < 1) return '';
const monthName = (m: number) => new Intl.DateTimeFormat(locale, { month: 'short', timeZone: 'UTC' }).format(new Date(Date.UTC(2000, m - 1, 1)));
const years = fromYear === toYear ? `${fromYear}` : `${fromYear}-${toYear}`;
const months = endMonth === 1 ? monthName(1) : `${monthName(1)}-${monthName(endMonth)}`;
return `${years} (${months})`;
};

/**
* Align comparison-period counts to the main chart items (same order, missing -> 0).
* The 'outside_range' item gets the comparison total of every category not shown as a bar.
Expand Down
Loading