Skip to content

Commit 5b84fa5

Browse files
committed
Improve MCC charts
1 parent e74f9dd commit 5b84fa5

2 files changed

Lines changed: 51 additions & 18 deletions

File tree

mcc/src/client/U24Dashboard/Dashboard.tsx

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ActionURL, Filter, getServerContext, Query } from '@labkey/api';
55

66
import PieChart from '../components/dashboard/PieChart';
77
import BarChart from '../components/dashboard/BarChart';
8+
import { ActiveElement, Chart, ChartEvent } from 'chart.js/dist/types/index';
89

910
export function Dashboard() {
1011
const [demographics, setDemographics] = useState(null);
@@ -13,6 +14,8 @@ export function Dashboard() {
1314
const [availableForTransfer, setAvailableForTransfer] = useState(null);
1415
const [requestRows, setRequestRows] = useState(null);
1516
const [censusRows, setCensusRows] = useState(null);
17+
const [birthData, setBirthData ] = useState(null);
18+
const [breedingPairData, setBreedingPairData ] = useState(null);
1619

1720
const ctx = getServerContext().getModuleContext('mcc') || {};
1821
const containerPath = ctx.MCCContainer || null;
@@ -64,6 +67,7 @@ export function Dashboard() {
6467
containerPath: requestContainerPath,
6568
schemaName: 'mcc',
6669
queryName: 'requestScores',
70+
columns: 'requestId/status',
6771
success: function(results) {
6872
if (isApiSubscribed) {
6973
setRequestRows(results.rows);
@@ -86,6 +90,20 @@ export function Dashboard() {
8690
success: function(results) {
8791
if (isApiSubscribed) {
8892
setCensusRows(results.rows);
93+
94+
setBreedingPairData(results.rows.flatMap(row => {
95+
return Array(row.totalBreedingPairs).fill({
96+
yearNo: row.yearNo,
97+
centerName: row.centerName
98+
})
99+
}))
100+
101+
setBirthData(results.rows.flatMap(row => {
102+
return Array(row.totalLivingOffspring).fill({
103+
yearNo: row.yearNo,
104+
centerName: row.centerName
105+
})
106+
}))
89107
}
90108
},
91109
failure: function(response) {
@@ -110,8 +128,11 @@ export function Dashboard() {
110128
);
111129
}
112130

113-
console.log(censusRows)
114-
console.log(requestRows)
131+
const clickHandler = function(event: ChartEvent, elements: ActiveElement[], chart: Chart){
132+
console.log(event)
133+
console.log(elements)
134+
console.log(chart)
135+
}
115136

116137
return (
117138
<>
@@ -151,20 +172,37 @@ export function Dashboard() {
151172
</div>
152173
</div>
153174
<div className="row">
175+
<div className="col-md-4">
176+
<div className="panel panel-default">
177+
<div className="panel-heading">Request Summary</div>
178+
<div className="panel-body">
179+
<PieChart fieldName = "requestId/status" demographics={requestRows} />
180+
</div>
181+
</div>
182+
</div>
154183
<div className="col-md-4">
155184
<div className="panel panel-default">
156185
<div className="panel-heading">Age (Living Animals)</div>
157186
<div className="panel-body">
158-
<BarChart demographics={living} fieldName="Id/ageClass/label" groupField="gender/meaning" />
187+
<BarChart demographics={living} fieldName="Id/ageClass/label" groupField="gender/meaning" onClick={clickHandler} />
188+
</div>
189+
</div>
190+
</div>
191+
</div>
192+
<div className="row">
193+
<div className="col-md-4">
194+
<div className="panel panel-default">
195+
<div className="panel-heading">U24 Births By Year</div>
196+
<div className="panel-body">
197+
<BarChart demographics={birthData} fieldName="centerName" groupField="yearNo" indexAxis="x"/>
159198
</div>
160199
</div>
161200
</div>
162201
<div className="col-md-4">
163202
<div className="panel panel-default">
164-
<div className="panel-heading">Requests</div>
203+
<div className="panel-heading">U24 Breeding Pairs</div>
165204
<div className="panel-body">
166-
{/*<PieChart fieldName = "gender/meaning" demographics={living} />*/}
167-
PLACEHOLDER: Number of births over time, etc.
205+
<BarChart demographics={breedingPairData} fieldName="centerName" groupField="yearNo" indexAxis="x" />
168206
</div>
169207
</div>
170208
</div>

mcc/src/client/components/dashboard/BarChart.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import React, { useEffect, useRef } from 'react';
2-
import {
3-
Chart,
4-
Legend,
5-
BarController,
6-
BarElement,
7-
CategoryScale,
8-
LinearScale,
9-
Tooltip
10-
} from 'chart.js';
2+
import { BarController, BarElement, CategoryScale, Chart, Legend, LinearScale, Tooltip } from 'chart.js';
3+
import { ActiveElement, ChartEvent } from 'chart.js/dist/types/index';
114

125
Chart.register(Legend, BarController, BarElement, CategoryScale, LinearScale, Tooltip);
136

@@ -19,10 +12,11 @@ const colors = [
1912
'rgb(194, 192, 210)'
2013
];
2114

22-
export default function BarChart(props: {demographics: [], fieldName: string, groupField?: string}) {
15+
export default function BarChart(props: {demographics: [], fieldName: string, groupField?: string, indexAxis?: 'x' | 'y', onClick?: (event: ChartEvent, elements: ActiveElement[], chart: Chart) => void }) {
2316
const canvas = useRef(null);
2417

25-
const { demographics, fieldName, groupField } = props
18+
const { demographics, fieldName, groupField, onClick} = props
19+
const indexAxis: 'x' | 'y' = props.indexAxis || 'y'
2620

2721
const collectedData = demographics.reduce((acc, curr: {}, idx) => {
2822
const value = curr[fieldName] === null ? 'Unknown' : curr[fieldName];
@@ -59,9 +53,10 @@ export default function BarChart(props: {demographics: [], fieldName: string, gr
5953
datasets: dataArr
6054
},
6155
options: {
56+
onClick: onClick,
6257
responsive: true,
6358
aspectRatio: 2,
64-
indexAxis: 'y',
59+
indexAxis: indexAxis,
6560
scales: {
6661
x: {
6762
beginAtZero: true

0 commit comments

Comments
 (0)