Handle label input

This commit is contained in:
Giorgio Calderone 2020-03-22 18:42:17 +01:00
parent a4bb94bfde
commit 546cfef009
2 changed files with 19 additions and 21 deletions

View File

@ -4,7 +4,6 @@ using StatsBase, ColorSchemes, ColorTypes, StructC14N, ReusePatterns
import Base.reset
import Base.write
import Base.string
export @gp, @gsp, save, linestyles, palette, contourlines, hist
@ -61,11 +60,6 @@ const options = Options()
# ╭───────────────────────────────────────────────────────────────────╮
# │ LOW LEVEL FUNCTIONS │
# ╰───────────────────────────────────────────────────────────────────╯
# ---------------------------------------------------------------------
function string(c::ColorTypes.RGB)
return string(float(c.r)*255) * " " * string(float(c.g)*255) * " " * string(float(c.b)*255)
end
# ---------------------------------------------------------------------
"""
@ -97,7 +91,6 @@ function CheckGnuplotVersion(cmd::AbstractString)
if ver < v"4.7"
error("gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found.")
end
#@info " Gnuplot version: " * string(ver)
return ver
end
@ -134,6 +127,10 @@ end
# ---------------------------------------------------------------------
tostring(v) = string(v)
tostring(c::ColorTypes.RGB) = string(float(c.r)*255) * " " * string(float(c.g)*255) * " " * string(float(c.b)*255)
tostring(v::AbstractString) = "\"" * string(v) * "\""
function data2string(args...)
@assert length(args) > 0
@ -145,12 +142,9 @@ function data2string(args...)
if typeof(d) <: Number
ok = true
elseif typeof(d) <: AbstractArray
if typeof(d[1]) <: Number
ok = true
end
if typeof(d[1]) <: ColorTypes.RGB
ok = true
end
(typeof(d[1]) <: String) && (ok = true)
(typeof(d[1]) <: Number) && (ok = true)
(typeof(d[1]) <: ColorTypes.RGB) && (ok = true)
end
@assert ok "Invalid argument type at position $iarg"
end
@ -176,7 +170,7 @@ function data2string(args...)
v = ""
for iarg in 1:length(args)
d = args[iarg]
v *= " " * string(d)
v *= " " * tostring(d)
end
push!(accum, v)
return accum
@ -192,7 +186,7 @@ function data2string(args...)
v = ""
for iarg in 1:length(args)
d = args[iarg]
v *= " " * string(d[i])
v *= " " * tostring(d[i])
end
push!(accum, v)
end
@ -216,7 +210,7 @@ function data2string(args...)
end
for iarg in 1:length(args)
d = args[iarg]
v *= " " * string(d[i])
v *= " " * tostring(d[i])
end
i += 1
push!(accum, v)
@ -243,11 +237,11 @@ function data2string(args...)
v = ""
for iarg in 1:firstMultiDim-1
d = args[iarg]
v *= " " * string(d[indices[iarg]])
v *= " " * tostring(d[indices[iarg]])
end
for iarg in firstMultiDim:length(args)
d = args[iarg]
v *= " " * string(d[i])
v *= " " * tostring(d[i])
end
i += 1
push!(accum, v)
@ -265,7 +259,7 @@ function data2string(args...)
v = ""
for iarg in 1:length(args)
d = args[iarg]
v *= " " * string(d[i])
v *= " " * tostring(d[i])
end
i += 1
push!(accum, v)

View File

@ -66,8 +66,6 @@ s = Gnuplot.data2string(x, y, z)
" 2 6 8" ,
" 3 6 9" ])
c = [[X, Y] for Y in y for X in x]; # First Y (i.e. rows) then X (i.e. columns)
u = getindex.(c, 1)
v = getindex.(c, 2)
@ -85,6 +83,12 @@ s = Gnuplot.data2string(u, v, z)
" 2 6 8" ,
" 3 6 9" ])
s = Gnuplot.data2string(1:3, 1:3, ["One", "Two", "Three"])
@test all(s .== [ " 1 1 \"One\"" ,
" 2 2 \"Two\"" ,
" 3 3 \"Three\""])
#-----------------------------------------------------------------
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"