(panels, x, y, w, h)
| 505 | |
| 506 | |
| 507 | def panel_layout_generation(panels, x, y, w, h): |
| 508 | # If only 1 panel, place it entirely |
| 509 | if len(panels) == 1: |
| 510 | p = panels[0] |
| 511 | cur_rp = (w/h) if h>1e-9 else p["rp"] |
| 512 | loss = abs(p["rp"] - cur_rp) |
| 513 | arrangement = [{ |
| 514 | "panel_name": p["section_name"], |
| 515 | "panel_id": p["panel_id"], |
| 516 | "x": x, "y": y, |
| 517 | "width": w, "height": h |
| 518 | }] |
| 519 | return loss, arrangement |
| 520 | |
| 521 | best_loss = float('inf') |
| 522 | best_arr = [] |
| 523 | total_sp = sum(pp["sp"] for pp in panels) |
| 524 | n = len(panels) |
| 525 | |
| 526 | for i in range(1, n): |
| 527 | subset1 = panels[:i] |
| 528 | subset2 = panels[i:] |
| 529 | sp1 = sum(pp["sp"] for pp in subset1) |
| 530 | ratio = sp1 / total_sp |
| 531 | |
| 532 | # horizontal |
| 533 | h_top = ratio * h |
| 534 | if 0 < h_top < h: |
| 535 | l1, a1 = panel_layout_generation(subset1, x, y, w, h_top) |
| 536 | l2, a2 = panel_layout_generation(subset2, x, y + h_top, w, h - h_top) |
| 537 | if (l1 + l2) < best_loss: |
| 538 | best_loss = l1 + l2 |
| 539 | best_arr = a1 + a2 |
| 540 | |
| 541 | # vertical |
| 542 | w_left = ratio * w |
| 543 | if 0 < w_left < w: |
| 544 | l1, a1 = panel_layout_generation(subset1, x, y, w_left, h) |
| 545 | l2, a2 = panel_layout_generation(subset2, x + w_left, y, w - w_left, h) |
| 546 | if (l1 + l2) < best_loss: |
| 547 | best_loss = l1 + l2 |
| 548 | best_arr = a1 + a2 |
| 549 | |
| 550 | return best_loss, best_arr |
| 551 | |
| 552 | def split_textbox(textbox, ratio): |
| 553 | """ |
no outgoing calls
no test coverage detected