Skip to content

Commit

Permalink
Handle margin=None in layout sizing mode computation (#6267)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 24, 2024
1 parent 269b433 commit 0343958
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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}'}

0 comments on commit 0343958

Please sign in to comment.