Skip to content

Commit 7b4889e

Browse files
committed
2 parents ddcd780 + 82abee1 commit 7b4889e

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

notebookjs/src/public/javascripts/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ function exec_cell(c_id) {
6464

6565
try {
6666
let output = ("global", eval)(vars_in_scope[id].getValue())
67-
67+
let command = vars_in_scope[id].getValue()
6868
if (Array.isArray(output)) {
6969
output = print_val(output)
7070
} else if (typeof output === 'object' && output !== null) {
7171
output = JSON.stringify(output)
7272
if (output == "{}") {
7373
output = ""
7474
}
75-
} else if (console) {
76-
// retreive value from the console funcction
75+
} else if (command.includes("console.log(")) {
76+
//retreive value from the console funcction
7777
console.oldLog = console.log;
7878
console.log = function (value) {
7979
return value;
@@ -94,12 +94,11 @@ function exec_cell(c_id) {
9494
}
9595

9696
// $(`#out_${id}`).empty()
97-
let command = vars_in_scope[id].getValue()
98-
// console.log(command);
99-
if (command.includes("table") || command.includes("plot") || command.includes("console.log(")) {
100-
$(`#out_${id}`).html("")
101-
$(`#out_${id}`).html(output);
102-
}
97+
// let command = vars_in_scope[id].getValue()
98+
if (command.includes("table") || command.includes("plot") || command.includes("console.log(")){
99+
// $(`#out_${id}`).html("")
100+
$(`#out_${id}`).html(output);
101+
}
103102
// document.getElementById("cell_spinner-1").style.display = "none"
104103
// document.getElementById("cell_num-1").style.display = "block"
105104

notebookjs/src/public/javascripts/utils.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
function print_val(val) {
3+
/// Neeed refactoring. Lot of duplicated line of code
34

45
if (Array.isArray(val[0])) {
56

6-
let col_length = val[0].length;
7+
78
let row_length = val.length;
89

910
let data_string = "[";
@@ -12,21 +13,21 @@ function print_val(val) {
1213
for (let i = 0; i < 10; i++) {
1314

1415
let row_val = val[i]
15-
16+
let col_length = row_val.length;
1617
data_string += "[";
1718
if (col_length > 10) {
1819

1920
for (let j = 0; j < 10; j++) {
20-
data_string += `${row_val[j]},`
21+
data_string += j== 9 ? `${row_val[j]}`:`${row_val[j]},`
2122
}
2223

2324
data_string += `.......${col_length - 10} more],`
2425
} else {
2526

2627
for (let j = 0; j < col_length; j++) {
27-
data_string += `${row_val[j]},`
28+
data_string += j== (col_length-1) ? `${row_val[j]}` :`${row_val[j]},`
2829
}
29-
data_string += "],"
30+
data_string += i == (row_length-1) ? "]" : "],"
3031
}
3132
}
3233
data_string += `...${row_length - 10} more]`
@@ -35,21 +36,23 @@ function print_val(val) {
3536
for (let i = 0; i < row_length; i++) {
3637

3738
let row_val = val[i]
39+
let col_length = row_val.length;
3840

3941
data_string += "[";
4042
if (col_length > 10) {
4143

4244
for (let j = 0; j < 10; j++) {
43-
data_string += `${row_val[j]},`
45+
data_string += j== 9 ? `${row_val[j]}`:`${row_val[j]},`
4446
}
4547

4648
data_string += `.......${col_length - 10} more],`
4749
} else {
4850

4951
for (let j = 0; j < col_length; j++) {
50-
data_string += `${row_val[j]},`
52+
53+
data_string += j== (col_length-1) ? `${row_val[j]}` :`${row_val[j]},`
5154
}
52-
data_string += "],"
55+
data_string += i == (row_length-1) ? "]" : "],"
5356
}
5457
}
5558
data_string += "]"
@@ -64,8 +67,7 @@ function print_val(val) {
6467
let count = row_length > 10 ? 10 : row_length
6568

6669
for (let i = 0; i < count; i++) {
67-
68-
data_string += `${val[i]},`
70+
data_string += i == (count-1) ? `${val[i]}` : `${val[i]},`
6971
}
7072

7173
let diff = row_length - count;
@@ -104,8 +106,7 @@ function viz(name, callback) {
104106

105107
let id = `#out_${window.current_cell}`
106108
$(`${id}`).append(`<div id=${name}></div>`)
107-
108-
return cb
109+
let cb = callback(name);
109110
}
110111

111112
function table(df) {
@@ -389,7 +390,12 @@ function load_notebook(json) {
389390
}
390391
}
391392

393+
function forLoop_log(args){
392394

393-
// function show_error_modal(){
395+
let id = `#out_${window.current_cell}`
396+
397+
$(`${id}`).append(`${args}<br />`)
398+
399+
}
394400

395-
// }
401+
console.forlog = forLoop_log

0 commit comments

Comments
 (0)