Separated chart generation into different functions for readability
This commit is contained in:
20
docs/main.js
20
docs/main.js
@@ -125,27 +125,23 @@ async function PapaParse(department, num, name, sem) {
|
|||||||
// console.log(selectedClass[i]["Count of letter grade"]);
|
// console.log(selectedClass[i]["Count of letter grade"]);
|
||||||
}
|
}
|
||||||
console.log(gradeDist);
|
console.log(gradeDist);
|
||||||
if (gradeChart) {
|
(gradeChart ? updateChart(lableName, gradeDist) : createChart(gradeDist, lableName));
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateChart(labelName, gradeDist) {
|
||||||
gradeChart.config.data = {
|
gradeChart.config.data = {
|
||||||
labels: gradeLabels,
|
labels: gradeLabels,
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: '\"' + lableName + "\"",
|
label: '\"' + labelName + "\"",
|
||||||
data: Object.values(gradeDist),
|
data: Object.values(gradeDist),
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
gradeChart.update();
|
gradeChart.update();
|
||||||
} else {
|
|
||||||
loadChart(gradeDist, lableName);
|
|
||||||
aboutDiv.style.visibility = 'hidden';
|
|
||||||
aboutDiv.style.display = 'none';
|
|
||||||
chartDiv.style.display = '';
|
|
||||||
formDiv.setAttribute("style", "grid-row: 1");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadChart(gradeDist, courseName) {
|
function createChart(gradeDist, courseName) {
|
||||||
gradeChart = new Chart(ctx, {
|
gradeChart = new Chart(ctx, {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: {
|
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");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user