Skip to content

Commit 3d6f45e

Browse files
committed
added an error line to the wpm over time chart
1 parent e4c5bf6 commit 3d6f45e

1 file changed

Lines changed: 58 additions & 11 deletions

File tree

public/js/script.js

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ let pageTransition = false;
1414
let keypressPerSecond = [];
1515
let currentKeypressCount = 0;
1616
let afkDetected = false;
17+
let errorsPerSecond = [];
18+
let currentErrorCount = 0;
1719

1820
let accuracyStats = {
1921
correct: 0,
@@ -293,9 +295,11 @@ function hideCaret() {
293295
}
294296

295297
function showCaret() {
296-
updateCaretPosition();
297-
$("#caret").removeClass("hidden");
298-
startCaretAnimation();
298+
if($("#result").hasClass('hidden')){
299+
updateCaretPosition();
300+
$("#caret").removeClass("hidden");
301+
startCaretAnimation();
302+
}
299303
}
300304

301305
function stopCaretAnimation() {
@@ -545,12 +549,21 @@ function showResult() {
545549
let mainColor = getComputedStyle(document.body).getPropertyValue('--main-color').replace(' ', '');
546550
let subColor = getComputedStyle(document.body).getPropertyValue('--sub-color').replace(' ', '');
547551

548-
549552
wpmOverTimeChart.options.scales.xAxes[0].ticks.minor.fontColor = subColor;
553+
wpmOverTimeChart.options.scales.xAxes[0].scaleLabel.fontColor = subColor;
550554
wpmOverTimeChart.options.scales.yAxes[0].ticks.minor.fontColor = subColor;
555+
wpmOverTimeChart.options.scales.yAxes[1].ticks.minor.fontColor = subColor;
556+
wpmOverTimeChart.options.scales.yAxes[0].scaleLabel.fontColor = subColor;
557+
wpmOverTimeChart.options.scales.yAxes[1].scaleLabel.fontColor = subColor;
558+
559+
551560
wpmOverTimeChart.data.datasets[0].borderColor = mainColor;
552561
wpmOverTimeChart.data.labels = labels;
553562
wpmOverTimeChart.data.datasets[0].data = wpmHistory;
563+
wpmOverTimeChart.data.datasets[1].data = errorsPerSecond;
564+
565+
566+
554567
wpmOverTimeChart.update({ duration: 0 });
555568
swapElements($("#words"),$("#result"),250);
556569
}
@@ -559,12 +572,15 @@ function restartTest() {
559572
clearIntervals();
560573
time = 0;
561574
afkDetected = false;
562-
keypressPerSecond = [];
563575
wpmHistory = [];
564576
setFocus(false);
565577
hideCaret();
566578
testActive = false;
567579
hideLiveWpm();
580+
keypressPerSecond = [];
581+
currentKeypressCount = 0;
582+
errorsPerSecond = [];
583+
currentErrorCount = 0;
568584
currentTestLine = 0;
569585
let el = null;
570586
if($("#words").hasClass('hidden')){
@@ -981,6 +997,9 @@ $(document).keypress(function(event) {
981997
wpmHistory.push(wpm);
982998
keypressPerSecond.push(currentKeypressCount);
983999
currentKeypressCount = 0;
1000+
errorsPerSecond.push(currentErrorCount);
1001+
currentErrorCount = 0;
1002+
console.log(errorsPerSecond);
9841003
if(keypressPerSecond[time-1] == 0 && keypressPerSecond[time-2] == 0 && !afkDetected){
9851004
showNotification("AFK detected",3000);
9861005
afkDetected = true;
@@ -999,6 +1018,7 @@ $(document).keypress(function(event) {
9991018
}
10001019
if (wordsList[currentWordIndex].substring(currentInput.length, currentInput.length + 1) != event["key"]) {
10011020
accuracyStats.incorrect++;
1021+
currentErrorCount++;
10021022
} else {
10031023
accuracyStats.correct++;
10041024
}
@@ -1144,7 +1164,16 @@ let wpmOverTimeChart = new Chart(ctx, {
11441164
data: [],
11451165
// backgroundColor: 'rgba(255, 255, 255, 0.25)',
11461166
borderColor: 'rgba(125, 125, 125, 1)',
1147-
borderWidth: 2
1167+
borderWidth: 2,
1168+
yAxisID: "wpm"
1169+
},
1170+
{
1171+
label: "errors",
1172+
data: [],
1173+
// backgroundColor: 'rgba(255, 255, 255, 0.25)',
1174+
borderColor: 'rgba(255, 125, 125, 1)',
1175+
borderWidth: 2,
1176+
yAxisID: "error"
11481177
}],
11491178
},
11501179
options: {
@@ -1172,21 +1201,39 @@ let wpmOverTimeChart = new Chart(ctx, {
11721201
},
11731202
display: true,
11741203
scaleLabel: {
1175-
display: false,
1176-
labelString: 'Seconds'
1204+
display: true,
1205+
labelString: 'Seconds',
1206+
fontFamily: "Roboto Mono"
11771207
}
11781208
}],
11791209
yAxes: [{
1210+
id: "wpm",
11801211
display: true,
11811212
scaleLabel: {
1182-
display: false,
1183-
labelString: 'Words per Minute'
1213+
display: true,
1214+
labelString: 'Words per Minute',
1215+
fontFamily: 'Roboto Mono'
11841216
},
11851217
ticks: {
11861218
fontFamily: 'Roboto Mono',
11871219
beginAtZero: true
11881220
}
1189-
}]
1221+
},
1222+
{
1223+
id: "error",
1224+
display: true,
1225+
scaleLabel: {
1226+
display: true,
1227+
labelString: 'Errors',
1228+
fontFamily: 'Roboto Mono'
1229+
},
1230+
ticks: {
1231+
precision:0,
1232+
fontFamily: 'Roboto Mono',
1233+
beginAtZero: true
1234+
}
1235+
}
1236+
]
11901237
}
11911238
}
11921239
});

0 commit comments

Comments
 (0)