revamped setTicksFromStringVector; dataframes label fix
This commit is contained in:
parent
43ba9b1172
commit
17a90e3b00
54
src/plot.jl
54
src/plot.jl
@ -188,9 +188,9 @@ function _add_series(plt::Plot, d::KW, ::Void, args...;
|
|||||||
plt.n += 1
|
plt.n += 1
|
||||||
|
|
||||||
if !stringsSupported() && di[:linetype] != :pie
|
if !stringsSupported() && di[:linetype] != :pie
|
||||||
setTicksFromStringVector(d, di, :x, :xticks)
|
setTicksFromStringVector(plt, d, di, "x")
|
||||||
setTicksFromStringVector(d, di, :y, :yticks)
|
setTicksFromStringVector(plt, d, di, "y")
|
||||||
setTicksFromStringVector(d, di, :z, :zticks)
|
setTicksFromStringVector(plt, d, di, "z")
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove plot args
|
# remove plot args
|
||||||
@ -215,21 +215,47 @@ end
|
|||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
# if x or y are a vector of strings, we should create a list of unique strings,
|
function get_indices(orig, labels)
|
||||||
# and map x/y to be the index of the string... then set the x/y tick labels
|
Int[findnext(labels, l, 1) for l in orig]
|
||||||
function setTicksFromStringVector(d::KW, di::KW, sym::Symbol, ticksym::Symbol)
|
end
|
||||||
# if the x or y values are strings, set ticks to the unique values, and x/y to the indices of the ticks
|
|
||||||
|
|
||||||
|
function setTicksFromStringVector(plt::Plot, d::KW, di::KW, letter)
|
||||||
|
sym = symbol(letter)
|
||||||
|
ticksym = symbol(letter * "ticks")
|
||||||
|
pargs = plt.plotargs
|
||||||
v = di[sym]
|
v = di[sym]
|
||||||
isa(v, AbstractArray) || return
|
|
||||||
|
|
||||||
T = eltype(v)
|
# do we really want to do this?
|
||||||
if T <: @compat(AbstractString) || (!isempty(T.types) && all(x -> x <: @compat(AbstractString), T.types))
|
typeof(v) <: AbstractArray || return
|
||||||
ticks = unique(di[sym])
|
trueOrAllTrue(_ -> typeof(_) <: AbstractString, v) || return
|
||||||
di[sym] = Int[findnext(ticks, v, 1) for v in di[sym]]
|
|
||||||
|
|
||||||
if !haskey(d, ticksym) || d[ticksym] == :auto
|
# compute the ticks and labels
|
||||||
d[ticksym] = (collect(1:length(ticks)), UTF8String[t for t in ticks])
|
ticks, labels = if ticksType(pargs[ticksym]) == :ticks_and_labels
|
||||||
|
# extend the existing ticks and labels. only add to labels if they're new!
|
||||||
|
ticks, labels = pargs[ticksym]
|
||||||
|
newlabels = filter(_ -> !(_ in labels), unique(v))
|
||||||
|
ticks = vcat(ticks, maximum(ticks) + (1:length(newlabels)))
|
||||||
|
labels = vcat(labels, newlabels)
|
||||||
|
ticks, labels
|
||||||
|
else
|
||||||
|
# create new ticks and labels
|
||||||
|
newlabels = unique(v)
|
||||||
|
collect(1:length(newlabels)), newlabels
|
||||||
|
end
|
||||||
|
|
||||||
|
d[ticksym] = ticks, labels
|
||||||
|
plt.plotargs[ticksym] = ticks, labels
|
||||||
|
|
||||||
|
# add an origsym field so that later on we can re-compute the x vector if ticks change
|
||||||
|
origsym = symbol(letter * "orig")
|
||||||
|
di[origsym] = v
|
||||||
|
di[sym] = get_indices(v, labels)
|
||||||
|
|
||||||
|
# loop through existing plt.seriesargs and adjust indices if there is an origsym key
|
||||||
|
for sargs in plt.seriesargs
|
||||||
|
if haskey(sargs, origsym)
|
||||||
|
# TODO: might need to call the setindex function instead to trigger a plot update for some backends??
|
||||||
|
sargs[sym] = get_indices(sargs[origsym], labels)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -469,7 +469,7 @@ function setup_dataframes()
|
|||||||
get!(d, symbol(letter * "label"), string(dfs))
|
get!(d, symbol(letter * "label"), string(dfs))
|
||||||
collect(df[dfs])
|
collect(df[dfs])
|
||||||
else
|
else
|
||||||
get!(d, :label, dfs')
|
get!(d, :label, reshape(dfs, 1, length(dfs)))
|
||||||
Any[collect(df[s]) for s in dfs]
|
Any[collect(df[s]) for s in dfs]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user