Skip to content

Commit 7fb1d99

Browse files
committed
2 parents eac85e9 + 63947e8 commit 7fb1d99

6 files changed

Lines changed: 256 additions & 5 deletions

File tree

notebookjs/src/public/javascripts/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function exec_cell(c_id) {
3838
if (Array.isArray(global_scope)) {
3939
global_scope = print_val(global_scope)
4040
}
41-
$(`#out_${id}`).html(global_scope || "");
41+
$(`#out_${id}`).html(global_scope);
4242

4343
count = parseInt(count) + 1
4444
let div_count = `div-${count}`
@@ -279,7 +279,7 @@ $(document).on("click", "button.add-text", function () {
279279
} else {
280280
where = "up"
281281
}
282-
console.log(this.id);
282+
// console.log(this.id);
283283
add_new_text_cell(this.id, where)
284284
})
285285

@@ -320,5 +320,9 @@ function update_text_box_size() {
320320
}
321321

322322

323+
$("#download").click(function(){
324+
325+
let out= notebook_json(vars_in_scope);
323326

324-
327+
console.log(out);
328+
});

notebookjs/src/public/javascripts/temp_store.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

notebookjs/src/public/javascripts/utils.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,81 @@ function viz(name, callback) {
8888
// $("#ploty").remove(`${name}`)
8989

9090
return cb
91+
}
92+
93+
function table(df){
94+
95+
const {col_types, series, columns, index, values} = df;
96+
97+
98+
let head = ""
99+
if(series){
100+
head += `<th class="${col_types[0]}">${columns}</th>`
101+
}else{
102+
103+
columns.forEach((name,i)=>{
104+
head +=`<th class="${col_types[i]}">${name}</th>`
105+
});
106+
}
107+
108+
let body = ""
109+
110+
values.forEach((row,i)=>{
111+
112+
let b_String = `<tr><th>${index[i]}</th>`
113+
114+
if(series){
115+
b_String += `<td class="${col_types[0]}">${row}</td>`
116+
}else{
117+
118+
row.forEach((v,j)=>{
119+
b_String +=`<td class="${col_types[j]}">${v}</td>`
120+
});
121+
}
122+
123+
b_String +="</tr>"
124+
125+
body +=b_String;
126+
});
127+
128+
const table = `
129+
<div style="overflow: auto; max-height: 300px;"><table class="df-table" border="1">
130+
<thead>
131+
<tr>
132+
<th></th>
133+
${head}
134+
</tr>
135+
</thead>
136+
<tbody>
137+
${body}
138+
</tbody>
139+
</table>
140+
</div>
141+
`;
142+
143+
return table;
144+
145+
}
146+
147+
function notebook_json(scope){
148+
149+
var store = {}
150+
151+
for(let key in scope){
152+
153+
let id = key.split("-")[1]
154+
155+
let cell_content = scope[key].getValue()
156+
157+
let cell_output = $(`#out_${key}`).html()
158+
159+
store[`cell-${id}`] = {
160+
"in": cell_content,
161+
"out": cell_output
162+
}
163+
}
164+
165+
store = JSON.stringify(store);
166+
167+
return store
91168
}

notebookjs/src/views/index.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<body>
23

34
<div class="">
@@ -50,7 +51,11 @@
5051
</div>
5152
<div class="col-md-2"></div>
5253

53-
{{!-- Output of code div start --}}
54+
</div>
55+
56+
<button id="download">Download</button>
57+
</div>
58+
5459

5560

5661
{{!-- Markdown cell start --}}

notebookjs/src/views/layout.hbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
2828
<link rel='stylesheet' href='/stylesheets/style.css' />
2929
<script src="https://cdn.jsdelivr.net/remarkable/1.7.1/remarkable.min.js"></script>
30-
30+
<style>
31+
table.df-table { white-space: pre; }
32+
table.df-table th, td { padding: 2px 5px; font-variant-numeric: tabular-nums; }
33+
table.df-table .float32, .int32 { text-align: right; }
34+
</style>
3135
</head>
3236

3337
<body>

0 commit comments

Comments
 (0)