Skip to content

Commit 7450ab6

Browse files
authored
Merge pull request #980 from thecourseforum/issue-652-mobile-pie-chart
Issue 652: Made fixes to pie chart, updated chart.js version
2 parents be9b65e + b930ac3 commit 7450ab6

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

doc/dev.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Run the following command in a POSIX-compliant shell (i.e. Windows users - use G
88

99
Replace `<install_dir>` with where you'd like to clone the script.
1010

11-
*TODO*: correct branch to main/dev when merged
11+
_TODO_: correct branch to main/dev when merged
1212

1313
```console
1414
curl -fL 'https://raw.githubusercontent.com/thecourseforum/theCourseForum2/refs/heads/master/scripts/setup.sh' | sh -s -- <install_dir>

tcf_website/static/course/course_professor.css

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@
5151
}
5252

5353
.chart-container {
54-
width: 90%;
55-
height: 90%;
5654
position: relative;
55+
margin-top: none;
56+
height: 80vh;
57+
width: 80vw;
5758
}
5859

5960
.chart-button {
@@ -129,6 +130,16 @@
129130
flex-direction: column;
130131
}
131132

133+
.top-center {
134+
position: absolute;
135+
top: 10px;
136+
left: auto;
137+
display: flex;
138+
align-items: center;
139+
justify-content: center;
140+
flex-direction: column;
141+
}
142+
132143
.gpa-text {
133144
color: #384676;
134145
font-size: 28px;
@@ -178,10 +189,6 @@
178189
}
179190

180191
@media (max-width: 1100px) {
181-
.chart-container {
182-
max-width: 600px;
183-
}
184-
185192
.grades-ratings-container {
186193
flex-direction: column;
187194
height: 650px;
@@ -252,9 +259,6 @@
252259
height: 50%;
253260
}
254261

255-
.chart-container {
256-
width: 175px;
257-
}
258262
.ratings-container {
259263
height: 50%;
260264
}

tcf_website/static/course/javascript/course_data.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function togglePieChart() {
88
if (myChart) {
99
myChart.destroy();
1010
}
11-
document.getElementById("canvas-parent").style.width = "290px";
11+
pieConfig.options.plugins.legend.display = false;
1212
// eslint-disable-next-line no-new,no-undef
1313
myChart = new Chart(ctx, pieConfig);
1414
}
@@ -17,7 +17,7 @@ function toggleBarChart() {
1717
if (myChart) {
1818
myChart.destroy();
1919
}
20-
document.getElementById("canvas-parent").style.width = "95%";
20+
barConfig.options.plugins.legend.display = false;
2121
// eslint-disable-next-line no-new,no-undef
2222
myChart = new Chart(ctx, barConfig);
2323
}
@@ -26,11 +26,13 @@ $(".pieToBar").click(function () {
2626
if (document.getElementById("toggle-btn").value === "bar") {
2727
toggleBarChart();
2828
document.getElementById("chart-label").className = "bottom-center";
29+
document.getElementById("grades-container").style.paddingBottom = "3em";
2930
document.getElementById("toggle-btn").innerHTML = "Pie";
3031
document.getElementById("toggle-btn").value = "pie";
3132
} else {
3233
togglePieChart();
3334
document.getElementById("chart-label").className = "absolute-center";
35+
document.getElementById("grades-container").style.paddingBottom = "0em";
3436
document.getElementById("toggle-btn").innerHTML = "Bar";
3537
document.getElementById("toggle-btn").value = "bar";
3638
}
@@ -176,9 +178,6 @@ const createChart = (gradesData) => {
176178
},
177179
},
178180
responsive: true,
179-
legend: {
180-
display: false,
181-
},
182181
scales: {
183182
xAxes: [
184183
{
@@ -206,6 +205,9 @@ const createChart = (gradesData) => {
206205
],
207206
},
208207
plugins: {
208+
legend: {
209+
display: false,
210+
},
209211
labels: {
210212
// render 'label', 'value', 'percentage', 'image' or custom function, default is 'percentage'
211213
render: "value",
@@ -242,12 +244,10 @@ const createChart = (gradesData) => {
242244

243245
// Generate configuration for Pie Chart
244246
pieConfig = {
245-
type: "pie",
247+
type: "doughnut",
246248
data: chartData,
247249
options: {
248-
cutoutPercentage: 65,
249-
responsive: true,
250-
aspectRatio: 1,
250+
maintainAspectRatio: false,
251251
tooltips: {
252252
callbacks: {
253253
label: function (tooltipItem, data) {
@@ -264,10 +264,10 @@ const createChart = (gradesData) => {
264264
},
265265
displayColors: false,
266266
},
267-
legend: {
268-
display: false,
269-
},
270267
plugins: {
268+
legend: {
269+
display: false,
270+
},
271271
labels: {
272272
// render 'label', 'value', 'percentage', 'image' or custom function, default is 'percentage'
273273
render: "label",

tcf_website/templates/course/course_professor.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{% block styles %}
77
<link rel="stylesheet" href="{% static 'course/course_professor.css' %}"/>
8-
<link rel="stylesheet" href="{% static 'icons/icons .css' %}"/>
8+
<link rel="stylesheet" href="{% static 'icons/icons.css' %}"/>
99
{% endblock %}
1010

1111
{% block content %}
@@ -184,10 +184,8 @@ <h2 class="mr-md-3">{{ course.title }}</h2>
184184
</div>
185185
</div>
186186
</div>
187-
<div class="grades-container">
188-
<div class="chart-container d-flex align-items-center justify-content-center">
189-
<div id="canvas-parent"><canvas id="myChart"></canvas></div>
190-
</div>
187+
<div id="grades-container" class="grades-container">
188+
<canvas id="myChart"></canvas>
191189
<div class="absolute-center" id="chart-label">
192190
<p class="gpa-text"> No grades found <i class="fa fa-frown-open fa-fw"></i></p>
193191
<p class="students-text"> &mdash; Students</p>
@@ -322,7 +320,7 @@ <h3 class="reviews-heading mb-0 mt-1 mr-4">{{ reviews|length }} {% if reviews|le
322320
</script>
323321

324322
<!-- For grade data -->
325-
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
323+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
326324
<script type="module"
327325
src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-labels/src/chartjs-plugin-labels.js"></script>
328326
<script type="module" src="{% static 'course/javascript/course_data.js' %}"></script>

0 commit comments

Comments
 (0)