working on data updating and notebooks

This commit is contained in:
Thomas Breloff 2015-09-25 01:00:22 -04:00
parent 0041b034e0
commit 9ce8d138d5
5 changed files with 358 additions and 85 deletions

File diff suppressed because one or more lines are too long

184
examples/plotupdates.ipynb Normal file

File diff suppressed because one or more lines are too long

View File

@ -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 # 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].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) # println("updated legend: ", gplt.guides)
end end

View File

@ -52,35 +52,19 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# real time updates # accessors for x/y data
# TODO: generalize this and move as much as possible out of here
function getImmerseData(plt::Plot{ImmersePackage}, i::Int) function Base.getindex(plt::Plot{ImmersePackage}, i::Int)
gplt = plt.o[2] data = plt.o[2].layers[end-i+1].mapping
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)
data[:x], data[:y] data[:x], data[:y]
end 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 end
Immerse.figure(fig.figno; displayfig = false) Immerse.figure(fig.figno; displayfig = false)
println("about to display")
display(gplt) display(gplt)
end end

View File

@ -138,10 +138,77 @@ ticksType(ticks) = :invalid
limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits
limsType(lims) = :invalid 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 # 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 # Some conversion functions