Skip to content

Commit f4a8e6a

Browse files
Script Name Change
1 parent 0d78c2b commit f4a8e6a

3 files changed

Lines changed: 70 additions & 4 deletions

File tree

src/graphMonth.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ monthHours = createChart();
7272

7373
window.addEventListener('resize', () => {
7474
// Destroy the existing chart instances for all canvases
75-
if (topicHoursGraph) {
76-
topicHoursGraph.destroy();
75+
if (weekCompareGraph) {
76+
weekCompareGraph.destroy();
7777
}
7878
if (annualHoursGraph) {
7979
annualHoursGraph.destroy();
@@ -83,7 +83,7 @@ window.addEventListener('resize', () => {
8383
}
8484

8585
// Recreate the chart instances for all canvases with updated dimensions
86-
topicHoursGraph = createTopicHoursGraph();
86+
weekCompareGraph = createWeekCompare();
8787
annualHoursGraph = createAnnualHoursGraph();
8888
monthHours = createChart();
8989
});

src/graphWeekCompare.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const topicHoursGraph_el = document.getElementById('topicHoursGraph');
2+
const ctxTopicHours = topicHoursGraph_el.getContext('2d');
3+
let weekCompareGraph; // Variable to store the chart instance
4+
5+
function getRandomNumber(min, max) {
6+
return (Math.random() * (max - min) + min).toFixed(1);
7+
}
8+
9+
function createWeekCompare() {
10+
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
11+
const previousWeekHours = days.map(() => getRandomNumber(0.5, 8));
12+
const currentWeekHours = days.map(() => getRandomNumber(0.5, 8));
13+
14+
return new Chart(ctxTopicHours, {
15+
type: 'line',
16+
data: {
17+
labels: days,
18+
datasets: [{
19+
label: 'Previous Week',
20+
data: previousWeekHours,
21+
borderColor: 'rgba(169, 169, 169, 0.1)',
22+
backgroundColor: 'rgba(255, 99, 132, 0)',
23+
borderWidth: 2,
24+
fill: false // No fill under the line
25+
},
26+
{
27+
label: 'Current Week',
28+
data: currentWeekHours,
29+
borderColor: 'rgba(54, 162, 235, 1)',
30+
backgroundColor: 'rgba(54, 162, 235, 0)',
31+
borderWidth: 2,
32+
fill: false // No fill under the line
33+
}]
34+
},
35+
options: {
36+
plugins: {
37+
title: {
38+
display: true,
39+
text: 'Weekly Hours Comparison',
40+
},
41+
legend: {
42+
display: false // Hide legend
43+
}
44+
},
45+
maintainAspectRatio: false,
46+
responsive: true,
47+
scales: {
48+
y: {
49+
display: true, // Display y-axis
50+
ticks: {
51+
stepSize: 1, // Step size for y-axis ticks
52+
font: {
53+
size: 12 // Adjust font size for y-axis ticks
54+
}
55+
}
56+
},
57+
x: {
58+
display: false // Hide x-axis
59+
}
60+
}
61+
}
62+
});
63+
}
64+
65+
// Initial setup
66+
weekCompareGraph = createWeekCompare();

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ <h3>10.5</h3>
9999
<script src="frame.js"></script>
100100
<script src="graphMonth.js"></script>
101101
<script src="graphAnnual.js"></script>
102-
<script src="graphTopics.js"></script>
102+
<script src="graphWeekCompare.js"></script>
103103
</body>
104104
</html>

0 commit comments

Comments
 (0)