diff --git a/client/src/views/Report/DonutChart/index.js b/client/src/views/CommonCharts/DonutChart/index.js similarity index 74% rename from client/src/views/Report/DonutChart/index.js rename to client/src/views/CommonCharts/DonutChart/index.js index f454919..05d0ea5 100644 --- a/client/src/views/Report/DonutChart/index.js +++ b/client/src/views/CommonCharts/DonutChart/index.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { isNotDefined } from '@togglecorp/fujs'; import { PieChart, @@ -15,7 +16,7 @@ const CustomTooltip = ({ active, payload }) => { if (!active) { return null; } - if (payload.length <= 0) { + if (isNotDefined(payload) || payload.length <= 0) { return null; } @@ -43,9 +44,12 @@ export default function DonutChart(props) { const { data, colorScheme, + donutChartHeight, + donutChartWidth, } = props; - if (data.length <= 0) { + + if (isNotDefined(data) || data.length <= 0) { return (
Nothings to show. @@ -56,22 +60,24 @@ export default function DonutChart(props) { return (
{data.map((d, index) => ( ))} @@ -82,7 +88,14 @@ export default function DonutChart(props) { ); } +DonutChart.defaultProps = { + donutChartHeight: 180, + donutChartWidth: '100%', +}; + DonutChart.propTypes = { + donutChartHeight: PropTypes.number, + donutChartWidth: PropTypes.string, data: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types colorScheme: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types }; diff --git a/client/src/views/Report/DonutChart/styles.scss b/client/src/views/CommonCharts/DonutChart/styles.scss similarity index 92% rename from client/src/views/Report/DonutChart/styles.scss rename to client/src/views/CommonCharts/DonutChart/styles.scss index 55b6b07..fe0f495 100644 --- a/client/src/views/Report/DonutChart/styles.scss +++ b/client/src/views/CommonCharts/DonutChart/styles.scss @@ -14,3 +14,7 @@ margin-bottom: 0; font-size: var(--font-size-super-large); } + +.cell { + cursor: pointer; +} diff --git a/client/src/views/Dashboard/GroupedBarChart/index.js b/client/src/views/Dashboard/GroupedBarChart/index.js new file mode 100644 index 0000000..4d5c2ed --- /dev/null +++ b/client/src/views/Dashboard/GroupedBarChart/index.js @@ -0,0 +1,83 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { isNotDefined } from '@togglecorp/fujs'; + +import { + BarChart, + Bar, + XAxis, + YAxis, + Tooltip, + Legend, + ResponsiveContainer, + ComposedChart, + Line, +} from 'recharts'; + +function CustomizedLabel(props) { + const { x, y, width, value } = props; + return ( + + {value} + + ); +} + +export default function GroupedBarChart(props) { + const { + data, + lineKey, + } = props; + + if (isNotDefined(data) || isNotDefined(data.values) || data.values.length <= 0) { + return ( +
Nothing to show
+ ); + } + + return ( + + + + + + + {data.columns.map(column => ( + } + style={{ cursor: 'pointer' }} + /> + ))} + {!!lineKey && ( + + )} + + + ); +} + +GroupedBarChart.defaultProps = { + lineKey: '', +}; + +GroupedBarChart.propTypes = { + data: PropTypes.object.isRequired, + lineKey: PropTypes.string, +}; diff --git a/client/src/views/Dashboard/Summary/index.js b/client/src/views/Dashboard/Summary/index.js index 1d1b758..7bad927 100644 --- a/client/src/views/Dashboard/Summary/index.js +++ b/client/src/views/Dashboard/Summary/index.js @@ -21,6 +21,8 @@ import LanguagePeopleGroupDisability from '#components/LanguagePeopleGroupDisabi import { transformSoi } from '#utils/transform'; +import DonutChartRecharts from '../../CommonCharts/DonutChart'; + import styles from './styles.scss'; const propTypes = { @@ -40,6 +42,8 @@ const defaultProps = { const droppedKey = 'total_no_of_rc_records_dropped_during_the_month'; const rcAwayKey = 'total_rc_temporarily_away'; +const donutChartHeight = 120; + const ageKeyMap = { '<=6': '0 - 6', '7-12': '7 - 12', @@ -70,6 +74,7 @@ const legendColorSelector = d => d.color; const donutColor = ['#41cf76', '#f44336']; const soiColorScheme = ['#ef5350', '#fff176', '#81c784']; + const sectionPercents = [0.75, 0.1, 0.15]; const mvcIndicatorKeySelector = d => d.label; @@ -366,7 +371,7 @@ export default class Summary extends PureComponent { }; const primaryUneducated = { - key: 'PrimaryUnEducated', + key: 'PrimaryUneducated', value: this.getValueFromMap(educationMap, '@PrimarySchoolAgeNoEducation') || 0, label: 'Primary School Age RC Not Involved in Education', }; @@ -397,7 +402,7 @@ export default class Summary extends PureComponent { const educated = education.filter(values => ( values.key === 'PrimaryEducated' - || values.key === 'SecondaryEducated' + || values.key === 'SecondaryEducated' )).reduce((a, b) => ({ ...a, value: a.value + b.value }), { value: 0, key: 'educated', @@ -406,7 +411,7 @@ export default class Summary extends PureComponent { const uneducated = education.filter(values => ( values.key === '@SecondarySchoolAgeNoEducation' - || values.key === '@PrimarySchoolAgeNoEducation' + || values.key === '@PrimarySchoolAgeNoEducation' )).reduce((a, b) => ({ ...a, value: a.value + b.value }), { value: 0, key: 'uneducated', @@ -635,6 +640,18 @@ export default class Summary extends PureComponent { ].filter(v => v.value); }) + getDonutDataWithName = memoize((donutData) => { + if (isFalsy(donutData)) { + return []; + } + + const dataWithName = donutData.map(data => ({ + ...data, + name: data.label, + })); + return dataWithName; + }); + render() { const { className, @@ -682,6 +699,10 @@ export default class Summary extends PureComponent { mostVulnerableChildrenVulnerabilityMarker, ); + const healthNutritionWithName = this.getDonutDataWithName(healthNutrition); + const educationInvolvementWithName = this.getDonutDataWithName(educationInvolvement); + const childMonitoringVizDataWithName = this.getDonutDataWithName(childMonitoringVizData); + const infoText = `The data below is aggregated from sponsorship management report from ${noOfProjects} @@ -717,7 +738,14 @@ export default class Summary extends PureComponent {

Health / Nutrition

- + {/* + /> */}

Education

- + {/* + /> */} +

Child Monitoring Status

- + {/* + /> */}

RC Supply Trend

- 0 && ( + + )} + {/* + /> */}

Child Monitoring Trend

- 0 && ( + + )} + {/* + /> */}

Health Nutrition Trend

- 0 && ( + + )} + {/* + /> */}

Correspondence Trend

- 0 && ( + + )} + {/* + /> */}

Education Trend

- 0 && ( + + )} + {/* + /> */}

SOI Trend

- 0 && ( + + )} + {/* + /> */}
); diff --git a/client/src/views/Report/GroupedBarChart.js b/client/src/views/Report/GroupedBarChart.js index abfd544..c79c2f5 100644 --- a/client/src/views/Report/GroupedBarChart.js +++ b/client/src/views/Report/GroupedBarChart.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { isNotDefined } from '@togglecorp/fujs'; import { BarChart, @@ -18,7 +19,7 @@ export default function GroupedBarChart(props) { } = props; - if (data.values.length <= 0) { + if (isNotDefined(data) || isNotDefined(data.values) || data.values.length <= 0) { return (
Nothing to show
); diff --git a/client/src/views/Report/HorizontalBar.js b/client/src/views/Report/HorizontalBar.js index cb29251..0bf2f7d 100644 --- a/client/src/views/Report/HorizontalBar.js +++ b/client/src/views/Report/HorizontalBar.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { isNotDefined } from '@togglecorp/fujs'; import { BarChart, @@ -18,7 +19,7 @@ export default function HorizontalBar(props) { colorScheme, } = props; - if (data.length <= 0) { + if (isNotDefined(data) || data.length <= 0) { return (
Nothings to show. diff --git a/client/src/views/Report/index.js b/client/src/views/Report/index.js index 4a08cc8..860a523 100644 --- a/client/src/views/Report/index.js +++ b/client/src/views/Report/index.js @@ -38,7 +38,7 @@ import { triColorScheme, } from './report-utils'; -import DonutChartReCharts from './DonutChart'; +import DonutChartReCharts from '../CommonCharts/DonutChart'; import HorizontalBarRecharts from './HorizontalBar'; import GroupedBarChartRecharts from './GroupedBarChart'; @@ -560,7 +560,7 @@ class Report extends PureComponent {