From 29cdaaa8e5a82160204a2eaeee65831da04177c3 Mon Sep 17 00:00:00 2001 From: Giorgio Calderone Date: Wed, 15 Apr 2020 11:20:49 +0200 Subject: [PATCH] Dropped Dataset as acceptable input; implemented gpvars() --- src/Gnuplot.jl | 51 +++++++++++++++++++++++++++++++++++--------------- src/recipes.jl | 18 +++++++++--------- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/Gnuplot.jl b/src/Gnuplot.jl index b5ccba1..3998c24 100644 --- a/src/Gnuplot.jl +++ b/src/Gnuplot.jl @@ -10,7 +10,7 @@ import Base.display export session_names, dataset_names, palette_names, linetypes, palette, terminal, terminals, test_terminal, stats, @gp, @gsp, save, gpexec, - boxxyerror, contourlines, hist, recipe + boxxyerror, contourlines, hist, recipe, gpvars # ╭───────────────────────────────────────────────────────────────────╮ # │ TYPE DEFINITIONS │ @@ -654,8 +654,8 @@ function reset(gp::Session) gp.datas = OrderedDict{String, Dataset}() gp.plots = [SinglePlot()] gp.curmid = 1 - gpexec(gp, "set output") gpexec(gp, "unset multiplot") + gpexec(gp, "set output") gpexec(gp, "reset session") add_cmd.(Ref(gp), options.reset) return nothing @@ -959,7 +959,6 @@ function parseArguments(_args...) (valtype(arg) <: AbstractString)) ; elseif isa(arg, Real) # ==> a dataset column with only one row args[pos] = [arg] - elseif isa(arg, Dataset) ; # ==> a Dataset object elseif hasmethod(recipe, tuple(typeof(arg))) # ==> implicit recipe @info which(recipe, tuple(typeof(arg))) # debug deleteat!(args, pos) @@ -1010,6 +1009,7 @@ function parseArguments(_args...) ((valtype(arg) <: Real) || (valtype(arg) <: AbstractString)) + # Collect all data accum = Vector{Any}() while isa(arg, AbstractArray) && ((valtype(arg) <: Real) || @@ -1048,18 +1048,6 @@ function parseArguments(_args...) name = "" empty!(cmds) 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) if length(cmds) > 0 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") diff --git a/src/recipes.jl b/src/recipes.jl index 9a8693a..9442cf5 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -17,26 +17,26 @@ recipe(h::Histogram2D) = # -------------------------------------------------------------------- # 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"], data=DatasetBin(256 .* getfield.(M, :r), 256 .* getfield.(M, :g), 256 .* getfield.(M, :b)), 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"], data=DatasetBin(256 .* getfield.(M, :r), 256 .* getfield.(M, :g), 256 .* getfield.(M, :b)), 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"], data=DatasetBin(256 .* getfield.(M, :val)), 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"], data=DatasetBin(256 .* getfield.(M, :val)), plot="rotate=$rot $opt with image notit") @@ -58,11 +58,11 @@ macro recipes_DataFrames() data = Vector{Gnuplot.Dataset}(); plot = Vector{String}(); for g in sort(unique(df[:, group])); - i = findall(df[:, group] .== g); - if length(i) > 0; - push!(data, Gnuplot.DatasetText(df[i, colx], df[i, coly])); - push!(plot, "w p t '$g'"); - end; + i = findall(df[:, group] .== g); + if length(i) > 0; + push!(data, Gnuplot.DatasetText(df[i, colx], df[i, coly])); + push!(plot, "w p t '$g'"); + end; end; return Gnuplot.PlotElement(xlab=string(colx), ylab=string(coly), data=data, plot=plot);