fixed dataframes loading; added dataframes to tests; started atom integration

This commit is contained in:
Thomas Breloff 2016-03-11 13:07:25 -05:00
parent b08212e2f9
commit 8b2a838388
5 changed files with 57 additions and 34 deletions

View File

@ -239,6 +239,9 @@ function __init__()
@eval import IJulia
IJulia.display_dict(plt::AbstractPlot) = Dict{ASCIIString, ByteString}("text/html" => sprint(writemime, "text/html", plt))
end
setup_dataframes()
setup_atom()
end
# ---------------------------------------------------------

View File

@ -79,7 +79,7 @@ function addExtension(fn::@compat(AbstractString), ext::@compat(AbstractString))
end
function savefig(plt::AbstractPlot, fn::@compat(AbstractString))
# get the extension
local ext
try
@ -117,3 +117,25 @@ Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::AbstractPlot) = g
function Base.writemime(io::IO, ::MIME"text/html", plt::AbstractPlot)
writemime(io, MIME("image/svg+xml"), plt)
end
# ---------------------------------------------------------
# Atom PlotPane
# ---------------------------------------------------------
function setup_atom()
# @require Atom begin
# @eval begin
# import Atom
#
# Atom.displaysize(::AbstractPlot) = (535, 379)
# Atom.displaytitle(::AbstractPlot) = "Plots.jl"
#
# Atom.@render Atom.PlotPane p::Plot begin
# x, y = Atom.@rpc Atom.plotsize()
# plot!(p, size=(x,y)) # changes the size of the Plots.Plot
# Atom.div(Dict(:style=>"background: white"), Atom.HTML(stringmime("text/html", p)))
# end
# end
# end
end

View File

@ -531,39 +531,33 @@ end
# For DataFrame support. Imports DataFrames and defines the necessary methods which support them.
@require DataFrames begin
function setup_dataframes()
@require DataFrames begin
function createKWargsList(plt::AbstractPlot, df::DataFrames.AbstractDataFrame, args...; kw...)
createKWargsList(plt, args...; kw..., dataframe = df)
end
function createKWargsList(plt::AbstractPlot, df::DataFrames.AbstractDataFrame, args...; kw...)
createKWargsList(plt, args...; kw..., dataframe = df)
end
# expecting the column name of a dataframe that was passed in... anything else should error
function extractGroupArgs(s::Symbol, df::DataFrames.AbstractDataFrame, args...)
if haskey(df, s)
return extractGroupArgs(df[s])
else
error("Got a symbol, and expected that to be a key in d[:dataframe]. s=$s d=$d")
end
end
function getDataFrameFromKW(d::Dict)
get(d, :dataframe) do
error("Missing dataframe argument!")
end
end
# the conversion functions for when we pass symbols or vectors of symbols to reference dataframes
convertToAnyVector(s::Symbol, d::Dict) = Any[getDataFrameFromKW(d)[s]], s
convertToAnyVector(v::AVec{Symbol}, d::Dict) = (df = getDataFrameFromKW(d); Any[df[s] for s in v]), v
# expecting the column name of a dataframe that was passed in... anything else should error
function extractGroupArgs(s::Symbol, df::DataFrames.AbstractDataFrame, args...)
if haskey(df, s)
return extractGroupArgs(df[s])
else
error("Got a symbol, and expected that to be a key in d[:dataframe]. s=$s d=$d")
end
end
function getDataFrameFromKW(d::Dict)
# for (k,v) in kw
# if k == :dataframe
# return v
# end
# end
get(d, :dataframe) do
error("Missing dataframe argument!")
end
end
# the conversion functions for when we pass symbols or vectors of symbols to reference dataframes
# convertToAnyVector(s::Symbol; kw...) = Any[getDataFrameFromKW(;kw...)[s]], s
# convertToAnyVector(v::AVec{Symbol}; kw...) = (df = getDataFrameFromKW(;kw...); Any[df[s] for s in v]), v
convertToAnyVector(s::Symbol, d::Dict) = Any[getDataFrameFromKW(d)[s]], s
convertToAnyVector(v::AVec{Symbol}, d::Dict) = (df = getDataFrameFromKW(d); Any[df[s] for s in v]), v
end
# --------------------------------------------------------------------

View File

@ -10,3 +10,5 @@ ImageMagick
PyPlot
@osx QuartzImageIO
GR
DataFrames
RDatasets

View File

@ -2,6 +2,8 @@
using VisualRegressionTests
using ExamplePlots
import DataFrames, RDatasets
# don't let pyplot use a gui... it'll crash
# note: Agg will set gui -> :none in PyPlot
ENV["MPLBACKEND"] = "Agg"
@ -16,12 +18,12 @@ using Plots, FactCheck
default(size=(500,300))
# TODO: use julia's Condition type and the wait() and notify() functions to initialize a Window, then wait() on a condition that
# TODO: use julia's Condition type and the wait() and notify() functions to initialize a Window, then wait() on a condition that
# is referenced in a button press callback (the button clicked callback will call notify() on that condition)
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2)
# first
# first
Plots._debugMode.on = debug
example = ExamplePlots._examples[idx]
info("Testing plot: $pkg:$idx:$(example.header)")