|
1 | 1 | import param |
2 | 2 | import panel as pn |
3 | | - |
| 3 | +import numpy as np |
| 4 | +from copy import copy |
4 | 5 |
|
5 | 6 | from .viewlist import possible_class_views |
6 | 7 | from .layout_presets import get_layout_description |
@@ -182,7 +183,48 @@ def listen_setting_changes(view): |
182 | 183 | for setting_data in view._settings: |
183 | 184 | view.settings._parameterized.param.watch(view.on_settings_changed, setting_data["name"]) |
184 | 185 |
|
| 186 | +def get_size_top_row(initial_row, initial_col, is_zone_array, original_zone_array): |
| 187 | + |
| 188 | + if original_zone_array[initial_row][initial_col] == False: |
| 189 | + return 0,0 |
| 190 | + |
| 191 | + num_rows = is_zone_array[initial_row][initial_col]*1 |
| 192 | + num_cols = num_rows |
| 193 | + |
| 194 | + num_rows += (not is_zone_array[1][initial_col])*1 |
| 195 | + |
| 196 | + if num_rows == 1: |
| 197 | + for zone in is_zone_array[0,1+initial_col:]: |
| 198 | + if zone == True: |
| 199 | + break |
| 200 | + num_cols += 1 |
| 201 | + elif num_rows == 2: |
| 202 | + for zone1, zone2 in np.transpose(is_zone_array[:,1+initial_col:]): |
| 203 | + if zone1 == True or zone2 == True: |
| 204 | + break |
| 205 | + num_cols += 1 |
| 206 | + |
| 207 | + is_zone_array[initial_row:initial_row+num_rows,initial_col:initial_col+num_cols] = True |
185 | 208 |
|
| 209 | + return num_rows, num_cols |
| 210 | + |
| 211 | +def get_size_bottom_row(initial_row, initial_col, is_zone_array, original_zone_array): |
| 212 | + |
| 213 | + if original_zone_array[initial_row][initial_col] == False: |
| 214 | + return 0,0 |
| 215 | + |
| 216 | + num_rows = is_zone_array[initial_row][initial_col]*1 |
| 217 | + if num_rows == 0: |
| 218 | + return 0, 0 |
| 219 | + num_cols = num_rows |
| 220 | + |
| 221 | + for zone in is_zone_array[1,1+initial_col:]: |
| 222 | + if zone == True: |
| 223 | + break |
| 224 | + else: |
| 225 | + num_cols += 1 |
| 226 | + |
| 227 | + return num_rows, num_cols |
186 | 228 |
|
187 | 229 | class PanelMainWindow: |
188 | 230 |
|
@@ -285,52 +327,18 @@ def create_main_layout(self): |
285 | 327 |
|
286 | 328 | all_zones = [f'zone{a}' for a in range(1,9)] |
287 | 329 | is_zone = [(layout_zone.get(zone) is not None) and (len(layout_zone.get(zone)) > 0) for zone in all_zones] |
288 | | - |
289 | | - # Get number of columns and rows per sub-region |
290 | | - num_cols_12 = max(is_zone[0]*1 + is_zone[1]*1, is_zone[4]*1 + is_zone[5]*1) |
291 | | - num_cols_56 = num_cols_12 |
292 | | - num_cols_37 = (is_zone[2] or is_zone[6])*1 |
293 | | - |
294 | | - num_rows_12 = ((is_zone[0] or is_zone[1])*1 - (is_zone[4] or is_zone[5])*1) + 1 |
295 | | - |
296 | | - # Do sub-regions [1,2], [4,5] [3][7] and [5][8] separately. For each, find out if |
297 | | - # both zones are present. If they are, place both in sub-region. If not, place one. |
298 | | - |
299 | | - row_slice_12 = slice(0,num_rows_12) |
300 | | - if (is_zone[0] and is_zone[1]): |
301 | | - gs[row_slice_12, slice(0,1)] = layout_zone.get('zone1') |
302 | | - gs[row_slice_12, slice(1,2)] = layout_zone.get('zone2') |
303 | | - elif (is_zone[0] and not is_zone[1]): |
304 | | - gs[row_slice_12, slice(0,num_cols_12)] = layout_zone.get('zone1') |
305 | | - elif (is_zone[1] and not is_zone[0]): |
306 | | - gs[row_slice_12, slice(0,num_cols_12)] = layout_zone.get('zone2') |
307 | | - |
308 | | - row_slice_56 = slice(num_rows_12, 2) |
309 | | - if (is_zone[4] and is_zone[5]): |
310 | | - gs[row_slice_56, slice(0,1)] = layout_zone.get('zone5') |
311 | | - gs[row_slice_56, slice(1,2)] = layout_zone.get('zone6') |
312 | | - elif (is_zone[4] and not is_zone[5]): |
313 | | - gs[row_slice_56, slice(0,num_cols_56)] = layout_zone.get('zone5') |
314 | | - elif (is_zone[5] and not is_zone[4]): |
315 | | - gs[row_slice_56, slice(0,num_cols_56)] = layout_zone.get('zone6') |
316 | | - |
317 | | - col_slice_37 = slice(num_cols_12,num_cols_12+1) |
318 | | - if is_zone[2] and is_zone[6]: |
319 | | - gs[slice(0, 1), col_slice_37] = layout_zone.get('zone3') |
320 | | - gs[slice(1, 2), col_slice_37] = layout_zone.get('zone7') |
321 | | - elif is_zone[2] and not is_zone[6]: |
322 | | - gs[slice(0, 2), col_slice_37] = layout_zone.get('zone3') |
323 | | - elif is_zone[6] and not is_zone[2]: |
324 | | - gs[slice(0, 2), col_slice_37] = layout_zone.get('zone7') |
325 | | - |
326 | | - col_slice_48 = slice(num_cols_12+num_cols_37,num_cols_12+num_cols_37+1) |
327 | | - if is_zone[3] and is_zone[7]: |
328 | | - gs[slice(0, 1), col_slice_48] = layout_zone.get('zone4') |
329 | | - gs[slice(1, 2), col_slice_48] = layout_zone.get('zone8') |
330 | | - elif is_zone[3] and not is_zone[7]: |
331 | | - gs[slice(0, 2), col_slice_48] = layout_zone.get('zone4') |
332 | | - elif is_zone[7] and not is_zone[3]: |
333 | | - gs[slice(0, 2), col_slice_48] = layout_zone.get('zone8') |
| 330 | + is_zone_array = np.reshape(is_zone, (2,4)) |
| 331 | + original_zone_array = copy(is_zone_array) |
| 332 | + |
| 333 | + for zone_index in range(8): |
| 334 | + row = zone_index // 4 |
| 335 | + col = zone_index % 4 |
| 336 | + if row == 0: |
| 337 | + num_rows, num_cols = get_size_top_row(row, col, is_zone_array, original_zone_array) |
| 338 | + elif row == 1: |
| 339 | + num_rows, num_cols = get_size_bottom_row(row, col, is_zone_array, original_zone_array) |
| 340 | + if num_rows > 0 and num_cols > 0: |
| 341 | + gs[slice(row, row + num_rows), slice(col,col+num_cols)] = layout_zone.get(f'zone{zone_index+1}') |
334 | 342 |
|
335 | 343 | self.main_layout = gs |
336 | 344 |
|
|
0 commit comments