Added term, term_png and term_svg fields in Options
This commit is contained in:
parent
d94e491522
commit
7bff6fc9a7
@ -3,7 +3,7 @@ module Gnuplot
|
|||||||
using StatsBase, ColorSchemes, ColorTypes, Colors, StructC14N, DataStructures
|
using StatsBase, ColorSchemes, ColorTypes, Colors, StructC14N, DataStructures
|
||||||
using REPL, ReplMaker
|
using REPL, ReplMaker
|
||||||
|
|
||||||
import Base.reset
|
#import Base.reset
|
||||||
import Base.write
|
import Base.write
|
||||||
import Base.show
|
import Base.show
|
||||||
|
|
||||||
@ -201,8 +201,10 @@ Structure containing the package global options, accessible through `Gnuplot.opt
|
|||||||
- `dry::Bool`: whether to use *dry* sessions, i.e. without an underlying Gnuplot process (default: `false`)
|
- `dry::Bool`: whether to use *dry* sessions, i.e. without an underlying Gnuplot process (default: `false`)
|
||||||
- `cmd::String`: command to start the Gnuplot process (default: `"gnuplot"`)
|
- `cmd::String`: command to start the Gnuplot process (default: `"gnuplot"`)
|
||||||
- `default::Symbol`: default session name (default: `:default`)
|
- `default::Symbol`: default session name (default: `:default`)
|
||||||
- `init::Vector{String}`: commands to initialize the session when it is created (e.g., to set default terminal);
|
- `term::String`: default terminal for interactive use (default: empty string, i.e. use gnuplot settings);
|
||||||
- `reset::Vector{String}`: commands to initialize the session when it is reset (e.g., to set default palette);
|
- `term_svg::String`: terminal to save png files (default `"svg"`);
|
||||||
|
- `term_png::String`: terminal to save png files (default `"pngcairo"`);
|
||||||
|
- `init::Vector{String}`: commands to initialize the session when it is created or reset (e.g., to set default palette);
|
||||||
- `verbose::Bool`: verbosity flag (default: `false`)
|
- `verbose::Bool`: verbosity flag (default: `false`)
|
||||||
- `preferred_format::Symbol`: preferred format to send data to gnuplot. Value must be one of:
|
- `preferred_format::Symbol`: preferred format to send data to gnuplot. Value must be one of:
|
||||||
- `bin`: fastest solution for large datasets, but uses temporary files;
|
- `bin`: fastest solution for large datasets, but uses temporary files;
|
||||||
@ -213,8 +215,10 @@ Base.@kwdef mutable struct Options
|
|||||||
dry::Bool = false
|
dry::Bool = false
|
||||||
cmd::String = "gnuplot"
|
cmd::String = "gnuplot"
|
||||||
default::Symbol = :default
|
default::Symbol = :default
|
||||||
|
term::String = ""
|
||||||
|
term_svg::String = "svg"
|
||||||
|
term_png::String = "pngcairo"
|
||||||
init::Vector{String} = Vector{String}()
|
init::Vector{String} = Vector{String}()
|
||||||
reset::Vector{String} = Vector{String}()
|
|
||||||
verbose::Bool = false
|
verbose::Bool = false
|
||||||
preferred_format::Symbol = :auto
|
preferred_format::Symbol = :auto
|
||||||
end
|
end
|
||||||
@ -522,16 +526,13 @@ function GPSession(sid::Symbol)
|
|||||||
pin, pout, perr, proc, chan)
|
pin, pout, perr, proc, chan)
|
||||||
sessions[sid] = out
|
sessions[sid] = out
|
||||||
|
|
||||||
for l in options.init
|
|
||||||
gpexec(out, l)
|
|
||||||
end
|
|
||||||
|
|
||||||
# If running in IJulia or Juno set the unknown terminal (trick
|
# If running in IJulia or Juno set the unknown terminal (trick
|
||||||
# copied from Gaston.jl)
|
# copied from Gaston.jl)
|
||||||
if (isdefined(Main, :IJulia) && Main.IJulia.inited) ||
|
if (isdefined(Main, :IJulia) && Main.IJulia.inited) ||
|
||||||
(isdefined(Main, :Juno) && Main.Juno.isactive())
|
(isdefined(Main, :Juno) && Main.Juno.isactive())
|
||||||
gpexec(out, "set term unknown")
|
gpexec(out, "set term unknown")
|
||||||
end
|
else
|
||||||
|
(options.term != "") && gpexec(out, "set term " * options.term)
|
||||||
|
|
||||||
# Set window title (if not already set)
|
# Set window title (if not already set)
|
||||||
term = writeread(out, "print GPVAL_TERM")[1]
|
term = writeread(out, "print GPVAL_TERM")[1]
|
||||||
@ -541,6 +542,7 @@ function GPSession(sid::Symbol)
|
|||||||
writeread(out, "set term $term $opts title 'Gnuplot.jl: $(out.sid)'")
|
writeread(out, "set term $term $opts title 'Gnuplot.jl: $(out.sid)'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
@ -764,7 +766,7 @@ function reset(gp::Session)
|
|||||||
gpexec(gp, "unset multiplot")
|
gpexec(gp, "unset multiplot")
|
||||||
gpexec(gp, "set output")
|
gpexec(gp, "set output")
|
||||||
gpexec(gp, "reset session")
|
gpexec(gp, "reset session")
|
||||||
add_cmd.(Ref(gp), options.reset)
|
add_cmd.(Ref(gp), options.init)
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1506,7 +1508,7 @@ Base.show(io::IO, gp::SessionID) = nothing
|
|||||||
function Base.show(io::IO, ::MIME"image/svg+xml", gp::SessionID)
|
function Base.show(io::IO, ::MIME"image/svg+xml", gp::SessionID)
|
||||||
if gp.dump
|
if gp.dump
|
||||||
tmpfile = tempname()*".svg"
|
tmpfile = tempname()*".svg"
|
||||||
save(gp.sid; term="svg", output=tmpfile)
|
save(gp.sid; term=options.term_svg, output=tmpfile)
|
||||||
write(io, read(tmpfile))
|
write(io, read(tmpfile))
|
||||||
rm(tmpfile; force=true)
|
rm(tmpfile; force=true)
|
||||||
end
|
end
|
||||||
@ -1515,7 +1517,7 @@ end
|
|||||||
function Base.show(io::IO, ::MIME"image/png", gp::SessionID)
|
function Base.show(io::IO, ::MIME"image/png", gp::SessionID)
|
||||||
if gp.dump
|
if gp.dump
|
||||||
tmpfile = tempname()*".png"
|
tmpfile = tempname()*".png"
|
||||||
save(gp.sid; output=tmpfile, term="pngcairo")
|
save(gp.sid; term=options.term_png, output=tmpfile)
|
||||||
write(io, read(tmpfile))
|
write(io, read(tmpfile))
|
||||||
rm(tmpfile; force=true)
|
rm(tmpfile; force=true)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,7 +4,7 @@ try
|
|||||||
catch
|
catch
|
||||||
Gnuplot.options.dry = true
|
Gnuplot.options.dry = true
|
||||||
end
|
end
|
||||||
push!(Gnuplot.options.init, "set term unknown")
|
Gnuplot.options.term = "unknown"
|
||||||
|
|
||||||
x = [1, 2, 3]
|
x = [1, 2, 3]
|
||||||
y = [4, 5, 6]
|
y = [4, 5, 6]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user