Skip to content

Commit 361b506

Browse files
authored
Merge pull request #52 from eriknw/css
Use CSS for styling.
2 parents f1e7756 + 0810f77 commit 361b506

File tree

4 files changed

+1232
-193
lines changed

4 files changed

+1232
-193
lines changed

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
include setup.py
2+
include README.md
3+
include LICENSE
4+
include MANIFEST.in
15
include versioneer.py
26
include grblas/_version.py

grblas/formatting.py

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,82 @@
88
except ImportError: # pragma: no cover
99
has_pandas = False
1010

11+
# This was written by a complete novice at CSS.
12+
# If you can help make it better, please do!
13+
CSS_STYLE = """
14+
<style>
15+
table.gb-info-table {
16+
border: 1px solid black;
17+
max-width: 100%;
18+
margin-top: 0px;
19+
margin-bottom: 0px;
20+
padding-top: 0px;
21+
padding-bottom: 0px;
22+
}
23+
24+
td.gb-info-name-cell {
25+
line-height: 100%;
26+
}
27+
28+
details.gb-arg-details {
29+
margin-top: 0px;
30+
margin-bottom: 0px;
31+
padding-top: 0px;
32+
padding-bottom: 5px;
33+
margin-left: 10px;
34+
}
35+
36+
summary.gb-arg-summary {
37+
display: list-item;
38+
outline: none;
39+
margin-top: 0px;
40+
margin-bottom: 0px;
41+
padding-top: 0px;
42+
padding-bottom: 0px;
43+
margin-left: -10px;
44+
}
45+
46+
details.gb-expr-details {
47+
margin-top: 0px;
48+
margin-bottom: 0px;
49+
padding-top: 0px;
50+
padding-bottom: 5px;
51+
}
52+
53+
summary.gb-expr-summary {
54+
display: list-item;
55+
outline: none;
56+
margin-top: 0px;
57+
margin-bottom: 0px;
58+
padding-top: 0px;
59+
padding-bottom: 0px;
60+
}
61+
62+
blockquote.gb-expr-blockquote {
63+
margin-top: 5px;
64+
margin-bottom: 0px;
65+
padding-top: 0px;
66+
padding-bottom: 0px;
67+
margin-left: 15px;
68+
}
69+
70+
.gb-scalar {
71+
margin-top: 0px;
72+
margin-bottom: 0px;
73+
padding-top: 0px;
74+
padding-bottom: 5px;
75+
}
76+
77+
/* modify pandas dataframe */
78+
table.dataframe {
79+
margin-top: 0px;
80+
margin-bottom: 0px;
81+
padding-top: 0px;
82+
padding-bottom: 0px;
83+
}
84+
</style>
85+
"""
86+
1187

1288
def _update_matrix_dataframe(df, matrix, rows, row_offset, columns, column_offset, *, mask=None):
1389
if rows is None and columns is None:
@@ -163,9 +239,9 @@ def vector_info(vector, *, mask=None, for_html=True):
163239

164240
def create_header_html(name, keys, vals):
165241
text = [
166-
'<div>\n<table style="border:1px solid black; max-width:100%;">\n'
242+
'<div>\n<table class="gb-info-table">\n'
167243
" <tr>\n"
168-
f' <td rowspan="2" style="line-height:100%"><pre>{name}</pre></td>\n'
244+
f' <td rowspan="2" class="gb-info-name-cell"><pre>{name}</pre></td>\n'
169245
]
170246
text.extend(f" <td><pre>{key}</pre></td>\n" for key in keys)
171247
text.append(" </tr>\n <tr>\n")
@@ -194,8 +270,9 @@ def _format_html(name, header, df):
194270
details = "<em>(Install</em> <tt>pandas</tt> <em>to see a preview of the data)</em>"
195271
return (
196272
"<div>"
197-
f"<details{state}>"
198-
'<summary style="display:list-item; outline:none;">'
273+
f"{CSS_STYLE}"
274+
f'<details{state} class="gb-arg-details">'
275+
'<summary class="gb-arg-summary">'
199276
f"<tt>{name}</tt>{header}"
200277
"</summary>"
201278
f"{details}"
@@ -226,7 +303,7 @@ def format_vector_html(vector, *, max_columns=None, mask=None):
226303

227304
def format_scalar_html(scalar):
228305
header = create_header_html("grblas.Scalar", ["value", "dtype"], [scalar.value, scalar.dtype])
229-
return f"<div><tt>{scalar._name_html}</tt>{header}</div>"
306+
return f'<div class="gb-scalar"><tt>{scalar._name_html}</tt>{header}</div>'
230307

231308

232309
def format_scalar(scalar):
@@ -244,13 +321,13 @@ def _format_expression(expr, header):
244321
args = [pos_to_arg[pos] for pos in sorted(pos_to_arg)]
245322
arg_string = "".join(x._repr_html_() for x in args if hasattr(x, "_repr_html_"))
246323
return (
247-
'<div style="padding:4px;">'
248-
"<details>"
249-
'<summary style="display:list-item; outline:none;">'
324+
"<div>"
325+
'<details class="gb-expr-details">'
326+
'<summary class="gb-expr-summary">'
250327
f"<b><tt>grblas.{type(expr).__name__}:</tt></b>"
251328
f"{header}"
252329
"</summary>"
253-
"<blockquote>"
330+
'<blockquote class="gb-expr-blockquote">'
254331
f"{arg_string}"
255332
"</blockquote>"
256333
"</details>"

0 commit comments

Comments
 (0)