-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (51 loc) · 1.35 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
$(document).ready(_ => {
const resultsChartCanvas = $('#resultsChart');
const resultsChart = new Chart(resultsChartCanvas, {
type: 'line',
data: {
datasets: [{
label: 'Results',
borderColor: '#34B7E3',
data: []
}]
},
options: {
scales: {
xAxes: [{
type: 'linear',
position: 'bottom'
}]
}
}
});
let results = [];
updateGraph();
const doneTypingInterval = 500; //time in ms (5 seconds)
let typingTimer; //timer identifier
//on keyup, start the countdown
$('#testCode textarea').keyup(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(updateGraph, doneTypingInterval);
});
$('#testParameters textarea').keyup(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(updateGraph, doneTypingInterval);
});
//when the code changes re-evaluate it
function updateGraph() {
$('#errors h1').empty();
const testCodeString = $('#testCode textarea').val();
const funcToTest = eval(testCodeString);
const parameterString = '{' + $('#testParameters textarea').val().split('\n').join(',') + '}';
const parameters = JSON.parse(parameterString);
let results;
try {
results = test(funcToTest, parameters);
} catch (error) {
$('#errors h1').html(error);
}
resultsChart.data.datasets[0].data = results;
resultsChart.update();
}
});