Skip to content

Commit

Permalink
Move plot widget to bottom (#1199)
Browse files Browse the repository at this point in the history
Co-authored-by: maximlt <[email protected]>
  • Loading branch information
ahuang11 and maximlt authored Dec 21, 2023
1 parent 1c2eb15 commit c8efb3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions hvplot/tests/testui.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
)

# 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

0 comments on commit c8efb3e

Please sign in to comment.