Skip to content

Commit

Permalink
Fix nested plotting: overlapping boxes were badly mishandled
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Sep 26, 2024
1 parent 1db9608 commit 4f70815
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 52 deletions.
24 changes: 15 additions & 9 deletions src/printbox-ext-plot/PrintBox_ext_plot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ let flatten_text_canvas canvas =
let update ~i ~j line =
if i >= 0 && i < dimi && j >= 0 && j < dimj then (
let visible_len =
min
(dimi - i)
min (dimi - i)
(PrintBox_text.str_display_width line 0 (String.length line))
in
if visible_len > 0 then (
Expand All @@ -332,13 +331,20 @@ let flatten_text_canvas canvas =
done
)
in
Array.iteri
(fun j row ->
Array.iteri
(fun i lines ->
List.iteri (fun dj line -> update ~i ~j:(j + dj) line) lines)
row)
outputs;
(* Traverse in reverse order, so that space-making changes do not get undone. *)
let _ : int =
Array.fold_right
(fun row j ->
let _ : int =
Array.fold_right
(fun lines i ->
List.iteri (fun dj line -> update ~i ~j:(j + dj) line) lines;
i - 1)
row (dimi - 1)
in
j - 1)
outputs (dimj - 1)
in
Array.map
(fun row -> String.concat "" @@ List.filter_map Fun.id @@ Array.to_list row)
canvas
Expand Down
82 changes: 41 additions & 41 deletions test/plotting_nested.expected

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/plotting_nested.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let test ~size =
(0.75, 0.75), nice_unicode;
|];
};
(* Map
Map
{
callback =
(fun (x, y) ->
Expand All @@ -78,7 +78,7 @@ let test ~size =
":"
else
";");
}; *)
};
];
})

Expand Down

0 comments on commit 4f70815

Please sign in to comment.