Skip to content

Commit 768eac0

Browse files
authored
Merge pull request #267 from dimitri-yatsenko/master
improved table appearance in jupyter
2 parents 326128d + e4a3787 commit 768eac0

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

‎datajoint/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import os
1717

1818
__author__ = "Dimitri Yatsenko, Edgar Y. Walker, and Fabian Sinz at Baylor College of Medicine"
19-
__version__ = "0.4.2"
20-
__date__ = "Nov 27, 2016"
19+
__version__ = "0.4.3"
20+
__date__ = "Nov 29, 2016"
2121
__all__ = ['__author__', '__version__',
2222
'config', 'conn', 'kill', 'BaseRelation',
2323
'Connection', 'Heading', 'FreeRelation', 'Not', 'schema',

‎datajoint/relational_operand.py‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,25 +360,50 @@ def preview(self):
360360
' '.join([templates[f] % ('*'+f if f in rel.primary_key else f) for f in columns]) + '\n' +
361361
' '.join(['+' + '-' * (widths[column] - 2) + '+' for column in columns]) + '\n' +
362362
'\n'.join(' '.join(templates[f] % tup[f] for f in columns) for tup in tuples) +
363-
('\n...\n' if len(rel) > limit else '\n') +
363+
('\n ...\n' if len(rel) > limit else '\n') +
364364
' (%d tuples)\n' % len(rel))
365365

366366
def _repr_html_(self):
367367
rel = self.proj(*self.heading.non_blobs,
368368
**dict(zip_longest(self.heading.blobs, [], fillvalue="'=BLOB='"))) # replace blobs with =BLOB=
369369
info = self.heading.table_info
370370
count = len(rel)
371-
return """ {title}
371+
372+
css = """
373+
<style type="text/css">
374+
.Relation{
375+
border-collapse:collapse;
376+
}
377+
.Relation th{
378+
background: #A0A0A0; color: #ffffff; padding:4px; border:#f0e0e0 1px solid;
379+
font-weight: normal; font-family: monospace; font-size: 75%;
380+
}
381+
.Relation td{
382+
padding:4px; border:#f0e0e0 1px solid; font-size:75%;
383+
}
384+
.Relation tr:nth-child(odd){
385+
background: #ffffff;
386+
}
387+
.Relation tr:nth-child(even){
388+
background: #f3f1ff;
389+
}
390+
</style>
391+
"""
392+
393+
return """
394+
{css}
395+
{title}
372396
<div style="max-height:1000px;max-width:1500px;overflow:auto;">
373-
<table border="1" class="dataframe">
397+
<table border="1" class="Relation">
374398
<thead> <tr style="text-align: right;"> <th> {head} </th> </tr> </thead>
375399
<tbody> <tr> {body} </tr> </tbody>
376400
</table>
377401
{ellipsis}
378402
<p>{count} tuples</p></div>
379403
""".format(
380-
title="" if info is None else "<h3>%s</h3>" % info['comment'],
381-
head='</th><th>'.join("<em>" + c + "</em>" if c in self.primary_key else c
404+
css=css,
405+
title="" if info is None else "<b>%s</b>" % info['comment'],
406+
head='</th><th>'.join('<b><font color="black">' + c + "</font></b>" if c in self.primary_key else c
382407
for c in rel.heading.names),
383408
ellipsis='<p>...</p>' if count > config['display.limit'] else '',
384409
body='</tr><tr>'.join(

‎tests/test_relation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,4 @@ def test_table_size(self):
182182
assert_true(self.experiment.size_on_disk > 100)
183183

184184
def test_repr_html(self):
185-
assert_true(self.ephys._repr_html_().strip().startswith("<h3>"))
185+
assert_true(self.ephys._repr_html_().strip().startswith("<style"))

0 commit comments

Comments
 (0)