Skip to content

Commit

Permalink
Merge pull request #1215 from GenericMappingTools/patch-XY-shift
Browse files Browse the repository at this point in the history
A patch to minimize GMT bug when MAP_ORIGIN_X|Y is set in modern mode
  • Loading branch information
joa-quim authored Jul 11, 2023
2 parents 0bec901 + 3fbdf4b commit 08959ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/common_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function parse_R(d::Dict, cmd::String, O::Bool=false, del::Bool=true, RIr::Bool=
CTRL.limits[7:7+length(limits)-1] = limits # The plot limits
(opt_R != " -Rtight" && opt_R !== nothing && limits != zeros(4) && all(CTRL.limits[1:4] .== 0)) &&
(CTRL.limits[1:length(limits)] = limits) # And this makes data = plot limits, IF data is empty.
contains(opt_R, "+r") && (CTRL.limits[13] = 1.0)# To know that -R...+r was used.
catch
CTRL.limits .= 0.0
end
Expand Down Expand Up @@ -337,7 +338,8 @@ function opt_R2num(opt_R::String)
#contains(rs[2], "T") || contains(rs[2], "t")
limits[1] = parse(Float64, rs[1][fst+1:end])
for k = 2:lastindex(rs) limits[k] = parse(Float64, rs[k]) end
if (isdiag) limits[2], limits[4] = limits[4], limits[2] end
#if (isdiag) limits[2], limits[4] = limits[4], limits[2] end
# Don't know anymore how -R...+r limits should be stored in CTRL.limits
elseif (opt_R != " -R" && opt_R != " -Rtight") # One of those complicated -R forms. Ask GMT the limits (but slow. It takes 0.2 s)
kml::GMTdataset = gmt("gmt2kml " * opt_R, [0 0])
limits = zeros(4)
Expand Down
8 changes: 6 additions & 2 deletions src/gmt_main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ function gmt(cmd::String, args...)
#(r == "") && (r = isFranklin[1] ? (joinpath(tempdir(), "GMTjl_tmp png")) : "GMTplot " * FMT[1]::String)
(r == "") && (r = isFranklin[1] ? (tmpdir_usr[1] * "/" * "GMTjl_" * tmpdir_usr[2] * " png") : "GMTplot " * FMT[1]::String)
IamModern[1] = true
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "0") # Workarround GMT bug.
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "0")
elseif (g_module == "end") # Last command of a MODERN session
(r == "") && (r = "-Vq") # Cannot have a no-args for this case otherwise it prints help
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "20c")
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "20c")
elseif (r == "" && n_argin == 0) # Just requesting usage message, add -? to options
r = "-?"
elseif (n_argin > 1 && (g_module == "psscale" || g_module == "colorbar")) # Happens with nested calls like in grdimage
Expand Down Expand Up @@ -240,8 +244,8 @@ end
# -----------------------------------------------------------------------------------------------
function extra_sets()
gmtlib_setparameter(G_API[1], "MAP_DEFAULT_PEN", "0.5p,black") # Change the default 0.25 pen thickness in -W
gmtlib_setparameter(G_API[1], "COLOR_NAN", "255") # Stop those ugly grays
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "20c") # Change the origin offset
gmtlib_setparameter(G_API[1], "COLOR_NAN", "255") # Stop those ugly grays
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "20c") # Change the origin offset
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "20c")
gmtlib_setparameter(G_API[1], "MAP_EMBELLISHMENT_MODE", "auto")
end
Expand Down
5 changes: 5 additions & 0 deletions src/themes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ function theme_modern()
resetdefaults(G_API[1])
gmtlib_setparameter(G_API[1], "MAP_FRAME_PEN", "0.75")
gmtlib_setparameter(G_API[1], "FONT_TITLE", "auto,Times-Roman,black")
gmtlib_setparameter(G_API[1], "FONT_HEADING", "auto,Times-Roman,black")
gmtlib_setparameter(G_API[1], "FONT_SUBTITLE", "auto,Times-Roman,black")
!IamModern[1] && swapmode(G_API[1], classic=true) # Reset GMT->current.setting.run_mode = GMT_CLASSIC
if (IamModern[1])
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_X", "0") # Workarround GMT bug.
gmtlib_setparameter(G_API[1], "MAP_ORIGIN_Y", "0")
end
return nothing
end

Expand Down

0 comments on commit 08959ee

Please sign in to comment.