Skip to content
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

Hotfix #357

Merged
merged 2 commits into from
Apr 17, 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
33 changes: 28 additions & 5 deletions components/BarChart.js → components/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import HighchartsReact from 'highcharts-react-official'



const BarChart = props => {
function Chart(props){

const options = {
chart: {
type: 'column',
backgroundColor: "#eff6ff"
type: props?.type,
backgroundColor: "#f9fafb" // "#eff6ff"
},
title: {
text: props.title || ''
Expand Down Expand Up @@ -43,7 +43,30 @@ const BarChart = props => {
dataLabels: {
enabled: true
}
}
},
// series: {
// allowPointSelect: true,
// cursor: 'pointer',
// dataLabels: [{
// enabled: true,
// distance: 20
// }, {
// enabled: true,
// distance: -40,
// format: '{point.percentage:.1f}%',
// style: {
// fontSize: '1.2em',
// textOutline: 'none',
// opacity: 0.7
// },
// filter: {
// operator: '>',
// property: '',
// value: 10
// }
// }]
// }

},
legend: {
layout: 'vertical',
Expand Down Expand Up @@ -80,4 +103,4 @@ const BarChart = props => {
);
};

export default BarChart;
export default Chart;
94 changes: 80 additions & 14 deletions pages/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import MainLayout from '../../components/MainLayout'
import { checkToken } from '../../controllers/auth/auth'
import React, { useState, useEffect, useMemo, useRef, useContext } from 'react'
import { useRouter } from 'next/router'
import BarChart from '../../components/BarChart'
import Chart from '../../components/Chart'
import Select from 'react-select'
import { UserContext } from '../../providers/user'
import Link from 'next/link'
Expand Down Expand Up @@ -775,7 +775,23 @@ function Dashboard(props) {
{/* <div id="dashboard" className="w-full grid grid-cols-6 gap-4 px-1 md:px-4 py-2 my-4"> */}
<div className="card col-span-6 md:col-span-2 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-4 font-semibold text-gray-900">Facility owners </h4>
<table className="w-full text-sm md:text-base p-2">
<Chart
title=""
categories={Array?.from(props?.data?.owner_types ?? [], cs => cs.name) || []}
tooltipsuffix="#"
xaxistitle="Owner Type"
yaxistitle="count"
type="pie"
data={(() => {
let data = [];
data?.push({
name: 'Facilities',
data: Array.from(props?.data?.owner_types ?? [], cs => ({ name: cs.name, y: parseFloat(cs.count)})) || []
});
return data;
})() || []} />

{/* <table className="w-full text-sm md:text-base p-2">
<thead className="border-b border-gray-300">
<tr>
<th className="text-left text-gray-800 p-2 text-sm uppercase">Metric</th>
Expand All @@ -790,12 +806,27 @@ function Dashboard(props) {
</tr>
))}
</tbody>
</table>
</table> */}
</div>

<div className="card col-span-6 md:col-span-2 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-4 font-semibold text-gray-900">Facility Types </h4>
<table className="w-full text-sm md:text-base p-2">
<Chart
title=""
categories={Array?.from(props?.data?.types_summary ?? [], cs => cs.name) || []}
tooltipsuffix="#"
xaxistitle="Facility Type"
yaxistitle="count"
type="bar"
data={(() => {
let data = [];
data?.push({
name: 'Facilities',
data: Array.from(props?.data?.types_summary ?? [], cs => ({ name: cs.name, y: parseFloat(cs.count)})) || []
});
return data;
})() || []} />
{/* <table className="w-full text-sm md:text-base p-2">
<thead className="border-b border-gray-300">
<tr>
<th className="text-left text-gray-800 p-2 text-sm uppercase">Metric</th>
Expand All @@ -810,13 +841,28 @@ function Dashboard(props) {
</tr>
))}
</tbody>
</table>
</table> */}
</div>

{/* Facilities summary 1/3 - FILTERABLE */}
<div className="card col-span-6 md:col-span-2 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-4 font-semibold text-gray-900">Facilities summary</h4>
<table className="w-full text-sm md:text-base p-2">
<Chart
title=""
categories={Array?.from(totalSummary ?? [], cs => cs.name) || []}
tooltipsuffix="#"
xaxistitle="Facility Summaries"
yaxistitle="count"
type="bar"
data={(() => {
let data = [];
data?.push({
name: 'Facilities',
data: Array.from(totalSummary ?? [], cs => ({ name: cs.name, y: parseFloat(cs.count)})) || []
});
return data;
})() || []} />
{/* <table className="w-full text-sm md:text-base p-2">
<thead className="border-b border-gray-300">
<tr>
<th className="text-left text-gray-800 p-2 text-sm uppercase">Metric</th>
Expand All @@ -831,7 +877,7 @@ function Dashboard(props) {
</tr>
))}
</tbody>
</table>
</table> */}
</div>
{/* CUs summary - FILTERABLE 1/3 */}
<div className="card col-span-6 md:col-span-2 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
Expand Down Expand Up @@ -876,7 +922,22 @@ function Dashboard(props) {
{/* facilities by keph level */}
<div className="card col-span-6 md:col-span-2 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-4 font-semibold text-gray-900">Facility KEPH Level </h4>
<table className="w-full text-sm md:text-base p-2">
<Chart
title=""
categories={Array?.from(props?.data?.keph_level ?? [], cs => cs.name) || []}
tooltipsuffix="#"
xaxistitle=""
yaxistitle=""
type="pie"
data={(() => {
let data = [];
data?.push({
name: 'Facilities',
data: Array.from(props?.data?.keph_level ?? [], cs => ({ name: cs.name, y: parseFloat(cs.count)})) || []
});
return data;
})() || []} />
{/* <table className="w-full text-sm md:text-base p-2">
<thead className="border-b border-gray-300">
<tr>
<th className="text-left text-gray-800 p-2 text-sm uppercase">Metric</th>
Expand All @@ -891,18 +952,19 @@ function Dashboard(props) {
</tr>
))}
</tbody>
</table>
</table> */}
</div>
{/* Facilities & CHUs by county (bar) 1/1 */}
{(groupID === 7 || groupID === 5) &&
<div className="no-print col-span-6 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 border-b text-center border-gray-100 w-full mb-2 font-semibold text-gray-900">Facilities &amp; CHUs by County</h4>
<BarChart
<Chart
title=""
categories={Array?.from(props?.data?.county_summary ?? [], cs => cs.name) || []}
tooltipsuffix="#"
xaxistitle="County"
yaxistitle="Number"
type="bar"
data={(() => {
let data = [];
data?.push({
Expand All @@ -921,12 +983,13 @@ function Dashboard(props) {
{groupID === 1 &&
<div className="no-print col-span-6 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-2 font-semibold text-gray-900">Facilities &amp; CHUs by Subcounty</h4>
<BarChart
<Chart
title=""
categories={Array?.from(props?.data?.constituencies_summary ?? [], cs => cs.name) || []}
tooltipsuffix="#"
xaxistitle="Subcounty"
yaxistitle="Number"
type="column"
data={(() => {
let data = [];
data?.push({
Expand All @@ -945,12 +1008,13 @@ function Dashboard(props) {
{groupID === 2 &&
<div className="no-print col-span-6 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-2 font-semibold text-gray-900">Facilities &amp; CHUs by Ward</h4>
<BarChart
<Chart
title=""
categories={Array?.from(props?.data?.wards_summary ?? [], cs => cs.name) || []}
tooltipsuffix="#"
xaxistitle="Ward"
yaxistitle="Number"
type="bar"
data={(() => {
let data = [];
data?.push({
Expand All @@ -968,25 +1032,27 @@ function Dashboard(props) {
{/* Facility owners & categories - national summary - FILTERABLE (bar) 1/2 */}
<div className="no-print col-span-6 md:col-span-3 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-2 font-semibold text-gray-900">Facility owners</h4>
<BarChart
<Chart
title=""
categories={Array.from(props?.data?.owner_types ?? [], ot => ot.name) || []}
tooltipsuffix="#"
xaxistitle="Owner"
yaxistitle="Number"
type="column"
data={(() => {
return [{ name: "Owner", data: Array.from(props?.data?.owner_types ?? [], ot => parseFloat(ot.count)) || [] }];
})() || []} />
</div>
{/* Facility types - national summary - FILTERABLE (bar) 1/2 */}
<div className="no-print col-span-6 md:col-span-3 flex flex-col items-start justify-start p-3 shadow-lg border border-gray-300/70 bg-gray-50" style={{ minHeight: '250px' }}>
<h4 className="text-lg uppercase pt-4 text-center border-b border-gray-100 w-full mb-2 font-semibold text-gray-900">Facility types</h4>
<BarChart
<Chart
title=""
categories={Array.from(props?.data?.types_summary ?? [], ts => ts.name) || []}
tooltipsuffix="#"
xaxistitle="Type"
yaxistitle="Number"
type="column"
data={(() => {
return [{ name: "Type", data: Array.from(props?.data?.types_summary ?? [], ts => parseFloat(ts.count)) || [] }];
})() || []} />
Expand Down
Loading