From 294dbc0d482dfdacea4965e7d1a3113cd0400024 Mon Sep 17 00:00:00 2001 From: Mark Keller <7525285+keller-mark@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:56:40 -0500 Subject: [PATCH] Add test and ensure int values --- src/vitessce/config.py | 4 +-- tests/test_config.py | 62 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/vitessce/config.py b/src/vitessce/config.py index 3a5a984..b19f714 100644 --- a/src/vitessce/config.py +++ b/src/vitessce/config.py @@ -1467,13 +1467,13 @@ def _layout(obj, x_min, x_max, y_min, y_max): total = sum(split) if isinstance(obj, VitessceConfigViewHConcat): - widths = [s / total * w for s in split] + widths = [int(s / total * w) for s in split] x_pos = x_min for view, width in zip(views, widths): _layout(view, x_pos, x_pos + width, y_min, y_max) x_pos += width if isinstance(obj, VitessceConfigViewVConcat): - heights = [s / total * h for s in split] + heights = [int(s / total * h) for s in split] y_pos = y_min for view, height in zip(views, heights): _layout(view, x_min, x_max, y_pos, y_pos + height) diff --git a/tests/test_config.py b/tests/test_config.py index fe57262..e8f9c78 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -555,6 +555,68 @@ def test_config_set_layout_multi_view(): "initStrategy": "auto" } +def test_config_set_layout_multi_view_custom_split(): + vc = VitessceConfig(schema_version="1.0.15") + my_dataset = vc.add_dataset(name='My Dataset') + v1 = vc.add_view(cm.SPATIAL, dataset=my_dataset) + v2 = vc.add_view(cm.SPATIAL, dataset=my_dataset) + v3 = vc.add_view(cm.SPATIAL, dataset=my_dataset) + + vc.layout(hconcat(v1, vconcat(v2, v3, split=[1, 2]), split=[3, 1])) + + vc_dict = vc.to_dict() + + assert vc_dict == { + "version": "1.0.15", + "name": "", + "description": "", + "datasets": [ + { + 'uid': 'A', + 'name': 'My Dataset', + 'files': [] + } + ], + 'coordinationSpace': { + 'dataset': { + 'A': 'A' + }, + }, + "layout": [ + { + 'component': 'spatial', + 'coordinationScopes': { + 'dataset': 'A', + }, + 'x': 0, + 'y': 0, + 'h': 12, + 'w': 9, + }, + { + 'component': 'spatial', + 'coordinationScopes': { + 'dataset': 'A', + }, + 'x': 9, + 'y': 0, + 'h': 4, + 'w': 3, + }, + { + 'component': 'spatial', + 'coordinationScopes': { + 'dataset': 'A', + }, + 'x': 9, + 'y': 4, + 'h': 8, + 'w': 3, + } + ], + "initStrategy": "auto" + } + def test_config_set_layout_multi_view_magic(): vc = VitessceConfig(schema_version="1.0.15")