Update gaston.jl

This commit is contained in:
t-bltg 2021-08-01 09:47:36 +02:00 committed by GitHub
parent 478868a6a2
commit f49f5d1638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,8 +51,8 @@ end
function _update_plot_object(plt::Plot{GastonBackend}) function _update_plot_object(plt::Plot{GastonBackend})
# respect the layout ratio # respect the layout ratio
xy_wh = gaston_multiplot_pos_size(plt.layout, (0, 0, 1, 1)) dat = gaston_multiplot_pos_size(plt.layout, (0, 0, 1, 1))
gaston_multiplot_pos_size!(0, xy_wh) gaston_multiplot_pos_size!(dat)
end end
for (mime, term) ( for (mime, term) (
@ -148,13 +148,13 @@ end
function gaston_multiplot_pos_size(layout, parent_xy_wh) function gaston_multiplot_pos_size(layout, parent_xy_wh)
nr, nc = size(layout) nr, nc = size(layout)
xy_wh_sp = Array{Any}(nothing, nr, nc) dat = Array{Any}(nothing, nr, nc)
for r 1:nr, c 1:nc # NOTE: col major for r 1:nr, c 1:nc # NOTE: col major
l = layout[r, c] l = layout[r, c]
if !isa(l, EmptyLayout) if !isa(l, EmptyLayout)
# previous position (origin) # previous position (origin)
prev_r = r > 1 ? xy_wh_sp[r - 1, c] : nothing prev_r = r > 1 ? dat[r - 1, c] : nothing
prev_c = c > 1 ? xy_wh_sp[r, c - 1] : nothing prev_c = c > 1 ? dat[r, c - 1] : nothing
prev_r isa Array && (prev_r = prev_r[end, end]) prev_r isa Array && (prev_r = prev_r[end, end])
prev_c isa Array && (prev_c = prev_c[end, end]) prev_c isa Array && (prev_c = prev_c[end, end])
x = prev_c !== nothing ? prev_c[1] + prev_c[3] : parent_xy_wh[1] x = prev_c !== nothing ? prev_c[1] + prev_c[3] : parent_xy_wh[1]
@ -164,21 +164,21 @@ function gaston_multiplot_pos_size(layout, parent_xy_wh)
h = layout.heights[r].value * parent_xy_wh[4] h = layout.heights[r].value * parent_xy_wh[4]
if l isa GridLayout if l isa GridLayout
sub = gaston_multiplot_pos_size(l, (x, y, w, h)) sub = gaston_multiplot_pos_size(l, (x, y, w, h))
xy_wh_sp[r, c] = size(sub) == (1, 1) ? only(sub) : sub dat[r, c] = size(sub) == (1, 1) ? only(sub) : sub
else else
xy_wh_sp[r, c] = x, y, w, h, l dat[r, c] = x, y, w, h, l
end end
end end
end end
return xy_wh_sp return dat
end end
function gaston_multiplot_pos_size!(n::Int, dat) function gaston_multiplot_pos_size!(dat)
nr, nc = size(dat) nr, nc = size(dat)
for c 1:nc, r 1:nr # NOTE: row major for c 1:nc, r 1:nr # NOTE: row major
xy_wh_sp = dat[r, c] xy_wh_sp = dat[r, c]
if xy_wh_sp isa Array if xy_wh_sp isa Array
n = gaston_multiplot_pos_size!(n, xy_wh_sp) gaston_multiplot_pos_size!(n, xy_wh_sp)
elseif xy_wh_sp isa Tuple elseif xy_wh_sp isa Tuple
x, y, w, h, sp = xy_wh_sp x, y, w, h, sp = xy_wh_sp
sp === nothing && continue sp === nothing && continue
@ -186,7 +186,7 @@ function gaston_multiplot_pos_size!(n::Int, dat)
sp.o.axesconf = "set origin $x,$y\nset size $w,$h\n" * sp.o.axesconf sp.o.axesconf = "set origin $x,$y\nset size $w,$h\n" * sp.o.axesconf
end end
end end
return n nothing
end end
function gaston_add_series(plt::Plot{GastonBackend}, series::Series) function gaston_add_series(plt::Plot{GastonBackend}, series::Series)