(specs, grid_ref, insets, insets_ref, row_seq)
| 1263 | |
| 1264 | |
| 1265 | def _build_grid_str(specs, grid_ref, insets, insets_ref, row_seq): |
| 1266 | # Compute rows and columns |
| 1267 | rows = len(specs) |
| 1268 | cols = len(specs[0]) |
| 1269 | |
| 1270 | # Initialize constants |
| 1271 | sp = " " # space between cell |
| 1272 | s_str = "[ " # cell start string |
| 1273 | e_str = " ]" # cell end string |
| 1274 | |
| 1275 | s_top = "⎡ " # U+23A1 |
| 1276 | s_mid = "⎢ " # U+23A2 |
| 1277 | s_bot = "⎣ " # U+23A3 |
| 1278 | |
| 1279 | e_top = " ⎤" # U+23A4 |
| 1280 | e_mid = " ⎟" # U+239F |
| 1281 | e_bot = " ⎦" # U+23A6 |
| 1282 | |
| 1283 | colspan_str = " -" # colspan string |
| 1284 | rowspan_str = " :" # rowspan string |
| 1285 | empty_str = " (empty) " # empty cell string |
| 1286 | # Init grid_str with intro message |
| 1287 | grid_str = "This is the format of your plot grid:\n" |
| 1288 | |
| 1289 | # Init tmp list of lists of strings (sorta like 'grid_ref' but w/ strings) |
| 1290 | _tmp = [["" for c in range(cols)] for r in range(rows)] |
| 1291 | |
| 1292 | # Define cell string as function of (r, c) and grid_ref |
| 1293 | def _get_cell_str(r, c, subplot_refs): |
| 1294 | layout_keys = sorted({k for ref in subplot_refs for k in ref.layout_keys}) |
| 1295 | |
| 1296 | ref_str = ",".join(layout_keys) |
| 1297 | |
| 1298 | # Replace yaxis2 -> y2 |
| 1299 | ref_str = ref_str.replace("axis", "") |
| 1300 | return "({r},{c}) {ref}".format(r=r + 1, c=c + 1, ref=ref_str) |
| 1301 | |
| 1302 | # Find max len of _cell_str, add define a padding function |
| 1303 | cell_len = ( |
| 1304 | max( |
| 1305 | [ |
| 1306 | len(_get_cell_str(r, c, ref)) |
| 1307 | for r, row_ref in enumerate(grid_ref) |
| 1308 | for c, ref in enumerate(row_ref) |
| 1309 | if ref |
| 1310 | ] |
| 1311 | ) |
| 1312 | + len(s_str) |
| 1313 | + len(e_str) |
| 1314 | ) |
| 1315 | |
| 1316 | def _pad(s, cell_len=cell_len): |
| 1317 | return " " * (cell_len - len(s)) |
| 1318 | |
| 1319 | # Loop through specs, fill in _tmp |
| 1320 | for r, spec_row in enumerate(specs): |
| 1321 | for c, spec in enumerate(spec_row): |
| 1322 | ref = grid_ref[r][c] |
no test coverage detected