forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_interval.js
More file actions
52 lines (41 loc) · 1.2 KB
/
setup_interval.js
File metadata and controls
52 lines (41 loc) · 1.2 KB
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
'use strict';
const app = require('../../app');
const Toast = require('../toast');
const {
parseFloat
} = Number;
const minInterval = 0.1;
const maxInterval = 10;
const startInterval = 0.5;
const stepInterval = 0.1;
const normalize = (sec) => {
let interval;
let message;
if (sec < minInterval) {
interval = minInterval;
message = `Interval of ${sec} seconds is too low. Setting to min allowed interval of ${minInterval} second(s).`;
} else if (sec > maxInterval) {
interval = maxInterval;
message = `Interval of ${sec} seconds is too high. Setting to max allowed interval of ${maxInterval} second(s).`;
} else {
interval = sec;
message = `Interval has been set to ${sec} second(s).`
}
return [interval, message];
};
module.exports = () => {
const $interval = $('#interval');
$interval.val(startInterval);
$interval.attr({
max: maxInterval,
min: minInterval,
step: stepInterval
});
$('#interval').on('change', function() {
const tracerManager = app.getTracerManager();
const [seconds, message] = normalize(parseFloat($(this).val()));
$(this).val(seconds);
tracerManager.interval = seconds * 1000;
Toast.showInfoToast(message);
});
};