Skip to content

Commit aaad1a0

Browse files
committed
add function to print table
1 parent 2ce1c81 commit aaad1a0

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

notebookjs/src/public/javascripts/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function exec_cell(c_id) {
2424
if (Array.isArray(global_scope)) {
2525
global_scope = print_val(global_scope)
2626
}
27-
$(`#out_${id}`).html(global_scope || "");
27+
$(`#out_${id}`).html(global_scope);
2828

2929
count = parseInt(count) + 1
3030
let div_count = `div-${count}`

notebookjs/src/public/javascripts/utils.js

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

8989
return cb
90+
}
91+
92+
function table(df){
93+
94+
const {col_types, series, columns, index, values} = df;
95+
96+
97+
let head = ""
98+
if(series){
99+
head += `<th class="${col_types[0]}">${columns}</th>`
100+
}else{
101+
102+
columns.forEach((name,i)=>{
103+
head +=`<th class="${col_types[i]}">${name}</th>`
104+
});
105+
}
106+
107+
let body = ""
108+
109+
values.forEach((row,i)=>{
110+
111+
let b_String = `<tr><th>${index[i]}</th>`
112+
113+
if(series){
114+
b_String += `<td class="${col_types[0]}">${row}</td>`
115+
}else{
116+
117+
row.forEach((v,j)=>{
118+
b_String +=`<td class="${col_types[j]}">${v}</td>`
119+
});
120+
}
121+
122+
b_String +="</tr>"
123+
124+
body +=b_String;
125+
});
126+
127+
const table = `
128+
<div style="overflow: auto; max-height: 300px;"><table class="df-table" border="1">
129+
<thead>
130+
<tr>
131+
<th></th>
132+
${head}
133+
</tr>
134+
</thead>
135+
<tbody>
136+
${body}
137+
</tbody>
138+
</table>
139+
</div>
140+
`;
141+
142+
return table;
143+
90144
}

notebookjs/src/views/index.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<style>
8+
table.df-table { white-space: pre; }
9+
table.df-table th, td { padding: 2px 5px; font-variant-numeric: tabular-nums; }
10+
table.df-table .float32, .int32 { text-align: right; }
11+
</style>
712
<title>Document</title>
813
</head>
914

0 commit comments

Comments
 (0)