Skip to content

Commit 2ce1c81

Browse files
committed
2 parents 0110760 + 26c7c09 commit 2ce1c81

3 files changed

Lines changed: 22 additions & 47 deletions

File tree

notebookjs/src/public/javascripts/index.js

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ const editor = CodeMirror(document.getElementById('div-1'), {
66
value: ''
77
});
88

9-
/////PROTO///////////
109

10+
//Global Params
1111
let vars_in_scope = {
1212
"div-1": editor
1313
}
14+
1415
let __cells_count = 1
1516

1617
function exec_cell(c_id) {
1718
let id = c_id.split("_")[1]
1819
let count = c_id.split("-")[1]
20+
window.current_cell = id;
1921

2022
try {
2123
let global_scope = ("global", eval)(vars_in_scope[id].getValue())
@@ -26,36 +28,14 @@ function exec_cell(c_id) {
2628

2729
count = parseInt(count) + 1
2830
let div_count = `div-${count}`
29-
30-
// if (!(div_count in vars_in_scope)) {
31-
// // add_new_code_cell(id, 'down')
32-
// // $("#container").append(
33-
// // `<div id=${div_count} class=""></div><br />
34-
// // <button style="color: black;" id=run_${div_count} class="run">Run</button>
35-
// // <div id=out_${div_count}></div><br />`
36-
// // )
37-
38-
// // let editor = CodeMirror(document.getElementById(`${div_count}`), {
39-
// // lineNumbers: true,
40-
// // tabSize: 2,
41-
// // mode: 'javascript',
42-
// // theme: 'monokai',
43-
// // extraKeys: {"Ctrl-Space": "autocomplete"},
44-
// // value: ''
45-
// // });
46-
47-
// // // editor.setSize(10, 10);
48-
49-
// // vars_in_scope[div_count] = editor;
50-
51-
// }
31+
window.current_cell = div_count
5232

5333
} catch (error) {
5434
$(`#out_${id}`).html(error)
5535
}
56-
5736
}
5837

38+
5939
function add_new_code_cell(c_id, where) {
6040
__cells_count += 1
6141
let last_scope_id = parseInt(Object.keys(vars_in_scope).pop().split("-")[1])
@@ -119,20 +99,13 @@ function add_new_code_cell(c_id, where) {
11999
divReference.insertAdjacentHTML("afterend", html);
120100
}
121101

122-
123-
124-
125-
// $(`#${parent_cell_id}`).parentNode.append(html)
126-
127102
let editor = CodeMirror(document.getElementById(`div-${new_id}`), {
128103
lineNumbers: true,
129104
tabSize: 2,
130105
mode: 'javascript',
131106
theme: 'monokai',
132107
value: ''
133108
});
134-
135-
136109
vars_in_scope[`div-${new_id}`] = editor
137110

138111
}
@@ -143,43 +116,34 @@ function add_new_text_cell(id, count) {
143116
}
144117

145118
function delete_cell(id) {
146-
if (__cells_count == 1){
119+
if (__cells_count == 1) {
147120
document.getElementsByClassName("del").disable = true
148-
}else{
121+
} else {
149122
row_id = `cell-${Number(id)}`
150123
var div_ele = document.getElementById(row_id);
151124
div_ele.parentNode.removeChild(div_ele);
152125
__cells_count -= 1
153126
}
154-
155-
127+
128+
156129

157130
}
158131

159132
$(document).on("click", "button.run", function () {
160-
// let id = this.id.split("_")[1]
161-
// let count = this.id.split("-")[1]
162-
// console.log(id);
163-
// console.log(count);
164133
exec_cell(this.id);
165134
})
166135

167136
$(document).on("click", "button.del", function () {
168-
// let id = this.id.split("_")[1]
169137
let id = this.id.split("-")[1]
170138
delete_cell(id)
171139
})
172140

173141
$(document).on("click", "button.add-code", function () {
174-
// let last_cell_in_scope = parseInt(Object.keys(vars_in_scope).pop().split("-")[1])
175-
// let id = this.id.split("-")[1]
176-
177142
let where;
178143
if (this.id.split("_").includes("down")) {
179144
where = "down"
180145
} else {
181146
where = "up"
182147
}
183148
add_new_code_cell(this.id, where)
184-
// add_new_code_cell(id, last_cell_in_scope, where)
185149
})

notebookjs/src/public/javascripts/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,15 @@ function print_val(val){
7676
return data_string;
7777

7878
}
79+
}
80+
81+
function viz(name,callback){
82+
83+
let id = `#out_${window.current_cell}`
84+
$(`${id}`).append(`<div id=${name}></div>`)
85+
86+
let cb = callback(name);
87+
// $("#ploty").remove(`${name}`)
88+
89+
return cb
7990
}

notebookjs/src/views/index.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
</div>
4848
<div class="col-md-1"></div>
4949
<div id="out_div-1" class="col-md-10 out-divs">
50-
5150
</div>
52-
</div>
5351

52+
</div>
53+
<div id="ploty"></div>
5454
</div>
5555

5656

0 commit comments

Comments
 (0)