-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement row striping options #461
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #461 +/- ##
==========================================
+ Coverage 86.77% 86.80% +0.03%
==========================================
Files 42 42
Lines 4749 4760 +11
==========================================
+ Hits 4121 4132 +11
Misses 628 628 ☔ View full report in Codecov by Sentry. |
If #460 looks good, once we merge it and update the build should pass again! |
@@ -701,3 +701,163 @@ | |||
|
|||
''' | |||
# --- | |||
# name: test_tab_options_striping_snap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too big. Can you reduce it to a snapshot that is mostly limited to the piece being tested, or test it another way?
tests/test_options.py
Outdated
gt_tbl_opt = GT(exibble, id="test").opt_row_striping() | ||
gt_tbl_tab_options = GT(exibble, id="test").tab_options(row_striping_include_table_body=True) | ||
|
||
assert gt_tbl_opt.as_raw_html() == gt_tbl_tab_options.as_raw_html() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test this further upstream? If rendered html strings are the very last step, is there an earlier step that indicates these two approaches do the same thing (e.g. checking the options values directly, etc..)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check the options values directly here (comparing the two approaches).
tests/test_options.py
Outdated
assert gt_tbl_opt.as_raw_html() == gt_tbl_tab_options.as_raw_html() | ||
|
||
|
||
def test_tab_options_striping_snap(snapshot): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on snapshot. It'd be okay to test the css and html separately if it makes it easier to strip down. I wonder if you could easily test the css using an assertion, and snapshot test just the html body (with fewer rows of data; the minimum needed to test--3? or w/e makes sense given there are groupings; no need to have all columns in the snapshot please strip down)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to make the input df with much smaller dimensions and only snapshot the table body (everything inside <tbody>
). I don't think there's a need to snapshot the CSS part.
@@ -503,10 +515,30 @@ def create_body_component_h(data: GTData) -> str: | |||
cell_styles = "" | |||
|
|||
if is_stub_cell: | |||
body_cells.append(f""" <th class="gt_row gt_left gt_stub">{cell_str}</th>""") | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, so just a small nit here 😅. Do you mind consolidating so there is a bit less duplicated code? Seems like the following could happen:
- change variables like
td_classes
andth_classes
to have the same name. Similar withth_classes_str
, etc.. - add a variable like el_name that is either "th" or "td"
- move all other logic (e.g.
the appending of "gt_striped", the " ".join, the body_cells.append) out of the if / else, so it is only written once (e.g. move it to line 543 and unindent)- Use el_name in what should now be a single piece of code creating the final th or td string.
It looks like if something is a stub, that only affects the element name and some of the classes to be set. (But other logic is being included)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will make these changes!
tests/test_options.py
Outdated
row_striping_include_table_body=True, | ||
row_striping_include_stub=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test these separately, so that we know if one option is specified, it does not set both things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. There is now two distinct snapshots where one tests striping only of the stub, the other only of the body cells.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo, thanks for all these tweaks, it's beautiful!
Thanks @machow! Always a pleasure. |
This PR addresses #435 by making row striping options functional in rendered tables. An example of using row striping involves three new options in
tab_options()
:Alternatively, the
opt_row_striping()
method allows for a simplified shortcut forrow_striping_include_table_body=True
so the user doesn't have to look throughtab_options()
for this basic functionality:Note that the default background color for striping is a very light gray (by design).