Skip to content

Commit 5acb24b

Browse files
rhttpike3
authored andcommitted
Simplify initial grid layout creation
1 parent a8922ff commit 5acb24b

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

mesa/experimental/jupyter_viz.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def render_in_browser():
157157
if measures:
158158
layout_types += [{"Measure": elem} for elem in range(len(measures))]
159159

160-
grid_layout_initial = get_initial_grid_layout(layout_types=layout_types)
160+
grid_layout_initial = make_initial_grid_layout(layout_types=layout_types)
161161
grid_layout, set_grid_layout = solara.use_state(grid_layout_initial)
162162

163163
with solara.Sidebar():
@@ -385,20 +385,15 @@ def function(model):
385385
return function
386386

387387

388-
def get_initial_grid_layout(layout_types):
389-
grid_lay = []
390-
y_coord = 0
391-
for ii in range(len(layout_types)):
392-
template_layout = {"h": 10, "i": 0, "moved": False, "w": 6, "y": 0, "x": 0}
393-
if ii == 0:
394-
grid_lay.append(template_layout)
395-
else:
396-
template_layout.update({"i": ii})
397-
if ii % 2 == 0:
398-
template_layout.update({"x": 0})
399-
y_coord += 16
400-
else:
401-
template_layout.update({"x": 6})
402-
template_layout.update({"y": y_coord})
403-
grid_lay.append(template_layout)
404-
return grid_lay
388+
def make_initial_grid_layout(layout_types):
389+
return [
390+
{
391+
"i": i,
392+
"w": 6,
393+
"h": 10,
394+
"moved": False,
395+
"x": 6 * (i % 2),
396+
"y": 16 * (i - i % 2),
397+
}
398+
for i in range(len(layout_types))
399+
]

0 commit comments

Comments
 (0)