summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorDougal Maclaurin <dougalm@google.com>2019-10-02 16:57:03 -0400
committerDougal Maclaurin <dougalm@google.com>2019-10-02 16:57:03 -0400
commit1d0cfdaf65ca93bb0ee0bb2da98ab11e7d33282c (patch)
tree3e4c9e179c0628855a311a57622dcce76e9d869f /static
parent7012a3784ac1fe25af4e0f678223311728bdc6d7 (diff)
Fix bug in notebook to do with duplicate cells
Diffstat (limited to 'static')
-rw-r--r--static/dynamic.js32
1 files changed, 22 insertions, 10 deletions
diff --git a/static/dynamic.js b/static/dynamic.js
index 4d72acac..87dd0b1c 100644
--- a/static/dynamic.js
+++ b/static/dynamic.js
@@ -3,17 +3,18 @@ var cells = {};
function append_contents(key, contents) {
if (key in cells) {
- var cell = cells[key];
+ var cur_cells = cells[key];
} else {
var cell = document.createElement("div");
cell.className = "cell";
- cells[key] = cell;
+ cells[key] = [cell];
+ var cur_cells = [cell];
}
-
for (var i = 0; i < contents.length; i++) {
- var node = lookup_address(cell, contents[i][0])
- node.innerHTML += contents[i][1];
- console.log(node);
+ for (var j = 0; j < cur_cells.length; j++) {
+ var node = lookup_address(cur_cells[j], contents[i][0])
+ node.innerHTML += contents[i][1];
+ }
}
}
@@ -28,20 +29,31 @@ function lookup_address(cell, address) {
var source = new EventSource("/getnext");
source.onmessage = function(event) {
var msg = JSON.parse(event.data);
- console.log(msg);
var order = msg[0];
var contents = msg[1];
for (var i = 0; i < contents.length; i++) {
append_contents(contents[i][0], contents[i][1]);
}
- // TODO: keys may appear twice, but they'll only show up once (html doesn't
- // allow repeated nodes). We need to make copies and keep them in sync.
if (order != null) {
+ var new_cells = {};
var body = document.getElementById("main-output");
body.innerHTML = "";
for (var i = 0; i < order.val.length; i++) {
- body.appendChild(cells[order.val[i]]);
+ var key = order.val[i]
+ var cur_cells = cells[key]
+ if (cur_cells.length == 0) {
+ var cur_cell = new_cells[key][0].cloneNode(true)
+ } else {
+ var cur_cell = cur_cells.pop()
+ if (key in new_cells) {
+ new_cells[key].push(cur_cell);
+ } else {
+ new_cells[key] = [cur_cell];
+ }
+ }
+ body.appendChild(cur_cell);
}
+ Object.assign(cells, new_cells);
}
render_plots();
};