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

Handle margin=None in layout sizing mode computation #6267

Merged
merged 2 commits into from
Jan 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions panel/layout/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def _compute_sizing_mode(self, children, props):
ensure sufficient space is available.
"""
margin = props.get('margin', self.margin)
if margin is None:
margin = 0
sizing_mode = props.get('sizing_mode', self.sizing_mode)
if sizing_mode == 'fixed':
return {}
Expand Down
47 changes: 47 additions & 0 deletions panel/tests/layout/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,50 @@ def test_pass_objects_ref(document, comm):
md3 = col.objects[0]
assert isinstance(md3, Markdown)
assert md3.object == 'foo'

@pytest.mark.parametrize('dim', ["width", "height"])
def test_compute_sizing_mode_stretch_margin_none(dim, document, comm):
md = Markdown(**{dim: 100})
col = Column(md, margin=None, sizing_mode=f'stretch_{dim}')

root = col.get_root(document, comm=comm)

new_props = col._compute_sizing_mode(root.children, {'margin': None})

assert new_props == {f'min_{dim}': 100, 'sizing_mode': f'stretch_{dim}'}

@pytest.mark.parametrize('dim', ["width", "height"])
def test_compute_sizing_mode_stretch_margin_int(dim, document, comm):
margin = 10
md = Markdown(**{dim: 100})
col = Column(md, margin=margin, sizing_mode=f'stretch_{dim}')

root = col.get_root(document, comm=comm)

new_props = col._compute_sizing_mode(root.children, {'margin': margin})

assert new_props == {f'min_{dim}': 120, 'sizing_mode': f'stretch_{dim}'}

@pytest.mark.parametrize('dim', ["width", "height"])
def test_compute_sizing_mode_stretch_margin_two_tuple(dim, document, comm):
margin = (0, 10) if dim == 'width' else (10, 0)
md = Markdown(**{dim: 100})
col = Column(md, margin=margin, sizing_mode=f'stretch_{dim}')

root = col.get_root(document, comm=comm)

new_props = col._compute_sizing_mode(root.children, {'margin': margin})

assert new_props == {f'min_{dim}': 120, 'sizing_mode': f'stretch_{dim}'}

@pytest.mark.parametrize('dim', ["width", "height"])
def test_compute_sizing_mode_stretch_margin_four_tuple(dim, document, comm):
margin = (0, 10, 0, 5) if dim == 'width' else (10, 0, 5, 0)
md = Markdown(**{dim: 100})
col = Column(md, margin=margin, sizing_mode=f'stretch_{dim}')

root = col.get_root(document, comm=comm)

new_props = col._compute_sizing_mode(root.children, {'margin': margin})

assert new_props == {f'min_{dim}': 115, 'sizing_mode': f'stretch_{dim}'}
Loading