Skip to content

Commit

Permalink
Plotting with html backend: fix z-index ordering, make framed=opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Sep 27, 2024
1 parent dc95393 commit 8a4ae1f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
23 changes: 19 additions & 4 deletions src/printbox-ext-plot/PrintBox_ext_plot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ let text_handler ext ~nested:_ =
specs)
| _ -> B.Unrecognized_extension

let embed_canvas_html ~nested canvas =
let embed_canvas_html ~num_specs ~nested canvas =
let size_y = Array.length canvas in
let size_x = Array.length canvas.(0) in
let cells =
Expand All @@ -369,7 +369,21 @@ let embed_canvas_html ~nested canvas =
row
|> Array.mapi (fun x cell ->
List.map
(fun (_prio, cell) ->
(fun (priority, cell) ->
let is_framed =
match PrintBox.view cell with
| B.Frame _ | B.Grid (`Bars, _) -> true
| _ -> false
in
let frame =
if is_framed then
";background-color:rgba(255,255,255,1)"
else
""
in
let z_index =
";z-index:" ^ Int.to_string (num_specs - priority)
in
let cell =
match nested cell with
| PrintBox_html.Render_html html -> html
Expand All @@ -383,7 +397,8 @@ let embed_canvas_html ~nested canvas =
[
H.a_style
("position:absolute;top:" ^ Int.to_string y
^ "px;left:" ^ Int.to_string x ^ "px");
^ "px;left:" ^ Int.to_string x ^ "px" ^ z_index
^ frame);
]
[ cell ])
cell)
Expand All @@ -406,7 +421,7 @@ let html_handler ext ~nested =
B.Same_as
(B.frame
@@ plot ~prec ~no_axes ~size ~x_label ~y_label ~sparse:true
(embed_canvas_html ~nested)
(embed_canvas_html ~num_specs:(List.length specs) ~nested)
specs)
| _ -> B.Unrecognized_extension

Expand Down
4 changes: 2 additions & 2 deletions src/printbox-ext-plot/PrintBox_ext_plot.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type plot_spec =

type graph = {
specs: plot_spec list;
(** Earlier plots in the list take precedence in text rendering: in case of overlap,
their boxes are on top. *)
(** Earlier plots in the list take precedence: in case of overlap, their contents
are on top. For HTML, we ensure that framed boxes and grids with bars are opaque. *)
x_label: string; (** Horizontal axis label. *)
y_label: string; (** Vertical axis label. *)
size: int * int;
Expand Down
2 changes: 1 addition & 1 deletion test/plotting.expected

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/plotting_half_moons.expected

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/plotting_linear.expected

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/plotting_nested.expected

Large diffs are not rendered by default.

0 comments on commit 8a4ae1f

Please sign in to comment.