Skip to content

Commit 013a6b8

Browse files
committed
update
1 parent 1d517a2 commit 013a6b8

File tree

2 files changed

+63
-116
lines changed

2 files changed

+63
-116
lines changed

modules/statistics/js/WidgetIndex.js

Lines changed: 24 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/statistics/jsx/widgets/chartBuilder.js

Lines changed: 39 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
/* eslint-disable */
2+
3+
let scanLineChart;
4+
let recruitmentPieChart;
5+
let recruitmentBarChart;
6+
let recruitmentLineChart;
7+
28
/**
39
* process - the chartBuilding for the widgets.
410
*/
@@ -15,10 +21,6 @@ function process() {
1521
// AJAX to get bar chart data
1622
const apiRecruitmentBarData =
1723
`${baseURL}/statistics/charts/siterecruitment_bysex`;
18-
let scanLineChart;
19-
let recruitmentPieChart;
20-
let recruitmentBarChart;
21-
let recruitmentLineChart;
2224

2325
// Colours for all charts broken down by only by site
2426
const siteColours = [
@@ -33,37 +35,6 @@ function process() {
3335
// male and female registered candidates
3436
$('.progress-bar').tooltip();
3537

36-
// Open the appropriate charts from the "views" dropdown menus
37-
$('.dropdown-menu a').click(function() {
38-
$(this).parent().siblings().removeClass('active');
39-
$(this).parent().addClass('active');
40-
$($(this).parent().siblings().children('a')).each(function() {
41-
$(document.getElementById(
42-
this.getAttribute('data-target'))
43-
).addClass('hidden');
44-
});
45-
$(document.getElementById(
46-
this.getAttribute('data-target'))
47-
).removeClass('hidden');
48-
49-
/* Make sure the chart variables are defined before resizing
50-
* They may not be defined on initial page load because
51-
* they are created through an AJAX request.
52-
*/
53-
if (typeof recruitmentPieChart !== 'undefined') {
54-
recruitmentPieChart.resize();
55-
}
56-
if (typeof recruitmentBarChart !== 'undefined') {
57-
recruitmentBarChart.resize();
58-
}
59-
if (typeof recruitmentLineChart !== 'undefined') {
60-
recruitmentLineChart.resize();
61-
}
62-
if (typeof scanLineChart !== 'undefined') {
63-
scanLineChart.resize();
64-
}
65-
});
66-
6738
$('.new-scans').click(function(e) {
6839
e.preventDefault();
6940
applyFilter('imaging_browser', {'Pending': 'PN'});
@@ -152,19 +123,19 @@ function process() {
152123
}
153124
}
154125
processedData.push(labels);
155-
for (const i in data.datasets) {
156-
if (data.datasets.hasOwnProperty(i)) {
126+
for (const i in data['datasets']) {
127+
if (data['datasets'].hasOwnProperty(i)) {
157128
const dataset = [];
158-
dataset.push(data.datasets[i].name);
159-
processedData.push(dataset.concat(data.datasets[i].data));
129+
dataset.push(data['datasets'][i].name);
130+
processedData.push(dataset.concat(data['datasets'][i].data));
160131
}
161132
}
162133
const totals = [];
163134
totals.push('Total');
164-
for (let j=0; j<data.datasets[0].data.length; j++){
135+
for (let j=0; j<data['datasets'][0].data.length; j++){
165136
let total = 0;
166-
for (let i=0; i<data.datasets.length; i++){
167-
total += parseInt(data.datasets[i].data[j]);
137+
for (let i=0; i<data['datasets'].length; i++){
138+
total += parseInt(data['datasets'][i].data[j]);
168139
}
169140
totals.push(total);
170141
}
@@ -179,9 +150,9 @@ function process() {
179150
*/
180151
function maxY(data){
181152
let maxi = 0;
182-
for(let j=0; j < data.datasets[0].data.length; j++){
183-
for(let i=0; i<data.datasets.length; i++){
184-
maxi = Math.max(maxi,parseInt(data.datasets[i].data[j]));
153+
for(let j=0; j < data['datasets'][0].data.length; j++){
154+
for(let i=0; i<data['datasets'].length; i++){
155+
maxi = Math.max(maxi, parseInt(data.datasets[i].data[j]));
185156
}
186157
}
187158
return maxi;
@@ -197,8 +168,8 @@ function process() {
197168
.then(
198169
(data) => {
199170
let legendNames = [];
200-
for (let j=0; j < data.datasets.length; j++) {
201-
legendNames.push(data.datasets[j].name);
171+
for (let j=0; j < data['datasets'].length; j++) {
172+
legendNames.push(data['datasets'][j].name);
202173
}
203174
const scanLineData = formatLineData(data);
204175
scanLineChart = c3.generate({
@@ -260,10 +231,10 @@ function process() {
260231
$(this).toggleClass('c3-legend-item-hidden')
261232
scanLineChart.toggle(id);
262233
});
263-
})
264-
.catch((error) => {
265-
console.error(error);
266-
});
234+
scanLineChart.resize();
235+
}).catch((error) => {
236+
console.error(error);
237+
});
267238

268239
// AJAX to get pie chart data
269240
fetch(
@@ -285,10 +256,10 @@ function process() {
285256
pattern: siteColours,
286257
},
287258
});
288-
})
289-
.catch((error) => {
290-
console.error(error);
291-
});
259+
recruitmentPieChart.resize();
260+
}).catch((error) => {
261+
console.error(error);
262+
});
292263

293264
// AJAX to get bar chart data
294265
fetch(
@@ -320,10 +291,10 @@ function process() {
320291
pattern: sexColours,
321292
},
322293
});
323-
})
324-
.catch((error) => {
325-
console.error(error);
326-
});
294+
recruitmentBarChart.resize();
295+
}).catch((error) => {
296+
console.error(error);
297+
});
327298

328299
// AJAX to get recruitment line chart data
329300
fetch(
@@ -335,8 +306,8 @@ function process() {
335306
.then(
336307
(data) => {
337308
let legendNames = [];
338-
for (let j=0; j < data.datasets.length; j++) {
339-
legendNames.push(data.datasets[j].name);
309+
for (let j=0; j < data['datasets'].length; j++) {
310+
legendNames.push(data['datasets'][j].name);
340311
}
341312
const recruitmentLineData = formatLineData(data);
342313
recruitmentLineChart = c3.generate({
@@ -384,7 +355,8 @@ function process() {
384355
return '<span></span>' + id;
385356
})
386357
.each(function(id) {
387-
d3.select(this).select('span').style('background-color',
358+
d3.select(this).select('span').style(
359+
'background-color',
388360
recruitmentLineChart.color(id));
389361
})
390362
.on('mouseover', function(id) {
@@ -394,13 +366,13 @@ function process() {
394366
recruitmentLineChart.revert();
395367
})
396368
.on('click', function(id) {
397-
$(this).toggleClass('c3-legend-item-hidden')
369+
$(this).toggleClass('c3-legend-item-hidden');
398370
recruitmentLineChart.toggle(id);
399371
});
400-
})
401-
.catch((error) => {
402-
console.error(error);
403-
});
372+
recruitmentLineChart.resize();
373+
}).catch((error) => {
374+
console.error(error);
375+
});
404376
}
405377

406378
export {

0 commit comments

Comments
 (0)