From 8b2a83838894dc6d7f903a75e209362137e4d237 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 11 Mar 2016 13:07:25 -0500 Subject: [PATCH] fixed dataframes loading; added dataframes to tests; started atom integration --- src/Plots.jl | 3 +++ src/output.jl | 24 +++++++++++++++++++++- src/plot.jl | 54 ++++++++++++++++++++++--------------------------- test/REQUIRE | 2 ++ test/imgcomp.jl | 8 +++++--- 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 16f407b7..7bf7304a 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -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 # --------------------------------------------------------- diff --git a/src/output.jl b/src/output.jl index 95a7bf08..aeb3adfb 100644 --- a/src/output.jl +++ b/src/output.jl @@ -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 diff --git a/src/plot.jl b/src/plot.jl index 3fa72394..11a27c1c 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -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 - # -------------------------------------------------------------------- diff --git a/test/REQUIRE b/test/REQUIRE index a2997f73..803da6a0 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -10,3 +10,5 @@ ImageMagick PyPlot @osx QuartzImageIO GR +DataFrames +RDatasets diff --git a/test/imgcomp.jl b/test/imgcomp.jl index e898e174..8ad6e479 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -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)")