Skip to content
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

Move plot widget to bottom #1199

Merged
merged 10 commits into from Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions hvplot/tests/testui.py
Expand Up @@ -64,6 +64,7 @@ def test_explorer_plot_code():
" kind='scatter',\n"
" x='bill_length_mm',\n"
" y=['bill_depth_mm'],\n"
" widget_location='bottom',\n"
")"
)
)
Expand All @@ -77,6 +78,7 @@ def test_explorer_plot_code():
" kind='scatter',\n"
" x='bill_length_mm',\n"
" y=['bill_depth_mm'],\n"
" widget_location='bottom',\n"
")"
)
)
Expand Down Expand Up @@ -278,6 +280,7 @@ def test_explorer_code_dataframe():
kind='points',
x='bill_length_mm',
y='species',
widget_location='bottom',
)"""
)
assert explorer._code_pane.object == dedent("""\
Expand All @@ -286,6 +289,7 @@ def test_explorer_code_dataframe():
kind='points',
x='bill_length_mm',
y='species',
widget_location='bottom',
)
```"""
)
Expand All @@ -301,6 +305,7 @@ def test_explorer_code_gridded():
kind='image',
x='lon',
y='lat',
widget_location='bottom',
)""")

assert explorer._code_pane.object == dedent("""\
Expand All @@ -311,6 +316,7 @@ def test_explorer_code_gridded():
kind='image',
x='lon',
y='lat',
widget_location='bottom',
)
```"""
)
Expand All @@ -327,6 +333,7 @@ def test_explorer_code_gridded_dataarray():
kind='image',
x='lon',
y='lat',
widget_location='bottom',
)""")

assert explorer._code_pane.object == dedent("""\
Expand All @@ -337,6 +344,7 @@ def test_explorer_code_gridded_dataarray():
kind='image',
x='lon',
y='lat',
widget_location='bottom',
)
```"""
)
Expand All @@ -353,6 +361,7 @@ def test_explorer_code_opts():
kind='image',
x='lon',
y='lat',
widget_location='bottom',
).opts(
color_levels=3,
)""")
Expand All @@ -365,6 +374,7 @@ def test_explorer_code_opts():
kind='image',
x='lon',
y='lat',
widget_location='bottom',
).opts(
color_levels=3,
)
Expand Down
19 changes: 15 additions & 4 deletions hvplot/ui.py
Expand Up @@ -517,8 +517,11 @@ def __init__(self, df, **params):
self._alert = pn.pane.Alert(
alert_type='danger', visible=False, sizing_mode='stretch_width'
)
self._hv_pane = pn.pane.HoloViews(sizing_mode='stretch_width', margin=(5, 20, 5, 20))
self._code_pane = pn.pane.Markdown(sizing_mode='stretch_width', margin=(5, 20, 0, 20))
self._hv_pane = pn.pane.HoloViews(
sizing_mode='stretch_both', min_height=250, margin=(5, 5, 5, 20),
widget_location="bottom", widget_layout=pn.Row)
self._code_pane = pn.pane.Markdown(
sizing_mode='stretch_both', min_height=250, margin=(5, 5, 0, 20))
self._layout = pn.Column(
self._alert,
self._statusbar,
Expand All @@ -528,9 +531,10 @@ def __init__(self, df, **params):
# Using .layout on the HoloViews pane to display the widgets
# https://github.com/holoviz/panel/issues/5628#issuecomment-1763443895
pn.Tabs(('Plot', self._hv_pane.layout), ('Code', self._code_pane)),
sizing_mode='stretch_width',
sizing_mode='stretch_both'
),
sizing_mode='stretch_both'
sizing_mode='stretch_width',
height=600
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min_height unfortunately did not work for me.

)

# initialize
Expand Down Expand Up @@ -596,6 +600,12 @@ def _plot(self, *events):
if opts_kwargs:
self._hvplot.opts(**opts_kwargs)
self._hv_pane.object = self._hvplot
# Working around a Panel issue that cause the widgets not to
# be well aligned when in a Row layout.
# See https://github.com/holoviz/panel/issues/6110
if len(self._hv_pane.widget_box) > 1:
for w in self._hv_pane.widget_box:
w.margin = (20, 5, 5, 5)
self._alert.visible = False
except Exception as e:
self._alert.param.update(
Expand Down Expand Up @@ -687,6 +697,7 @@ def plot_code(self, var_name=None):
Data variable name by which the returned string will start.
"""
settings = self.settings()
settings["widget_location"] = "bottom"
settings_args = ''
if settings:
settings_args = self._build_kwargs_string(settings)
Expand Down