MOBILE-4270 feedback: Avoid division by zero on doughnut charts

main
Pau Ferrer Ocaña 2023-05-11 12:41:59 +02:00
parent 96a121f3db
commit 8113ea5f29
1 changed files with 4 additions and 3 deletions

View File

@ -334,15 +334,16 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
return label;
});
item.chartData = parsedData.map((dataItem) => <number> dataItem.answercount);
item.chartData = parsedData.map((dataItem) => Number(dataItem.answercount));
if (item.typ == 'multichoicerated') {
if (item.typ === 'multichoicerated') {
item.average = parsedData.reduce((prev, current) => prev + Number(current.avg), 0.0);
}
const subtype = item.presentation.charAt(0);
const single = subtype != 'c';
// Display bar chart if there are no answers to avoid division by 0 error.
const single = subtype !== 'c' && item.chartData.some((count) => count > 0);
item.chartType = single ? 'doughnut' : 'bar';
item.templateName = 'chart';
break;