From 6fe2197b595f2602c2545300dfd4bb78d7024502 Mon Sep 17 00:00:00 2001 From: Derek Chen Date: Tue, 1 Aug 2023 14:47:40 -0500 Subject: [PATCH] Separated chart generation into different functions for readability --- docs/main.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/main.js b/docs/main.js index edbe9e7..bdb5e8d 100644 --- a/docs/main.js +++ b/docs/main.js @@ -125,27 +125,23 @@ async function PapaParse(department, num, name, sem) { // console.log(selectedClass[i]["Count of letter grade"]); } console.log(gradeDist); - if (gradeChart) { - gradeChart.config.data = { - labels: gradeLabels, - datasets: [{ - label: '\"' + lableName + "\"", - data: Object.values(gradeDist), - borderWidth: 2, - backgroundColor: backgroundColor, - }] - }; - gradeChart.update(); - } else { - loadChart(gradeDist, lableName); - aboutDiv.style.visibility = 'hidden'; - aboutDiv.style.display = 'none'; - chartDiv.style.display = ''; - formDiv.setAttribute("style", "grid-row: 1"); - } + (gradeChart ? updateChart(lableName, gradeDist) : createChart(gradeDist, lableName)); } -function loadChart(gradeDist, courseName) { +function updateChart(labelName, gradeDist) { + gradeChart.config.data = { + labels: gradeLabels, + datasets: [{ + label: '\"' + labelName + "\"", + data: Object.values(gradeDist), + borderWidth: 2, + backgroundColor: backgroundColor, + }] + }; + gradeChart.update(); +} + +function createChart(gradeDist, courseName) { gradeChart = new Chart(ctx, { type: 'bar', data: { @@ -181,4 +177,8 @@ function loadChart(gradeDist, courseName) { } } }); + aboutDiv.style.visibility = 'hidden'; + aboutDiv.style.display = 'none'; + chartDiv.style.display = ''; + formDiv.setAttribute("style", "grid-row: 1"); } \ No newline at end of file