working on data updating and notebooks
This commit is contained in:
parent
0041b034e0
commit
9ce8d138d5
File diff suppressed because one or more lines are too long
184
examples/plotupdates.ipynb
Normal file
184
examples/plotupdates.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -190,7 +190,7 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
||||
# Should ensure from this side that colors which are the same are merged together
|
||||
|
||||
push!(gplt.guides[1].labels, d[:label])
|
||||
push!(gplt.guides[1].colors, first(d[:marker] == :none ? d[:color] : d[:markercolor]))
|
||||
push!(gplt.guides[1].colors, d[:marker] == :none ? d[:color] : d[:markercolor])
|
||||
# println("updated legend: ", gplt.guides)
|
||||
end
|
||||
|
||||
|
||||
@ -52,35 +52,19 @@ end
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# real time updates
|
||||
# TODO: generalize this and move as much as possible out of here
|
||||
# accessors for x/y data
|
||||
|
||||
function getImmerseData(plt::Plot{ImmersePackage}, i::Int)
|
||||
gplt = plt.o[2]
|
||||
gplt.layers[end-i+1].mapping
|
||||
end
|
||||
|
||||
# add a new x/y data point to series i
|
||||
function Base.push!(plt::Plot{ImmersePackage}, i::Int, x::Real, y::Real)
|
||||
data = getImmerseData(plt, i)
|
||||
data[:x] = extendSeriesData(data[:x], x)
|
||||
data[:y] = extendSeriesData(data[:y], y)
|
||||
plt
|
||||
end
|
||||
|
||||
# add a new y, and extend x "naturally" for series i
|
||||
function Base.push!(plt::Plot{ImmersePackage}, i::Int, y::Real)
|
||||
xdata, ydata = xy(plt, i)
|
||||
data[:x] = extendSeriesData(data[:x]) # this will only work with a UnitRange{Int}!!!
|
||||
data[:y] = extendSeriesData(data[:y], y)
|
||||
plt
|
||||
end
|
||||
|
||||
function xy(plt::Plot{ImmersePackage}, i::Int)
|
||||
data = getImmerseData(plt, i)
|
||||
function Base.getindex(plt::Plot{ImmersePackage}, i::Int)
|
||||
data = plt.o[2].layers[end-i+1].mapping
|
||||
data[:x], data[:y]
|
||||
end
|
||||
|
||||
function Base.setindex!(plt::Plot{ImmersePackage}, xy::Tuple, i::Integer)
|
||||
data = plt.o[2].layers[end-i+1].mapping
|
||||
data[:x], data[:y] = xy
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
@ -151,7 +135,6 @@ function Base.display(::PlotsDisplay, plt::Plot{ImmersePackage})
|
||||
end
|
||||
|
||||
Immerse.figure(fig.figno; displayfig = false)
|
||||
println("about to display")
|
||||
display(gplt)
|
||||
end
|
||||
|
||||
|
||||
71
src/utils.jl
71
src/utils.jl
@ -138,10 +138,77 @@ ticksType(ticks) = :invalid
|
||||
limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits
|
||||
limsType(lims) = :invalid
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
# push/append/clear/set the underlying plot data
|
||||
# NOTE: backends should implement the getindex and setindex! methods to get/set the x/y data objects
|
||||
|
||||
|
||||
# index versions
|
||||
function Base.push!(plt::Plot, i::Integer, x, y)
|
||||
xdata, ydata = plt[i]
|
||||
plt[i] = (extendSeriesData(xdata, x), extendSeriesData(ydata, y))
|
||||
plt
|
||||
end
|
||||
function Base.push!(plt::Plot, i::Integer, y)
|
||||
xdata, ydata = plt[i]
|
||||
if !isa(xdata, UnitRange)
|
||||
error("Expected x is a UnitRange since you're trying to push a y value only")
|
||||
end
|
||||
plt[i] = (extendUnitRange(xdata), extendSeriesData(ydata, y))
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
# update all at once
|
||||
function Base.push!(plt::Plot, x::AVec, y::AVec)
|
||||
nx = length(x)
|
||||
ny = length(y)
|
||||
for i in 1:plt.n
|
||||
push!(plt, i, x[mod1(i,nx)], y[mod1(i,ny)])
|
||||
end
|
||||
plt
|
||||
end
|
||||
|
||||
function Base.push!(plt::Plot, x, y::AVec)
|
||||
push!(plt, [x], y)
|
||||
end
|
||||
|
||||
function Base.push!(plt::Plot, y::AVec)
|
||||
ny = length(y)
|
||||
for i in 1:plt.n
|
||||
push!(plt, i, y[mod1(i,ny)])
|
||||
end
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
# append to index
|
||||
function Base.append!(plt::Plot, i::Integer, x::AVec, y::AVec)
|
||||
@assert length(x) == length(y)
|
||||
xdata, ydata = plt[i]
|
||||
plt[i] = (extendSeriesData(xdata, x), extendSeriesData(ydata, y))
|
||||
plt
|
||||
end
|
||||
|
||||
function Base.append!(plt::Plot, i::Integer, y::AVec)
|
||||
xdata, ydata = plt[i]
|
||||
if !isa(xdata, UnitRange{Int})
|
||||
error("Expected x is a UnitRange since you're trying to push a y value only")
|
||||
end
|
||||
plt[i] = (extendUnitRange(xdata, length(y)), extendSeriesData(ydata, y))
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
# used in updating an existing series
|
||||
extendSeriesData(v::UnitRange{Int}) = minimum(v):maximum(v)+1
|
||||
extendSeriesData{T<:Real}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v)
|
||||
|
||||
extendUnitRange(v::UnitRange{Int}, n::Int = 1) = minimum(v):maximum(v)+n
|
||||
extendSeriesData(v::AVec, z) = (push!(v, z); v)
|
||||
extendSeriesData(v::AVec, z::AVec) = (append!(v, z); v)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
|
||||
# Some conversion functions
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user