Lay out text and figure boxes inside a panel. The figure’s aspect ratio (width / height) is now enforced strictly: • width ≤ panel width • height ≤ 0.60 × panel height (empirical upper‑bound you already used) • width / height == panel_dict["figure_aspect"]
(panel_dict, figure_model_params, section_title_height=32)
| 326 | return panel_model_params, figure_model_params |
| 327 | |
| 328 | def place_text_and_figures_exact(panel_dict, figure_model_params, section_title_height=32): |
| 329 | """ |
| 330 | Lay out text and figure boxes inside a panel. |
| 331 | |
| 332 | The figure’s aspect ratio (width / height) is now enforced strictly: |
| 333 | • width ≤ panel width |
| 334 | • height ≤ 0.60 × panel height (empirical upper‑bound you already used) |
| 335 | • width / height == panel_dict["figure_aspect"] |
| 336 | """ |
| 337 | # ---------------- Constants used for text layout ----------------- |
| 338 | char_width_px = 7 |
| 339 | line_height_px = 16 |
| 340 | chars_per_line = max(int(panel_dict["width"] / char_width_px), 1) |
| 341 | |
| 342 | total_lines_text = np.ceil(panel_dict["text_len"] / chars_per_line) |
| 343 | total_text_height = total_lines_text * line_height_px |
| 344 | |
| 345 | x_p, y_p = panel_dict["x"], panel_dict["y"] |
| 346 | w_p, h_p = panel_dict["width"], panel_dict["height"] |
| 347 | |
| 348 | figure_boxes, text_boxes = [], [] |
| 349 | |
| 350 | panel_name_lower = panel_dict["panel_name"].lower() |
| 351 | has_title_in_name = "title" in panel_name_lower |
| 352 | |
| 353 | # ------------------------------------------------------- |
| 354 | # Helper to build a text‑box dict |
| 355 | # ------------------------------------------------------- |
| 356 | def make_text_box(panel_id, x, y, width, height, textbox_id, textbox_name): |
| 357 | return { |
| 358 | "panel_id": panel_id, |
| 359 | "x": float(x), |
| 360 | "y": float(y), |
| 361 | "width": float(width), |
| 362 | "height": float(height), |
| 363 | "textbox_id": textbox_id, |
| 364 | "textbox_name": textbox_name, |
| 365 | } |
| 366 | |
| 367 | # ----------------------------------------------------------------------- |
| 368 | # Case 1 — no figure in this panel |
| 369 | # ----------------------------------------------------------------------- |
| 370 | if panel_dict["figure_size"] <= 0: |
| 371 | if has_title_in_name: |
| 372 | text_boxes.append( |
| 373 | make_text_box(panel_dict["panel_id"], x_p, y_p, w_p, h_p, |
| 374 | textbox_id=0, |
| 375 | textbox_name=f'p<{panel_dict["panel_name"]}>_t0') |
| 376 | ) |
| 377 | else: |
| 378 | title_h = min(section_title_height, h_p) |
| 379 | text_boxes.extend([ |
| 380 | make_text_box(panel_dict["panel_id"], x_p, y_p, w_p, title_h, |
| 381 | textbox_id=0, |
| 382 | textbox_name=f'p<{panel_dict["panel_name"]}>_t0'), |
| 383 | make_text_box(panel_dict["panel_id"], x_p, y_p + title_h, w_p, h_p - title_h, |
| 384 | textbox_id=1, |
| 385 | textbox_name=f'p<{panel_dict["panel_name"]}>_t1'), |
no test coverage detected