Skip to content

Commit ac79b5d

Browse files
authored
Expand the colorbar syntax to =(xlabel=..., triangles=...) (#1877)
* Expand the colorbar syntax to =(xlabel=..., triangles=...) * Fix test * Another test fix attempt.
1 parent 5d9d2ba commit ac79b5d

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

src/finish_PS_nested.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,9 @@ function add_opt_module(d::Dict)::Vector{String}
7070
r = add_opt_module_barr2(symb)
7171
elseif (symb == :colorbar && (isa(val, StrSymb)))
7272
# Accepts Top/TopTri[High|Low], Bottom/BottomTri, Left/LeftTri, Right/RightTri or triangles (caseless)
73-
val_str::String = lowercase(string(val))
7473
opt_RJ = !IamModern[] ? CTRL.pocket_R[1] * " -J" : ""
75-
anc = "RM"; tris = "" # Default anchor Right Middle and no triangles
76-
if (contains(val_str, "tri") && !isempty(CURRENT_CPT[])) # Sets CPT.bfn to match colormap end colors
77-
CURRENT_CPT[].bfn[1,:] .= CURRENT_CPT[].colormap[1,:]
78-
CURRENT_CPT[].bfn[2,:] .= CURRENT_CPT[].colormap[end,:]
79-
tris = contains(val_str, "high") ? "+ef" : contains(val_str, "low") ? "+eb" : "+e"
80-
end
81-
if (!startswith(val_str, "tri")) # Means that not just triangles were requested
82-
t::Char = val_str[1] # Accept "Top, Bot, Left" but default to Right
83-
anc = (t == 't') ? "TC" : (t == 'b' ? "BC" : (t == 'l' ? "LM" : "RM"))
84-
end
85-
r = "psscale $opt_RJ -Baf -C -DJ" * anc * tris
74+
anc_tris = colorbar_triangles(val)
75+
r = "psscale $opt_RJ -Baf -C -DJ" * anc_tris
8676
elseif (symb == :clip)
8777
if (isa(val, String) || isa(val, Symbol)) # Accept also "land", "water" or "ocean" or DCW country codes(s) or a hard -E string
8878
_str::String = string(val) # Shoot the Any
@@ -108,6 +98,23 @@ function add_opt_module(d::Dict)::Vector{String}
10898
return out
10999
end
110100

101+
# ---------------------------------------------------------------------------------------------------
102+
function colorbar_triangles(val::StrSymb)::String
103+
# Accepts Top/TopTri[High|Low], Bottom/BottomTri, Left/LeftTri, Right/RightTri or triangles (caseless)
104+
val_str::String = lowercase(string(val))
105+
anc = "RM"; tris = "" # Default anchor Right Middle and no triangles
106+
if (contains(val_str, "tri") && !isempty(CURRENT_CPT[])) # Sets CPT.bfn to match colormap end colors
107+
CURRENT_CPT[].bfn[1,:] .= CURRENT_CPT[].colormap[1,:]
108+
CURRENT_CPT[].bfn[2,:] .= CURRENT_CPT[].colormap[end,:]
109+
tris = contains(val_str, "high") ? "+ef" : contains(val_str, "low") ? "+eb" : "+e"
110+
end
111+
if (!startswith(val_str, "tri")) # Means that not just triangles were requested
112+
t::Char = val_str[1] # Accept "Top, Bot, Left" but default to Right
113+
anc = (t == 't') ? "TC" : (t == 'b' ? "BC" : (t == 'l' ? "LM" : "RM"))
114+
end
115+
return anc * tris
116+
end
117+
111118
# Add to split code from above in these 2 function barriers to avoid all finish_PS_nested() invalidations
112119
function add_opt_module_barr2(symb::Symbol)::Union{String, Vector{String}}
113120
r::Union{String, Vector{String}} = ""

src/psscale.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ function colorbar_parser(arg1::Union{Nothing, GMTcpt}=nothing; first=true, kwarg
7474
(!isempty(opt_D)) && (!contains(opt_D, "DJ") && !contains(opt_D, "Dj") && !contains(opt_D, "Dg")) && (cmd = replace(cmd, "-R " => ""))
7575
cmd *= opt_D
7676
cmd, arg1, = add_opt_cpt(d, cmd, CPTaliases, 'C', 0, arg1)
77+
if (opt_D === "" && ((val = hlp_desnany_str(d, [:triangles])) !== "")) # User asked for triangles but did not set pos
78+
(val == "true") && (val = "tri") # Means just triangles
79+
anc_tris = colorbar_triangles(val) # Returns anchor+triangles string
80+
cmd *= " -DJ" * anc_tris
81+
end
7782
if (!isa(arg1, GMTcpt) && !occursin("-C", cmd)) # If given no CPT, try to see if we have a current one stored in global
7883
if (!isempty(CURRENT_CPT[]))
7984
cmd *= " -C"; arg1 = CURRENT_CPT[]
@@ -82,7 +87,7 @@ function colorbar_parser(arg1::Union{Nothing, GMTcpt}=nothing; first=true, kwarg
8287

8388
cmd = add_opt(d, cmd, "L", [:L :equal :equal_size], (range="i", gap="")) # Aditive
8489
(opt_B != "" && !contains(cmd, " -L")) && (cmd *= opt_B) # If no -B & no -L, add default -B
85-
isempty(opt_D) && (cmd *= " -DJMR") # So that we can call it with just a CPT
90+
(isempty(opt_D) && !contains(cmd, " -D")) && (cmd *= " -DJMR") # So that we can call it with just a CPT
8691

8792
cmd = gmt_proggy * cmd
8893
r = check_dbg_print_cmd(d, cmd)

test/test_cube.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ xyzw2cube("test_cube_ascii_rowlevmaj.dat")[:,:,2] == [20.0 20.0 20.0; 20.0 20
4242
xyzw2cube("test_cube_ascii_collevmaj.dat")[:,:,2] == [20.0 20.0 20.0; 20.0 20.0 20.0]
4343
xyzw2cube(gmtread("test_cube_ascii_rowmaj.dat"))[:,:,1] == [10.0 10.0 10.0; 10.0 10.0 10.0]
4444

45-
cubeplot(cube, title="T annual", colorbar=("xlabel=bbb","ylabel=yy"))
45+
cubeplot(cube, title="T annual", colorbar=("xlabel=bbb", "ylabel=yy"))
4646
cubeplot(cube, inset=(3,3))
4747
cubeplot(cube, top="@earth_relief_05m", coast=true, inset=(3,3))
4848
cubeplot(cube, top="@earth_relief_05m", topshade=true)

test/test_views.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ grdimage("@earth_relief_01d_g", clim=[-4000 4000], Vd=dbg2)
2323
grdimage("lixo.grd", coast=true, colorbar=true, logo=true, Vd=dbg2)
2424
G = gmt("grdmath -Rg -fg -I5 X");
2525
gmtwrite("lixo.grd", G)
26-
grdimage("lixo.grd", proj=:Winkel, colorbar=true, coast=true)
26+
grdimage("lixo.grd", proj=:Winkel, colorbar=(xlabel="test", triangles=true), logo=true, coast=true)
2727
@test startswith(grdimage("@earth_relief", region=(-74,-59,5,15), proj=:guess, Vd=2), "grdimage @earth_relief -R-74/-59/5/15")
2828

2929
G2 = mat2grid(rand(181,361), x=-180:180, y=-90:90);

0 commit comments

Comments
 (0)