forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.js
More file actions
58 lines (45 loc) · 1012 Bytes
/
log.js
File metadata and controls
58 lines (45 loc) · 1012 Bytes
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
'use strict';
const Tracer = require('./tracer');
class LogTracer extends Tracer {
static getClassName() {
return 'LogTracer';
}
constructor(name) {
super(name);
if (this.isNew) initView(this);
}
_print(msg) {
this.manager.pushStep(this.capsule, {
type: 'print',
msg: msg
});
return this;
}
processStep(step, options) {
switch (step.type) {
case 'print':
this.print(step.msg);
break;
}
}
refresh() {
this.scrollToEnd(Math.min(50, this.interval));
}
clear() {
super.clear();
this.$wrapper.empty();
}
print(message) {
this.$wrapper.append($('<span>').append(message + '<br/>'));
}
scrollToEnd(duration) {
this.$container.animate({
scrollTop: this.$container[0].scrollHeight
}, duration);
}
}
const initView = (tracer) => {
tracer.$wrapper = tracer.capsule.$wrapper = $('<div class="wrapper">');
tracer.$container.append(tracer.$wrapper);
};
module.exports = LogTracer;