Skip to content

Commit 8daa38f

Browse files
authored
Merge pull request #1974 from GenericMappingTools/fixes-4-plot-side-by-side
Fixes needed to let two grdimages plot side-by side and no need to set size.
2 parents 0cbbd8f + 181122f commit 8daa38f

4 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/GMT.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ using .Laszip
387387
t = joinpath(tempdir(), "lixo.dat")
388388
gmtwrite(t, [0.0 0; 1 1])
389389
gmtread(t)
390-
gmtread(TESTSDIR * "assets/burro_cenora.jpg")
390+
gmtread(tests("burro_cenora.jpg"))
391+
basemap(R=:d, proj=:guess)
391392
coast(R=:g, proj=:guess, W=(level=1, pen=(2, :green)), savefig=tempname()*".ps")
392393
rm(t)
393394
D = mat2ds(rand(3, 3), colnames=["Time", "b", "c"])

src/common_options.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ function parse_J(d::Dict, cmd::String; default::String="", map::Bool=true, O::Bo
482482
# If MAP == false, do not try to append a fig size
483483

484484
(SHOW_KWARGS[]) && return (print_kwarg_opts([:J :proj :projection], "NamedTuple | String"), "")
485+
if (!O) CTRL.pocket_J[1], CTRL.pocket_J[2], CTRL.pocket_J[3], CTRL.pocket_J[4] = "", "", "", " " end # Start fresh
485486

486487
opt_J::String = ""; mnemo::Bool = false
487488
if ((val = find_in_dict(d, [:J :proj :projection], del)[1]) !== nothing)
@@ -530,17 +531,17 @@ function parse_J(d::Dict, cmd::String; default::String="", map::Bool=true, O::Bo
530531
else # For when a new size is entered in a middle of a script
531532
if ((s = helper_append_figsize(d, opt_J, O, del)) != "")
532533
if (opt_J == " -J")
533-
(CTRL.pocket_J[1] != s) && # Composed funs (ex: fill_between) would trigger this warning
534+
if (CTRL.pocket_J[1] != s) # Composed funs (ex: fill_between) would trigger this warning
534535
println("SEVERE WARNING: When appending a new fig with a different size you SHOULD set the `projection`. \n\tAdding `projection=:linear` at your own risk.");
535-
opt_J *= "X" * s[4:end]::String
536+
opt_J *= "X" * s[4:end]::String
537+
else
538+
opt_J *= (O ? "" : "X") * s[4:end]::String # When overlaying use current projection, otherwise use linear
539+
end
536540
else
537541
opt_J = s
538542
end
539543
end
540544
end
541-
#if (CTRL.proj_linear[1]) # If CTRL.proj_linear[1] == false, trust it
542-
#CTRL.proj_linear[1] = (length(opt_J) >= 4 && opt_J[4] != 'X' && opt_J[4] != 'x' && opt_J[4] != 'Q' && opt_J[4] != 'q') ? false : true
543-
#end
544545

545546
(opt_J == " ") && (opt_J = "") # We use " " when wanting to prevent the default -J
546547
fish_size_from_J(opt_J) # So far we only need this in plot(hexbin)
@@ -606,6 +607,8 @@ end
606607

607608
function helper_append_figsize(d::Dict, opt_J::String, O::Bool, del::Bool=true)::String
608609
val_, symb = find_in_dict(d, [:figscale :fig_scale :scale :figsize :fig_size], del)
610+
# Use the current figure size in overlay mode when we pass a projection but no size in it.
611+
(O && val_ === nothing && CTRL.pocket_J[2] != "" && length(opt_J) > 3 && !endswith(opt_J, CTRL.pocket_J[2])) && (val_ = CTRL.pocket_J[2])
609612
(val_ === nothing && is_in_dict(d, [:flipaxes :flip_axes]) === nothing) && return ""
610613
val::String = arg2str(val_)
611614
if (occursin("scale", arg2str(symb))) # We have a fig SCALE request
@@ -616,18 +619,18 @@ function helper_append_figsize(d::Dict, opt_J::String, O::Bool, del::Bool=true):
616619
if (opt_J == " -JX")
617620
val = check_flipaxes(d, val)
618621
opt_J::String = isletter(val[1]) ? " -J" * val : " -Jx" * val # FRAGILE
619-
else opt_J = append_figsize(d, opt_J, val, true)
622+
else opt_J = append_figsize(d, opt_J, val, true, false)
620623
end
621624
else # A fig SIZE request
622625
(haskey(d, :units)) && (val *= d[:units][1]::String)
623626
if (occursin("+proj", opt_J)) opt_J *= "+width=" * val
624-
else opt_J = append_figsize(d, opt_J, val)
627+
else opt_J = append_figsize(d, opt_J, val, false, O)
625628
end
626629
end
627630
return opt_J
628631
end
629632

630-
function append_figsize(d::Dict, opt_J::String, width::String="", scale::Bool=false)::String
633+
function append_figsize(d::Dict, opt_J::String, width::String="", scale::Bool=false, O::Bool=false)::String
631634
# Appending either a fig width or fig scale depending on what projection.
632635
# Sometimes we need to separate with a '/' others not. If WIDTH == "" we
633636
# use the DEF_FIG_SIZE, otherwise use WIDTH that can be a size or a scale.
@@ -668,8 +671,13 @@ function append_figsize(d::Dict, opt_J::String, width::String="", scale::Bool=fa
668671
end
669672
end
670673
end
674+
671675
width = check_flipaxes(d, width)
672-
opt_J *= slash * width * de
676+
if (O && (opt_J == " -J") && (CTRL.pocket_J[2] !== ""))
677+
opt_J = replace(CTRL.pocket_J[1], CTRL.pocket_J[2] => width)
678+
else
679+
opt_J *= slash * width * de
680+
end
673681
CTRL.pocket_J[1], CTRL.pocket_J[2] = opt_J, width # Save these for eventual (in -B) change if flip dims dir
674682
if (scale) opt_J = opt_J[1:3] * lowercase(opt_J[4]) * opt_J[5:end] end # Turn " -JX" to " -Jx"
675683
return opt_J
@@ -770,7 +778,7 @@ end
770778

771779
function build_opt_J(val)::Tuple{String, Bool}
772780
out::String = ""; mnemo = false
773-
if (isa(val, String) || isa(val, Symbol))
781+
if (isa(val, StrSymb))
774782
val_s::String = string(val)
775783
if (val_s == "guess")
776784
out, mnemo = guess_proj(CTRL.limits[7:8], CTRL.limits[9:10]), true
@@ -4169,7 +4177,7 @@ function dbg_print_cmd(d::Dict{Symbol,Any}, cmd::Vector{String})
41694177
if (Vd >= 2) # Delete these first before reporting
41704178
delete!(d, [[:show], [:leg, :legend, :l], [:box_pos], [:leg_pos], [:figname], [:name], [:savefig]])
41714179
pocket_call[][3] = nothing # This is mostly for testing purposes, but potentially needed elsewhere.
4172-
CTRL.limits[1:12] = zeros(12)
4180+
#CTRL.limits[1:12] = zeros(12)
41734181
# Some times an automtic CPT has been generated by the Vd'ed cmd but when that happens MUST debug it
41744182
#CURRENT_CPT[] = GMTcpt() # Can't do this because it would f. plot(..., colorbar=true)
41754183
end

test/test_common_opts.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
@test GMT.parse_J(Dict{Symbol,Any}(:J => (name=:Cyl_,center=(0,45))), "", default="", map=false)[1] == " -JCyl_stere/0/45"
7373
@test_throws ErrorException("When projection arguments are in a NamedTuple the projection 'name' keyword is madatory.") GMT.parse_J(Dict{Symbol,Any}(:J => (parallels=[45 65],)), "", default="", map=false)
7474
@test_throws ErrorException("When projection is a named tuple you need to specify also 'center' and|or 'parallels'") GMT.parse_J(Dict{Symbol,Any}(:J => (name=:merc,)), "", default="", map=false)
75+
basemap(R=:d, proj=:guess, figsize=8);
76+
@test basemap!(R=:d, X=10, B=:same, proj=:guess, show=1, Vd=2) == "psbasemap -Rd -JN0.0/8 -B -X10"
7577
r = GMT.parse_params(Dict{Symbol,Any}(:par => (MAP_FRAME_WIDTH=0.2, IO=:lixo, OI="xoli")), "");
7678
@test r == " --MAP_FRAME_WIDTH=0.2 --IO=lixo --OI=xoli"
7779
@test GMT.parse_params(Dict{Symbol,Any}(:par => (:MAP_FRAME_WIDTH,0.2)), "") == " --MAP_FRAME_WIDTH=0.2"

test/test_mgd77.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@testset "MAGREF" begin
2+
resetGMT(); # Make sure we start with a clean slate
23
@test magref(R=[-180,180,-90,90], I=0.25, onetime=2000, alt=10, F=:H, Vd=dbg2) == "mgd77magref -A+t2000+a10+y -Frh/H"
34
@test magref([0. 0], onetime=2000, alt=10, H=1, Vd=dbg2) == "mgd77magref -A+t2000+a10+y -Fh/0"
45
@test magref([0. 0], alt=10, H=1, CM4core=true, Vd=dbg2) == "mgd77magref -A+a10 -Fh/1"

0 commit comments

Comments
 (0)