Added test_terminal() function; Changed name and meaning of linestyles: now returns linetypes

This commit is contained in:
Giorgio Calderone 2020-03-25 20:22:04 +01:00
parent 34b7dc9184
commit 4fa4b392c6
2 changed files with 31 additions and 10 deletions

View File

@ -5,7 +5,7 @@ using StatsBase, ColorSchemes, ColorTypes, StructC14N, ReusePatterns
import Base.reset import Base.reset
import Base.write import Base.write
export @gp, @gsp, save, linestyles, palette, contourlines, hist, terminal, terminals export @gp, @gsp, save, linetypes, palette, contourlines, hist, terminal, terminals, test_terminal
# ╭───────────────────────────────────────────────────────────────────╮ # ╭───────────────────────────────────────────────────────────────────╮
# │ TYPE DEFINITIONS │ # │ TYPE DEFINITIONS │
@ -133,7 +133,7 @@ end
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
tostring(v) = string(v) tostring(v) = string(v)
tostring(c::ColorTypes.RGB) = string(float(c.r)*255) * " " * string(float(c.g)*255) * " " * string(float(c.b)*255) tostring(c::ColorTypes.RGB) = string(Int(c.r*255)) * " " * string(Int(c.g*255)) * " " * string(Int(c.b*255))
tostring(v::AbstractString) = "\"" * string(v) * "\"" tostring(v::AbstractString) = "\"" * string(v) * "\""
function data2string(args...) function data2string(args...)
@ -425,9 +425,17 @@ function write(gp::GPSession, d::DataSet)
printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) EOD\n") printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) EOD\n")
end end
write(gp.pin, "$(d.name) << EOD\n") write(gp.pin, "$(d.name) << EOD\n")
write(gp.pin, join(d.lines, "\n") * "\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") write(gp.pin, "EOD\n")
flush(gp.pin) flush(gp.pin)
#if length(buf) > 1e4
# write(stdout, "\r" * *(fill(" ", length(s))...) * "\r")
#end
return nothing return nothing
end end
@ -1027,13 +1035,13 @@ save(sid::Symbol, file::AbstractString; kw...) = savescript(getsession(sid), fil
# │ HIGH LEVEL FACILITIES │ # │ HIGH LEVEL FACILITIES │
# ╰───────────────────────────────────────────────────────────────────╯ # ╰───────────────────────────────────────────────────────────────────╯
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
linestyles(s::Symbol) = linestyles(colorschemes[s]) linetypes(s::Symbol) = linetypes(colorschemes[s])
function linestyles(cmap::ColorScheme) function linetypes(cmap::ColorScheme)
styles = Vector{String}() out = Vector{String}()
for i in 1:length(cmap.colors) for i in 1:length(cmap.colors)
push!(styles, "set style line $i lt 1 lc rgb '#" * Base.hex(cmap.colors[i])) push!(out, "set linetype $i lc rgb '#" * Base.hex(cmap.colors[i]))
end end
return join(styles, "\n") return join(out, "\n") * "\nset linetype cycle " * string(length(cmap.colors)) * "\n"
end end
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -1328,4 +1336,17 @@ function splash(outputfile="")
nothing nothing
end end
function test_terminal(term=nothing; linetypes=nothing, palette=nothing)
quit(:test_term)
quit(:test_palette)
if !isnothing(term)
exec(:test_term , "set term $term;")
exec(:test_palette , "set term $term")
end
s = (isnothing(linetypes) ? "" : Gnuplot.linetypes(linetypes))
exec(:test_term , "$s; test")
s = (isnothing(palette) ? "" : Gnuplot.palette(palette))
exec(:test_palette , "$s; test palette")
end
end #module end #module

View File

@ -92,8 +92,8 @@ s = Gnuplot.data2string(1:3, 1:3, ["One", "Two", "Three"])
#----------------------------------------------------------------- #-----------------------------------------------------------------
pal = palette(:deepsea) pal = palette(:deepsea)
@test pal == "set palette defined (0.0 '#2B004D', 0.25 '#4E0F99', 0.5 '#3C54D4', 0.75 '#48A9F8', 1.0 '#C5ECFF')\nset palette maxcol 5\n" @test pal == "set palette defined (0.0 '#2B004D', 0.25 '#4E0F99', 0.5 '#3C54D4', 0.75 '#48A9F8', 1.0 '#C5ECFF')\nset palette maxcol 5\n"
ls = linestyles(:deepsea) ls = linetypes(:deepsea)
@test ls == "set style line 1 lt 1 lc rgb '#2B004D\nset style line 2 lt 1 lc rgb '#4E0F99\nset style line 3 lt 1 lc rgb '#3C54D4\nset style line 4 lt 1 lc rgb '#48A9F8\nset style line 5 lt 1 lc rgb '#C5ECFF" @test ls == "set linetype 1 lc rgb '#2B004D\nset linetype 2 lc rgb '#4E0F99\nset linetype 3 lc rgb '#3C54D4\nset linetype 4 lc rgb '#48A9F8\nset linetype 5 lc rgb '#C5ECFF\nset linetype cycle 5\n"
#----------------------------------------------------------------- #-----------------------------------------------------------------
# Test wth empty dataset # Test wth empty dataset