Skip to content

Commit

Permalink
Add test and ensure int values
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Nov 27, 2024
1 parent bbdd4f2 commit 294dbc0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/vitessce/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
62 changes: 62 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 294dbc0

Please sign in to comment.