Skip to content

Commit 9874b7c

Browse files
lorenzo-wrich-iannonemachow
authored
Fix #791 by handling interactive_data_values properly (#792)
* Fix #791 on upstream repo * Refactor pipe function to use Concatenate in type hints Updated the pipe function signature to use Concatenate for better type hinting. * Add tests for nanoplot interactive option * tests: test interactive_data_values svg --------- Co-authored-by: Richard Iannone <riannone@me.com> Co-authored-by: Michael Chow <mc_al_github@fastmail.com>
1 parent f657d81 commit 9874b7c

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

great_tables/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ def nanoplot_options(
14451445
show_vertical_guides = True if show_vertical_guides is None else show_vertical_guides
14461446
show_y_axis_guide = True if show_y_axis_guide is None else show_y_axis_guide
14471447

1448-
interactive_data_values = interactive_data_values or True
1448+
interactive_data_values = True if interactive_data_values is None else interactive_data_values
14491449

14501450
# y_val_fmt_fn, y_axis_fmt_fn, and y_ref_line_fmt_fn
14511451
# are not assigned to a default value

tests/test__utils_nanoplots.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,22 @@ def test_nanoplot_unknown_plot_type():
19841984
_generate_nanoplot(y_vals=[1, 2, 3], plot_type="unknown")
19851985

19861986

1987+
@pytest.mark.parametrize("interactive_data_values", [True, False])
1988+
def test_generate_nanoplot_interactive_data_values_toggles_hover_css(interactive_data_values):
1989+
svg = _generate_nanoplot(
1990+
y_vals=[1.0, 2.0, 3.0],
1991+
interactive_data_values=interactive_data_values,
1992+
)
1993+
1994+
assert _is_nanoplot_output(svg)
1995+
1996+
if interactive_data_values:
1997+
assert ".vert-line:hover rect" in svg
1998+
else:
1999+
assert ":hover" not in svg
2000+
assert ".vert-line rect" in svg
2001+
2002+
19872003
@pytest.mark.parametrize(
19882004
"n, bool_",
19892005
[
@@ -2061,3 +2077,17 @@ def test_noerror_list_of_strings() -> None:
20612077
show_data_area=False,
20622078
),
20632079
)
2080+
2081+
2082+
def test_nanoplot_options_interactive_data_values():
2083+
# When interactive_data_values is not set, it should default to True
2084+
opts_default = nanoplot_options()
2085+
assert opts_default["interactive_data_values"] is True
2086+
2087+
# When explicitly set to False, it should be respected (not overridden)
2088+
opts_false = nanoplot_options(interactive_data_values=False)
2089+
assert opts_false["interactive_data_values"] is False
2090+
2091+
# When explicitly set to True, it should remain True
2092+
opts_true = nanoplot_options(interactive_data_values=True)
2093+
assert opts_true["interactive_data_values"] is True

0 commit comments

Comments
 (0)