From 0b989cd33edf390a0ca40197002d97ce2c93e6c4 Mon Sep 17 00:00:00 2001 From: t-bltg <13423344+t-bltg@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:04:09 +0200 Subject: [PATCH] Gaston: rework multiplot --- src/backends/gaston.jl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/backends/gaston.jl b/src/backends/gaston.jl index 484bf247..324b989a 100644 --- a/src/backends/gaston.jl +++ b/src/backends/gaston.jl @@ -149,9 +149,14 @@ end function gaston_multiplot_pos_size(layout, parent_xy_wh) nr, nc = size(layout) dat = Array{Any}(nothing, nr, nc) - for r ∈ 1:nr, c ∈ 1:nc # NOTE: col major + for r ∈ 1:nr, c ∈ 1:nc l = layout[r, c] - if !isa(l, EmptyLayout) + # width and height (pct) are multiplicative (parent) + w = layout.widths[c].value * parent_xy_wh[3] + h = layout.heights[r].value * parent_xy_wh[4] + if isa(l, EmptyLayout) + dat[r, c] = (c - 1) * w, (r - 1) * h, w, h, nothing + else # previous position (origin) prev_r = r > 1 ? dat[r - 1, c] : nothing prev_c = c > 1 ? dat[r, c - 1] : nothing @@ -159,9 +164,6 @@ function gaston_multiplot_pos_size(layout, parent_xy_wh) prev_c isa Array && (prev_c = prev_c[end, end]) x = prev_c !== nothing ? prev_c[1] + prev_c[3] : parent_xy_wh[1] y = prev_r !== nothing ? prev_r[2] + prev_r[4] : parent_xy_wh[2] - # width and height (pct) are multiplicative (parent) - w = layout.widths[c].value * parent_xy_wh[3] - h = layout.heights[r].value * parent_xy_wh[4] if l isa GridLayout sub = gaston_multiplot_pos_size(l, (x, y, w, h)) dat[r, c] = size(sub) == (1, 1) ? only(sub) : sub @@ -175,15 +177,17 @@ end function gaston_multiplot_pos_size!(dat) nr, nc = size(dat) - for c ∈ 1:nc, r ∈ 1:nr # NOTE: row major + for r ∈ 1:nr, c ∈ 1:nc xy_wh_sp = dat[r, c] if xy_wh_sp isa Array - gaston_multiplot_pos_size!(n, xy_wh_sp) + gaston_multiplot_pos_size!(xy_wh_sp) elseif xy_wh_sp isa Tuple x, y, w, h, sp = xy_wh_sp sp === nothing && continue sp.o === nothing && continue - sp.o.axesconf = "set origin $x,$y\nset size $w,$h\n" * sp.o.axesconf + @show r, c x, y sp[:title] + # gnuplot screen coordinates: bottom left at 0,0 and top right at 1,1 + sp.o.axesconf = "set origin $x, $(1 - y - h)\nset size $w, $h\n" * sp.o.axesconf end end nothing