Skip to content

Commit 0d78c2b

Browse files
Fix Graph Resizing!
- This is actually huge because I've always had an issue with these graphs resizing back down. But I found a way to do it! Fixes to my other apps incoming!
1 parent f7c2848 commit 0d78c2b

5 files changed

Lines changed: 17 additions & 24 deletions

File tree

src/graphAnnual.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,3 @@ function createAnnualHoursGraph() {
6363

6464
// Initial setup
6565
annualHoursGraph = createAnnualHoursGraph();
66-
67-
// Resize event listener
68-
window.addEventListener('resize', () => {
69-
annualHoursGraph.destroy();
70-
71-
annualHoursGraph = createAnnualHoursGraph();
72-
});

src/graphMonth.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,20 @@ function createChart() {
7070
// Initial setup
7171
monthHours = createChart();
7272

73-
// Resize event listener
7473
window.addEventListener('resize', () => {
75-
// Destroy the existing chart instance
76-
monthHours.destroy();
74+
// Destroy the existing chart instances for all canvases
75+
if (topicHoursGraph) {
76+
topicHoursGraph.destroy();
77+
}
78+
if (annualHoursGraph) {
79+
annualHoursGraph.destroy();
80+
}
81+
if (monthHours) {
82+
monthHours.destroy();
83+
}
7784

78-
// Recreate the chart with updated dimensions
85+
// Recreate the chart instances for all canvases with updated dimensions
86+
topicHoursGraph = createTopicHoursGraph();
87+
annualHoursGraph = createAnnualHoursGraph();
7988
monthHours = createChart();
80-
});
89+
});

src/graphTopics.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function createTopicHoursGraph() {
4343
}
4444
},
4545
maintainAspectRatio: false,
46-
responsive: false,
46+
responsive: true,
4747
scales: {
4848
y: {
4949
display: true, // Display y-axis
@@ -64,12 +64,3 @@ function createTopicHoursGraph() {
6464

6565
// Initial setup
6666
topicHoursGraph = createTopicHoursGraph();
67-
68-
// Resize event listener
69-
window.addEventListener('resize', () => {
70-
// Destroy the existing chart instance
71-
topicHoursGraph.destroy();
72-
73-
// Recreate the chart with updated dimensions
74-
topicHoursGraph = createTopicHoursGraph();
75-
});

src/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ h1,h2,h3,h4,h5,h6 {
217217

218218
.bottom-grid {
219219
display: grid;
220-
grid-template-columns: 1fr 1fr auto;
220+
grid-template-columns: 1fr 1fr 1fr;
221221
grid-gap: 5px;
222222
overflow: hidden;
223223
}

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ <h3>10.5</h3>
8787
</div>
8888
<div class="bottom-right-graphs">
8989
<div class="container">
90-
<canvas id="topicHoursGraph" style="width: 100%; height: auto;"></canvas>
90+
<canvas id="topicHoursGraph"></canvas>
9191
</div>
9292
<div class="container">
9393
<canvas id="annualHoursGraph"></canvas>

0 commit comments

Comments
 (0)