2022-05-15 22:28:42 +02:00
|
|
|
const DURATION = 750;
|
2022-05-07 16:54:28 +02:00
|
|
|
|
2022-05-15 17:53:12 +02:00
|
|
|
class Record {
|
|
|
|
constructor(tree, message) {
|
|
|
|
this.tree = tree;
|
|
|
|
this.message = message;
|
|
|
|
}
|
|
|
|
|
|
|
|
render(graph, textBox) {
|
|
|
|
graph.renderDot(this.tree);
|
|
|
|
if (textBox) {
|
|
|
|
textBox.textContent = this.message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-07 16:54:28 +02:00
|
|
|
class Recorder {
|
2022-05-15 17:53:12 +02:00
|
|
|
constructor(graph, textBox, id) {
|
2022-05-07 16:54:28 +02:00
|
|
|
this.graph = graph;
|
2022-05-15 17:53:12 +02:00
|
|
|
this.textBox = textBox;
|
2022-05-07 16:54:28 +02:00
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
this.atOnce = false;
|
|
|
|
|
2022-05-15 22:47:07 +02:00
|
|
|
this.clear();
|
2022-05-07 16:54:28 +02:00
|
|
|
this.initGraph();
|
|
|
|
}
|
|
|
|
|
2022-05-15 22:47:07 +02:00
|
|
|
clear() {
|
|
|
|
this.rendered = -1;
|
|
|
|
this.rendering = false;
|
|
|
|
this.states = new Array();
|
|
|
|
}
|
|
|
|
|
2022-05-07 16:54:28 +02:00
|
|
|
renderAtOnce() {
|
|
|
|
this.atOnce = true;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
unblockRendering() {
|
|
|
|
this.rendering = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
initGraph() {
|
|
|
|
this.graph.transition(() =>
|
|
|
|
d3
|
|
|
|
.transition("main")
|
|
|
|
.ease(d3.easeLinear)
|
|
|
|
.on("end", this.unblockRendering.bind(this))
|
|
|
|
.delay(500)
|
|
|
|
.duration(DURATION)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.atOnce) {
|
|
|
|
if (this.rendered != this.states.length - 1) {
|
|
|
|
this.rendered = this.states.length - 1;
|
2022-05-15 17:53:12 +02:00
|
|
|
this.states[this.rendered].render(this.graph, this.textBox);
|
2022-05-07 16:54:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.rendering ||
|
|
|
|
!this.states ||
|
|
|
|
this.rendered == this.states.length - 1
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.rendering = true;
|
|
|
|
|
|
|
|
this.rendered++;
|
2022-05-15 17:53:12 +02:00
|
|
|
this.states[this.rendered].render(this.graph, this.textBox);
|
2022-05-07 16:54:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
previous() {
|
|
|
|
throw "not implemented!";
|
|
|
|
}
|
|
|
|
|
|
|
|
next() {
|
|
|
|
throw "not implemented!";
|
|
|
|
}
|
|
|
|
|
2022-05-16 18:36:31 +02:00
|
|
|
record(tree, message, ...highlightedNodes) {
|
2022-05-07 16:54:28 +02:00
|
|
|
// TODO: adjust join if necessary
|
2022-05-15 22:28:42 +02:00
|
|
|
this.states.push(
|
2022-05-16 18:36:31 +02:00
|
|
|
new Record(tree.toDot(...highlightedNodes).join(""), message)
|
2022-05-15 22:28:42 +02:00
|
|
|
);
|
2022-05-07 16:54:28 +02:00
|
|
|
this.render();
|
|
|
|
}
|
|
|
|
}
|