Dropped Dataset as acceptable input; implemented gpvars()

This commit is contained in:
Giorgio Calderone 2020-04-15 11:20:49 +02:00
parent 44a7ea2ecd
commit 29cdaaa8e5
2 changed files with 45 additions and 24 deletions

View File

@ -10,7 +10,7 @@ import Base.display
export session_names, dataset_names, palette_names, linetypes, palette, export session_names, dataset_names, palette_names, linetypes, palette,
terminal, terminals, test_terminal, terminal, terminals, test_terminal,
stats, @gp, @gsp, save, gpexec, stats, @gp, @gsp, save, gpexec,
boxxyerror, contourlines, hist, recipe boxxyerror, contourlines, hist, recipe, gpvars
# ╭───────────────────────────────────────────────────────────────────╮ # ╭───────────────────────────────────────────────────────────────────╮
# │ TYPE DEFINITIONS │ # │ TYPE DEFINITIONS │
@ -654,8 +654,8 @@ function reset(gp::Session)
gp.datas = OrderedDict{String, Dataset}() gp.datas = OrderedDict{String, Dataset}()
gp.plots = [SinglePlot()] gp.plots = [SinglePlot()]
gp.curmid = 1 gp.curmid = 1
gpexec(gp, "set output")
gpexec(gp, "unset multiplot") gpexec(gp, "unset multiplot")
gpexec(gp, "set output")
gpexec(gp, "reset session") gpexec(gp, "reset session")
add_cmd.(Ref(gp), options.reset) add_cmd.(Ref(gp), options.reset)
return nothing return nothing
@ -959,7 +959,6 @@ function parseArguments(_args...)
(valtype(arg) <: AbstractString)) ; (valtype(arg) <: AbstractString)) ;
elseif isa(arg, Real) # ==> a dataset column with only one row elseif isa(arg, Real) # ==> a dataset column with only one row
args[pos] = [arg] args[pos] = [arg]
elseif isa(arg, Dataset) ; # ==> a Dataset object
elseif hasmethod(recipe, tuple(typeof(arg))) # ==> implicit recipe elseif hasmethod(recipe, tuple(typeof(arg))) # ==> implicit recipe
@info which(recipe, tuple(typeof(arg))) # debug @info which(recipe, tuple(typeof(arg))) # debug
deleteat!(args, pos) deleteat!(args, pos)
@ -1010,6 +1009,7 @@ function parseArguments(_args...)
((valtype(arg) <: Real) || ((valtype(arg) <: Real) ||
(valtype(arg) <: AbstractString)) (valtype(arg) <: AbstractString))
# Collect all data
accum = Vector{Any}() accum = Vector{Any}()
while isa(arg, AbstractArray) && while isa(arg, AbstractArray) &&
((valtype(arg) <: Real) || ((valtype(arg) <: Real) ||
@ -1048,18 +1048,6 @@ function parseArguments(_args...)
name = "" name = ""
empty!(cmds) empty!(cmds)
continue continue
elseif isa(arg, Dataset) # ==> a Dataset object
deleteat!(args, pos)
spec = ""
if (pos <= length(args)) &&
isa(args[pos], String)
spec = args[pos]
deleteat!(args, pos)
end
push!(elems, PlotElement(mid=mid, cmds=cmds, name=name, data=arg, plot=spec))
name = ""
empty!(cmds)
continue
elseif isa(arg, PlotElement) elseif isa(arg, PlotElement)
if length(cmds) > 0 if length(cmds) > 0
push!(elems, PlotElement(mid=mid, cmds=cmds)) push!(elems, PlotElement(mid=mid, cmds=cmds))
@ -1843,6 +1831,39 @@ end
# ╭───────────────────────────────────────────────────────────────────╮
# │ VARIABLE ACCESS │
# ╰───────────────────────────────────────────────────────────────────╯
# --------------------------------------------------------------------
gpvars() = gpvars(options.default)
function gpvars(sid::Symbol)
gp = getsession(sid)
vars = string.(strip.(split(gpexec("show var all"), '\n')))
out = Dict{Symbol, Union{String, Real}}()
for v in vars
if length(v) > 6
if v[1:6] == "GPVAL_"
s = string.(strip.(split(v[7:end], '=')))
key = Symbol(s[1])
if s[2][1] == '"'
out[key] = s[2][2:end-1]
else
try
out[key] = Meta.parse(s[2])
catch
out[key] = s[2]
end
end
end
end
end
return out
end
include("recipes.jl") include("recipes.jl")

View File

@ -17,26 +17,26 @@ recipe(h::Histogram2D) =
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Images # Images
recipe(M::Matrix{ColorTypes.RGB{T}}; rot="-90deg", opt="") where T = recipe(M::Matrix{ColorTypes.RGB{T}}; rot="-90deg", opt="") where T =
PlotElement(cmds=["set autoscale fix", "set size square"], PlotElement(cmds=["set autoscale fix", "set size square"],
data=DatasetBin(256 .* getfield.(M, :r), data=DatasetBin(256 .* getfield.(M, :r),
256 .* getfield.(M, :g), 256 .* getfield.(M, :g),
256 .* getfield.(M, :b)), 256 .* getfield.(M, :b)),
plot="rotate=$rot $opt with rgbimage notit") plot="rotate=$rot $opt with rgbimage notit")
recipe(M::Matrix{ColorTypes.RGBA{T}}; rot="-90deg", opt="") where T = recipe(M::Matrix{ColorTypes.RGBA{T}}; rot="-90deg", opt="") where T =
PlotElement(cmds=["set autoscale fix", "set size square"], PlotElement(cmds=["set autoscale fix", "set size square"],
data=DatasetBin(256 .* getfield.(M, :r), data=DatasetBin(256 .* getfield.(M, :r),
256 .* getfield.(M, :g), 256 .* getfield.(M, :g),
256 .* getfield.(M, :b)), 256 .* getfield.(M, :b)),
plot="rotate=$rot $opt with rgbimage notit") plot="rotate=$rot $opt with rgbimage notit")
recipe(M::Matrix{ColorTypes.Gray{T}}; rot="-90deg", opt="") where T = recipe(M::Matrix{ColorTypes.Gray{T}}; rot="-90deg", opt="") where T =
PlotElement(cmds=["set autoscale fix", "set size square"], PlotElement(cmds=["set autoscale fix", "set size square"],
data=DatasetBin(256 .* getfield.(M, :val)), data=DatasetBin(256 .* getfield.(M, :val)),
plot="rotate=$rot $opt with image notit") plot="rotate=$rot $opt with image notit")
recipe(M::Matrix{ColorTypes.GrayA{T}}; rot="-90deg", opt="") where T = recipe(M::Matrix{ColorTypes.GrayA{T}}; rot="-90deg", opt="") where T =
PlotElement(cmds=["set autoscale fix", "set size square"], PlotElement(cmds=["set autoscale fix", "set size square"],
data=DatasetBin(256 .* getfield.(M, :val)), data=DatasetBin(256 .* getfield.(M, :val)),
plot="rotate=$rot $opt with image notit") plot="rotate=$rot $opt with image notit")
@ -58,11 +58,11 @@ macro recipes_DataFrames()
data = Vector{Gnuplot.Dataset}(); data = Vector{Gnuplot.Dataset}();
plot = Vector{String}(); plot = Vector{String}();
for g in sort(unique(df[:, group])); for g in sort(unique(df[:, group]));
i = findall(df[:, group] .== g); i = findall(df[:, group] .== g);
if length(i) > 0; if length(i) > 0;
push!(data, Gnuplot.DatasetText(df[i, colx], df[i, coly])); push!(data, Gnuplot.DatasetText(df[i, colx], df[i, coly]));
push!(plot, "w p t '$g'"); push!(plot, "w p t '$g'");
end; end;
end; end;
return Gnuplot.PlotElement(xlab=string(colx), ylab=string(coly), return Gnuplot.PlotElement(xlab=string(colx), ylab=string(coly),
data=data, plot=plot); data=data, plot=plot);