Skip to content

Commit

Permalink
Merge pull request #1531 from GenericMappingTools/temp_changes
Browse files Browse the repository at this point in the history
Revert the cat_1_arg story again because it lacked colnames.  Move a chunk code is psxy to a function.
  • Loading branch information
joa-quim authored Sep 17, 2024
2 parents 04d92b5 + c3b561c commit c297bd6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/gmt_main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,10 @@ info(C::GMTcpt) = show(C)
# ---------- For Pluto ------------------------------------------------------------------------------
Base.:show(io::IO, mime::MIME"image/png", wp::WrapperPluto) = write(io, read(wp.fname))

# ---------- For Tables -----------------------------------------------------------------------------
Base.:names(D::GDtype) = isa(D, Vector) ? D[1].colnames : D.colnames
#Base.:names(D::GMTdataset) = D.colnames
#Base.:names(D::Vector{GMTdataset}) = D[1].colnames

# ---------- For fck stop printing UInts in hexadecinal ---------------------------------------------
#Base.show(io::IO, x::T) where {T<:Union{UInt, UInt128, UInt64, UInt32, UInt16, UInt8}} = Base.print(io, x)
6 changes: 5 additions & 1 deletion src/gmt_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,17 @@ GMTdataset(data::Array{Float32,2}) =

#=
Base.@kwdef struct GMTtypes
stored::Int = 0
stored::String = ""
grd::GMTgrid = GMTgrid()
img::GMTimage = GMTimage()
ds::GMTdataset = GMTdataset()
dsv::Vector{GMTdataset} = [GMTdataset()]
cpt::GMTcpt = GMTcpt()
ps::GMTps = GMTps()
function GMTtypes(stored, grd, img, ds, dsv, cpt, ps)
stored = (!isempty(grd)) ? "grd" : (!isempty(img)) ? "img" : (!isempty(ds)) ? "ds" : (!isempty(dsv)) ? "dsv" : (!isempty(cpt)) ? "cpt" : (!isempty(ps)) ? "ps" : ""
new(stored, grd, img, ds, dsv, cpt, ps)
end
end
=#

Expand Down
2 changes: 1 addition & 1 deletion src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ function cat_1_arg(arg, toDS::Bool=false)
elseif (isdataframe(arg) || isODE(arg))
return arg
end
return toDS ? set_dsBB(GMTdataset(data=arg)) : arg
return toDS ? mat2ds(arg) : arg
end

# ------------------------------------------------------------------------------------------------------
Expand Down
42 changes: 25 additions & 17 deletions src/psxy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,7 @@ function common_plot_xyz(cmd0::String, arg1, caller::String, first::Bool, is3D::

_cmd = fish_bg(d, _cmd) # See if we have a "pre-command"

if (isa(arg1, GDtype) && (((val = find_in_dict(d, [:labels])[1])) !== nothing)) # Plot TEXT attributed labels
s_val::String = string(val)::String
(!startswith(s_val, "att") || ((ind = findfirst("=", s_val)) === nothing) && (ind = findfirst(':', s_val)) === nothing) &&
error("The labels option must be 'labels=att=???' or 'labels=attrib=???'")
ts::String = s_val[ind+1:end]
ct::GMTdataset = centroid(arg1) # Texts will be plotted at the polygons centroids
ct.text = info(arg1, att=ts)
(CTRL.pocket_call[1] === nothing) ? (CTRL.pocket_call[1] = ct) : (CTRL.pocket_call[2] = ct)
if ((fnt = add_opt(d, "", "", [:font], (angle="+a", font=("+f", font)), false, true)) != "")
(fnt[1] != '+') && (fnt = "+f" * fnt)
delete!(d, :font)
else
nc::Int = round(Int, sqrt(length(arg1))) # A crude guess of the number of columns
fnt = (nc < 5) ? "+f8p" : (nc < 9 ? "+f6p" : "+f5p") # A simple heuristic
end
append!(_cmd, ["pstext -R -J -F" * fnt * "+jMC"])
end
isa(arg1, GDtype) && plt_txt_attrib!(arg1, d, _cmd) # Function barrier to plot TEXT attributed labels (in case)

finish = (is_ternary && occursin(" -M",_cmd[1])) ? false : true # But this case (-M) is bugged still in 6.2.0
r = finish_PS_module(d, _cmd, "", K, O, finish, arg1, arg2, arg3, arg4)
Expand All @@ -354,6 +338,30 @@ function common_plot_xyz(cmd0::String, arg1, caller::String, first::Bool, is3D::
return r
end

# ---------------------------------------------------------------------------------------------------
function plt_txt_attrib!(D::GDtype, d::Dict, _cmd::Vector{String})
# Plot TEXT attributed labels and serve as function barrier agains to f Anys
((val = find_in_dict(d, [:labels])[1]) === nothing) && return nothing

s_val::String = string(val)
(!startswith(s_val, "att") || ((ind = findfirst("=", s_val)) === nothing) && (_ind = findfirst(':', s_val)) === nothing) &&
error("The labels option must be 'labels=att=???' or 'labels=attrib=???'")
ind::Int = _ind # Because it fck insists _ind is a Any
ts::String = s_val[ind+1:end]
ct::GMTdataset = centroid(D) # Texts will be plotted at the polygons centroids
ct.text = info(D, att=ts)
(CTRL.pocket_call[1] === nothing) ? (CTRL.pocket_call[1] = ct) : (CTRL.pocket_call[2] = ct)
if ((fnt = add_opt(d, "", "", [:font], (angle="+a", font=("+f", font)), false, true)) != "")
(fnt[1] != '+') && (fnt = "+f" * fnt)
delete!(d, :font)
else
nc::Int = round(Int, sqrt(length(D))) # A crude guess of the number of columns
fnt = (nc < 5) ? "+f8p" : (nc < 9 ? "+f6p" : "+f5p")# A simple heuristic
end
append!(_cmd, ["pstext -R -J -F" * fnt * "+jMC"])
return nothing
end

# ---------------------------------------------------------------------------------------------------
function deal_faceverts(arg1, d, opt_p)
# Deal with the situation where we are plotting 3D FV's
Expand Down

0 comments on commit c297bd6

Please sign in to comment.