Skip to content

Commit b349e25

Browse files
authored
Fix Table view horizontal overflow with long string columns (#1746)
1 parent 4b4ccb2 commit b349e25

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

lumen/tests/views/test_base.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from lumen.state import state
1111
from lumen.variables.base import Variables
1212
from lumen.views.base import (
13-
Panel, VegaLiteView, View, hvOverlayView, hvPlotView,
13+
Panel, Table, VegaLiteView, View, hvOverlayView, hvPlotView,
1414
)
1515

1616

@@ -221,6 +221,29 @@ def test_hvplot_view_to_spec(set_root):
221221
'alpha': 0.3
222222
}
223223

224+
def test_table_layout_defaults(set_root):
225+
set_root(str(Path(__file__).parent.parent))
226+
source = FileSource(tables={'test': 'sources/test.csv'})
227+
view = View.from_spec({'type': 'table', 'table': 'test'}, source, [])
228+
panel = view.get_panel()
229+
assert panel.sizing_mode == 'stretch_width'
230+
assert panel.layout == 'fit_data_stretch'
231+
assert panel._configuration.get('columnDefaults', {}).get('maxInitialWidth') == 300
232+
233+
234+
def test_table_user_configuration_merges(set_root):
235+
set_root(str(Path(__file__).parent.parent))
236+
source = FileSource(tables={'test': 'sources/test.csv'})
237+
table = Table(
238+
pipeline=Pipeline(source=source, table='test'),
239+
configuration={'columnDefaults': {'maxInitialWidth': 500, 'headerSort': False}},
240+
)
241+
panel = table.get_panel()
242+
config = panel._configuration
243+
assert config['columnDefaults']['maxInitialWidth'] == 500
244+
assert config['columnDefaults']['headerSort'] is False
245+
246+
224247
@pytest.mark.parametrize("view_type", ("table", "hvplot"))
225248
def test_view_title(set_root, view_type):
226249
set_root(str(Path(__file__).parent.parent))

lumen/views/base.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,24 @@ class Table(View):
11631163
_panel_type = pn.widgets.tables.Tabulator
11641164

11651165
def get_panel(self):
1166-
return self._panel_type(**self._normalize_params(self._get_params()))
1166+
params = self._normalize_params(self._get_params())
1167+
config = {'columnDefaults': {'maxInitialWidth': 300}}
1168+
if 'configuration' in self.kwargs:
1169+
config.update(self.kwargs['configuration'])
1170+
params['configuration'] = config
1171+
return self._panel_type(**params)
11671172

11681173
def _get_params(self):
1169-
return dict(value=self.get_data(), disabled=True, page_size=self.page_size,
1170-
**self.kwargs)
1174+
kwargs = {k: v for k, v in self.kwargs.items() if k != 'configuration'}
1175+
params = dict(
1176+
value=self.get_data(),
1177+
disabled=True,
1178+
page_size=self.page_size,
1179+
sizing_mode='stretch_width',
1180+
layout='fit_data_stretch',
1181+
)
1182+
params.update(kwargs)
1183+
return params
11711184

11721185

11731186
class DownloadView(View):

0 commit comments

Comments
 (0)