First commit
This commit is contained in:
parent
a5cebaf53e
commit
db094ec85d
@ -12,8 +12,9 @@ export @gp, @gsp, save, linetypes, palette, contourlines, hist, terminal, termin
|
|||||||
# ╰───────────────────────────────────────────────────────────────────╯
|
# ╰───────────────────────────────────────────────────────────────────╯
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
mutable struct DataSet
|
mutable struct DataSet
|
||||||
name::String
|
source::String
|
||||||
lines::Vector{String}
|
preview::String
|
||||||
|
data::String
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ end
|
|||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
@quasiabstract mutable struct DrySession
|
@quasiabstract mutable struct DrySession
|
||||||
sid::Symbol # session ID
|
sid::Symbol # session ID
|
||||||
datas::Vector{DataSet} # data sets
|
datas::Dict{String, DataSet} # data sets
|
||||||
plots::Vector{SinglePlot} # commands and plot commands (one entry for each plot of the multiplot)
|
plots::Vector{SinglePlot} # commands and plot commands (one entry for each plot of the multiplot)
|
||||||
curmid::Int # current multiplot ID
|
curmid::Int # current multiplot ID
|
||||||
end
|
end
|
||||||
@ -264,7 +265,7 @@ end
|
|||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function DrySession(sid::Symbol)
|
function DrySession(sid::Symbol)
|
||||||
(sid in keys(sessions)) && error("Gnuplot session $sid is already active")
|
(sid in keys(sessions)) && error("Gnuplot session $sid is already active")
|
||||||
out = DrySession(sid, Vector{DataSet}(), [SinglePlot()], 1)
|
out = DrySession(sid, Dict{String, DataSet}(), [SinglePlot()], 1)
|
||||||
sessions[sid] = out
|
sessions[sid] = out
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
@ -388,30 +389,12 @@ end
|
|||||||
write(gp::DrySession, d::DataSet) = nothing
|
write(gp::DrySession, d::DataSet) = nothing
|
||||||
function write(gp::GPSession, d::DataSet)
|
function write(gp::GPSession, d::DataSet)
|
||||||
if options.verbose
|
if options.verbose
|
||||||
v = ""
|
printstyled(color=:light_black, d.preview * "\n")
|
||||||
printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) $(d.name) << EOD\n")
|
|
||||||
n = min(options.datalines, length(d.lines))
|
|
||||||
for i in 1:n
|
|
||||||
printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) $(d.lines[i])\n")
|
|
||||||
end
|
end
|
||||||
if n < length(d.lines)
|
out = write(gp.pin, d.data)
|
||||||
printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) ...\n")
|
out += write(gp.pin, "\n")
|
||||||
end
|
|
||||||
printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) EOD\n")
|
|
||||||
end
|
|
||||||
write(gp.pin, "$(d.name) << EOD\n")
|
|
||||||
buf = join(d.lines, "\n") * "\n"
|
|
||||||
#if length(buf) > 1e4
|
|
||||||
# s = "Writing data to gnuplot (length=$(length(buf)) bytes) ..."
|
|
||||||
# printstyled(color=:light_black, s)
|
|
||||||
#end
|
|
||||||
write(gp.pin, buf)
|
|
||||||
write(gp.pin, "EOD\n")
|
|
||||||
flush(gp.pin)
|
flush(gp.pin)
|
||||||
#if length(buf) > 1e4
|
return out
|
||||||
# write(stdout, "\r" * *(fill(" ", length(s))...) * "\r")
|
|
||||||
#end
|
|
||||||
return nothing
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -445,7 +428,7 @@ end
|
|||||||
# ╰───────────────────────────────────────────────────────────────────╯
|
# ╰───────────────────────────────────────────────────────────────────╯
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function reset(gp::DrySession)
|
function reset(gp::DrySession)
|
||||||
gp.datas = Vector{DataSet}()
|
gp.datas = Dict{String, DataSet}()
|
||||||
gp.plots = [SinglePlot()]
|
gp.plots = [SinglePlot()]
|
||||||
gp.curmid = 1
|
gp.curmid = 1
|
||||||
exec(gp, "reset session")
|
exec(gp, "reset session")
|
||||||
@ -464,14 +447,21 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function newdataset(gp::DrySession, accum::Vector{String}; name="")
|
newBlockName(gp::DrySession) = string("\$data", length(gp.datas)+1)
|
||||||
(name == "") && (name = string("\$data", length(gp.datas)+1))
|
|
||||||
d = DataSet(name, accum)
|
|
||||||
push!(gp.datas, d)
|
# ---------------------------------------------------------------------
|
||||||
|
function newdataset(gp::DrySession, accum::Vector{String}; name=newBlockName(gp))
|
||||||
|
isnothing(name) && (name=newBlockName(gp))
|
||||||
|
prepend!(accum, [name * " << EOD"])
|
||||||
|
append!( accum, ["EOD"])
|
||||||
|
preview = (length(accum) < 6 ? accum : [accum[1:5]..., "...", accum[end]])
|
||||||
|
d = DataSet(name, join("GNUPLOT ($(gp.sid)) " .* preview, "\n"), join(accum, "\n"))
|
||||||
|
gp.datas[name] = d
|
||||||
write(gp, d) # Send now to gnuplot process
|
write(gp, d) # Send now to gnuplot process
|
||||||
return name
|
return name
|
||||||
end
|
end
|
||||||
newdataset(gp::DrySession, args...; name="") = newdataset(gp, arrays2datablock(args...), name=name)
|
newdataset(gp::DrySession, args...; name=newBlockName(gp)) = newdataset(gp, arrays2datablock(args...), name=name)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
@ -576,13 +566,8 @@ function savescript(gp::DrySession, filename; term::AbstractString="", output::A
|
|||||||
end
|
end
|
||||||
(output != "") && println(stream, "set output '$output'")
|
(output != "") && println(stream, "set output '$output'")
|
||||||
|
|
||||||
for i in 1:length(gp.datas)
|
for (name, d) in gp.datas
|
||||||
d = gp.datas[i]
|
println(stream, d.data)
|
||||||
println(stream, d.name * " << EOD")
|
|
||||||
for j in 1:length(d.lines)
|
|
||||||
println(stream, d.lines[j])
|
|
||||||
end
|
|
||||||
println(stream, "EOD")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for i in 1:length(gp.plots)
|
for i in 1:length(gp.plots)
|
||||||
@ -650,7 +635,7 @@ function driver(args...; flag3d=false)
|
|||||||
doReset && reset(gp)
|
doReset && reset(gp)
|
||||||
|
|
||||||
dataset = Vector{Any}()
|
dataset = Vector{Any}()
|
||||||
setname = ""
|
setname = nothing
|
||||||
plotspec = nothing
|
plotspec = nothing
|
||||||
|
|
||||||
function dataset_completed()
|
function dataset_completed()
|
||||||
@ -671,7 +656,7 @@ function driver(args...; flag3d=false)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
dataset = Vector{Any}()
|
dataset = Vector{Any}()
|
||||||
setname = ""
|
setname = nothing
|
||||||
plotspec = nothing
|
plotspec = nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user