Skip to content

Commit 294dbc0

Browse files
committed
Add test and ensure int values
1 parent bbdd4f2 commit 294dbc0

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/vitessce/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,13 +1467,13 @@ def _layout(obj, x_min, x_max, y_min, y_max):
14671467
total = sum(split)
14681468

14691469
if isinstance(obj, VitessceConfigViewHConcat):
1470-
widths = [s / total * w for s in split]
1470+
widths = [int(s / total * w) for s in split]
14711471
x_pos = x_min
14721472
for view, width in zip(views, widths):
14731473
_layout(view, x_pos, x_pos + width, y_min, y_max)
14741474
x_pos += width
14751475
if isinstance(obj, VitessceConfigViewVConcat):
1476-
heights = [s / total * h for s in split]
1476+
heights = [int(s / total * h) for s in split]
14771477
y_pos = y_min
14781478
for view, height in zip(views, heights):
14791479
_layout(view, x_min, x_max, y_pos, y_pos + height)

tests/test_config.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,68 @@ def test_config_set_layout_multi_view():
555555
"initStrategy": "auto"
556556
}
557557

558+
def test_config_set_layout_multi_view_custom_split():
559+
vc = VitessceConfig(schema_version="1.0.15")
560+
my_dataset = vc.add_dataset(name='My Dataset')
561+
v1 = vc.add_view(cm.SPATIAL, dataset=my_dataset)
562+
v2 = vc.add_view(cm.SPATIAL, dataset=my_dataset)
563+
v3 = vc.add_view(cm.SPATIAL, dataset=my_dataset)
564+
565+
vc.layout(hconcat(v1, vconcat(v2, v3, split=[1, 2]), split=[3, 1]))
566+
567+
vc_dict = vc.to_dict()
568+
569+
assert vc_dict == {
570+
"version": "1.0.15",
571+
"name": "",
572+
"description": "",
573+
"datasets": [
574+
{
575+
'uid': 'A',
576+
'name': 'My Dataset',
577+
'files': []
578+
}
579+
],
580+
'coordinationSpace': {
581+
'dataset': {
582+
'A': 'A'
583+
},
584+
},
585+
"layout": [
586+
{
587+
'component': 'spatial',
588+
'coordinationScopes': {
589+
'dataset': 'A',
590+
},
591+
'x': 0,
592+
'y': 0,
593+
'h': 12,
594+
'w': 9,
595+
},
596+
{
597+
'component': 'spatial',
598+
'coordinationScopes': {
599+
'dataset': 'A',
600+
},
601+
'x': 9,
602+
'y': 0,
603+
'h': 4,
604+
'w': 3,
605+
},
606+
{
607+
'component': 'spatial',
608+
'coordinationScopes': {
609+
'dataset': 'A',
610+
},
611+
'x': 9,
612+
'y': 4,
613+
'h': 8,
614+
'w': 3,
615+
}
616+
],
617+
"initStrategy": "auto"
618+
}
619+
558620

559621
def test_config_set_layout_multi_view_magic():
560622
vc = VitessceConfig(schema_version="1.0.15")

0 commit comments

Comments
 (0)