diff --git a/.gitignore b/.gitignore index 7b54dfb3..bb43a1d0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.jl.*.cov *.jl.mem .DS_Store -examples/.ipynb_checkpoints/* \ No newline at end of file +examples/.ipynb_checkpoints/* +examples/meetup/.ipynb_checkpoints/* diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 89c4edc1..041525be 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -633,16 +633,16 @@ function buildGadflySubplotContext(subplt::Subplot) Gadfly.vstack(rows...) end -function setGadflyDisplaySize(w,h) - Compose.set_default_graphic_size(w * Compose.px, h * Compose.px) -end - +setGadflyDisplaySize(w,h) = Compose.set_default_graphic_size(w * Compose.px, h * Compose.px) +setGadflyDisplaySize(plt::Plot) = setGadflyDisplaySize(plt.initargs[:size]...) +setGadflyDisplaySize(subplt::Subplot) = setGadflyDisplaySize(getinitargs(subplt, 1)[:size]...) # ------------------------------------------------------------------------- function dowritemime{P<:GadflyOrImmerse}(io::IO, func, plt::PlottingObject{P}) gplt = getGadflyContext(plt) - setGadflyDisplaySize(plt.initargs[:size]...) + # setGadflyDisplaySize(plt.initargs[:size]...) + setGadflyDisplaySize(plt) Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) end @@ -670,7 +670,7 @@ end function Base.display(::PlotsDisplay, subplt::Subplot{GadflyPackage}) - setGadflyDisplaySize(subplt.initargs[1][:size]...) + setGadflyDisplaySize(getinitargs(subplt,1)[:size]...) ctx = buildGadflySubplotContext(subplt) diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl index e40c13e3..a4be5212 100644 --- a/src/backends/immerse.jl +++ b/src/backends/immerse.jl @@ -92,7 +92,7 @@ function buildSubplotObject!(subplt::Subplot{ImmersePackage}, isbefore::Bool) isbefore && return false # create the Gtk window with vertical box vsep - d = subplt.initargs[1] + d = getinitargs(subplt,1) w,h = d[:size] vsep = Gtk.GtkBoxLeaf(:v) win = Gtk.GtkWindowLeaf(vsep, d[:windowtitle], w, h) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index ff31c28f..df705c87 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -497,8 +497,8 @@ end function buildSubplotObject!(subplt::Subplot{PyPlotPackage}, isbefore::Bool) l = subplt.layout - w,h = map(px2inch, subplt.initargs[1][:size]) - bgcolor = getPyPlotColor(subplt.initargs[1][:background_color]) + w,h = map(px2inch, getinitargs(subplt,1)[:size]) + bgcolor = getPyPlotColor(getinitargs(subplt,1)[:background_color]) fig = PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96) nr = nrows(l) diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index c50f7fc6..a167eca2 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -278,7 +278,7 @@ function buildSubplotObject!(subplt::Subplot{QwtPackage}, isbefore::Bool) # i += rowcnt # end subplt.o = Qwt.vsplitter(rows...) - Qwt.resizewidget(subplt.o, subplt.initargs[1][:size]...) + Qwt.resizewidget(subplt.o, getinitargs(subplt,1)[:size]...) Qwt.moveToLastScreen(subplt.o) # hack so it goes to my center monitor... sorry true end diff --git a/src/colors.jl b/src/colors.jl index be76f766..813c98af 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -105,6 +105,8 @@ colorscheme(m::AMat) = size(m,1) == 1 ? map(colorscheme, m) : [colorscheme(m[:,i colorscheme(c::Colorant) = ColorWrapper(c) const _rainbowColors = [colorant"blue", colorant"purple", colorant"green", colorant"orange", colorant"red"] +const _testColors = [colorant"darkblue", colorant"blueviolet", colorant"darkcyan",colorant"green", + darken(colorant"yellow",0.3), colorant"orange", darken(colorant"red",0.2)] @compat const _gradients = Dict( :blues => [colorant"lightblue", colorant"darkblue"], @@ -117,6 +119,8 @@ const _rainbowColors = [colorant"blue", colorant"purple", colorant"green", color :rainbow => _rainbowColors, :lightrainbow => map(lighten, _rainbowColors), :darkrainbow => map(darken, _rainbowColors), + :darktest => _testColors, + :lighttest => map(c -> lighten(c, 0.3), _testColors), ) # -------------------------------------------------------------- @@ -305,7 +309,8 @@ end function getPaletteUsingGradientSymbol(palette, bgcolor::Colorant, numcolors::Int = _defaultNumColors) #; gradientsym::Symbol = :auto) # @show gradientsym if palette == :auto - grad = ColorGradient(_gradients[isdark(bgcolor) ? :lightrainbow : :darkrainbow]) + # grad = ColorGradient(_gradients[isdark(bgcolor) ? :lightrainbow : :darkrainbow]) + grad = ColorGradient(_gradients[isdark(bgcolor) ? :lighttest : :darktest]) # elseif typeof(palette) <: AVec || typeof(palette) <: ColorGradient # grad = ColorGradient(palette) else diff --git a/src/subplot.jl b/src/subplot.jl index 57278140..4e031d45 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -167,11 +167,14 @@ function subplot(args...; kw...) # initialize the individual plots pkg = backend() plts = Plot[] - ds = Dict[] + # ds = Dict[] for i in 1:length(layout) - push!(ds, getPlotArgs(pkg, d, i)) - ds[i][:subplot] = true - push!(plts, plot(pkg; ds[i]...)) + di = getPlotArgs(pkg, d, i) + di[:subplot] = true + push!(plts, plot(pkg; di...)) + # push!(ds, getPlotArgs(pkg, d, i)) + # ds[i][:subplot] = true + # push!(plts, plot(pkg; ds[i]...)) end # tmpd = getPlotKeywordArgs(pkg, kw, 1, 0) # TODO: this should happen in the plot creation loop... think... what if we want to set a title per subplot?? @@ -181,7 +184,8 @@ function subplot(args...; kw...) # # tmpd[:show] = shouldShow # create the object and do the plotting - subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, ds, false, false, false, (r,c) -> (nothing,nothing)) + # subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, ds, false, false, false, (r,c) -> (nothing,nothing)) + subplt = Subplot(nothing, plts, pkg, length(layout), 0, layout, d, false, false, false, (r,c) -> (nothing,nothing)) subplot!(subplt, args...; kw...) subplt diff --git a/src/types.jl b/src/types.jl index e81654b6..691a0aec 100644 --- a/src/types.jl +++ b/src/types.jl @@ -38,7 +38,8 @@ type Subplot{T<:PlottingPackage, L<:SubplotLayout} <: PlottingObject{T} p::Int # number of plots n::Int # number of series layout::L - initargs::Vector{Dict} + # initargs::Vector{Dict} + initargs::Dict initialized::Bool linkx::Bool linky::Bool diff --git a/test/REQUIRE b/test/REQUIRE index 0e0558eb..979cf3c2 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -6,3 +6,5 @@ FactCheck PyPlot UnicodePlots Gadfly +Images +ImageMagick diff --git a/test/imgcomp.jl b/test/imgcomp.jl index 9156f458..a45cc02b 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -16,8 +16,8 @@ include("../docs/example_generation.jl") # plt # end -using Plots -import Images, Gtk, ImageMagick +using Plots, FactCheck +import Images, ImageMagick function makeImageWidget(fn) img = Gtk.GtkImageLeaf(fn) @@ -29,11 +29,14 @@ function makeImageWidget(fn) end function replaceReferenceImage(tmpfn, reffn) - println("cp $tmpfn $reffn") + cmd = `cp $tmpfn $reffn` + run(cmd) + info("Replaced reference image with: $cmd") end "Show a Gtk popup with both images and a confirmation whether we should replace the new image with the old one" function compareToReferenceImage(tmpfn, reffn) + @eval import Gtk # add the images imgbox = Gtk.GtkBoxLeaf(:h) @@ -51,7 +54,8 @@ function compareToReferenceImage(tmpfn, reffn) box = Gtk.GtkBoxLeaf(:v) push!(box, imgbox) push!(box, btnbox) - win = Gtk.GtkWindowLeaf(Gtk.GtkFrameLeaf(box)) + win = Gtk.GtkWindowLeaf("Should we make this the new reference image?") + push!(win, Gtk.GtkFrameLeaf(box)) # we'll wait on this condition c = Condition() @@ -76,7 +80,7 @@ end # 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 = true, sigma = [0,0], eps = 1e-3) +function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, sigma = [1,1], eps = 1e-3) # first Plots._debugMode.on = debug @@ -84,7 +88,10 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0, backend(pkg) backend() - info("here: ", PlotExamples.examples[idx].exprs) + # ensure consistent results + srand(1234) + + # run the example map(eval, PlotExamples.examples[idx].exprs) # save the png @@ -97,7 +104,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0, # reference image location refdir = joinpath(Pkg.dir("Plots"), "test", "refimg", "v$(VERSION.major).$(VERSION.minor)", string(pkg)) try - mkdir(refdir) + run(`mkdir -p $refdir`) catch err display(err) end @@ -105,7 +112,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0, try - info("Comparing $tmpfn to reference $reffn") + # info("Comparing $tmpfn to reference $reffn") # load the reference image refimg = Images.load(reffn) @@ -115,10 +122,16 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0, # to blur together when comparing images Images.@test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps) + # we passed! + info("Reference image $reffn matches") + return true + catch ex + warn("Image did not match reference image $reffn") if isinteractive() # if we're in interactive mode, open a popup and give us a chance to examine the images + warn("Should we make this the new reference image?") compareToReferenceImage(tmpfn, reffn) return @@ -131,13 +144,9 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0, end end -function image_comparison_tests(pkg::Symbol; debug = false) +function image_comparison_tests(pkg::Symbol; skip = [], debug = false, sigma = [1,1], eps = 1e-3) for i in 1:length(PlotExamples.examples) - # try - image_comparison_tests(pkgname, i, debug=debug) - # catch ex - # # TODO: put error info into markdown? - # warn("Example $pkgname:$i:$(examples[i].header) failed with: $ex") - # end + i in skip && continue + @fact image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) --> true end end diff --git a/test/refimg/v0.4/gadfly/ref1.png b/test/refimg/v0.4/gadfly/ref1.png new file mode 100644 index 00000000..4741e61d Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref1.png differ diff --git a/test/refimg/v0.4/gadfly/ref10.png b/test/refimg/v0.4/gadfly/ref10.png new file mode 100644 index 00000000..e7138377 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref10.png differ diff --git a/test/refimg/v0.4/gadfly/ref11.png b/test/refimg/v0.4/gadfly/ref11.png new file mode 100644 index 00000000..cafa4e63 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref11.png differ diff --git a/test/refimg/v0.4/gadfly/ref12.png b/test/refimg/v0.4/gadfly/ref12.png new file mode 100644 index 00000000..bd66bccd Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref12.png differ diff --git a/test/refimg/v0.4/gadfly/ref13.png b/test/refimg/v0.4/gadfly/ref13.png new file mode 100644 index 00000000..eba12f06 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref13.png differ diff --git a/test/refimg/v0.4/gadfly/ref14.png b/test/refimg/v0.4/gadfly/ref14.png new file mode 100644 index 00000000..6f4d40d5 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref14.png differ diff --git a/test/refimg/v0.4/gadfly/ref15.png b/test/refimg/v0.4/gadfly/ref15.png new file mode 100644 index 00000000..20cd5c62 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref15.png differ diff --git a/test/refimg/v0.4/gadfly/ref16.png b/test/refimg/v0.4/gadfly/ref16.png new file mode 100644 index 00000000..e665c750 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref16.png differ diff --git a/test/refimg/v0.4/gadfly/ref17.png b/test/refimg/v0.4/gadfly/ref17.png new file mode 100644 index 00000000..787e4ba7 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref17.png differ diff --git a/test/refimg/v0.4/gadfly/ref18.png b/test/refimg/v0.4/gadfly/ref18.png new file mode 100644 index 00000000..445cb910 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref18.png differ diff --git a/test/refimg/v0.4/gadfly/ref2.png b/test/refimg/v0.4/gadfly/ref2.png new file mode 100644 index 00000000..39e204d7 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref2.png differ diff --git a/test/refimg/v0.4/gadfly/ref20.png b/test/refimg/v0.4/gadfly/ref20.png new file mode 100644 index 00000000..f3be26d8 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref20.png differ diff --git a/test/refimg/v0.4/gadfly/ref21.png b/test/refimg/v0.4/gadfly/ref21.png new file mode 100644 index 00000000..e1f3116b Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref21.png differ diff --git a/test/refimg/v0.4/gadfly/ref3.png b/test/refimg/v0.4/gadfly/ref3.png new file mode 100644 index 00000000..32e07feb Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref3.png differ diff --git a/test/refimg/v0.4/gadfly/ref4.png b/test/refimg/v0.4/gadfly/ref4.png new file mode 100644 index 00000000..7322381b Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref4.png differ diff --git a/test/refimg/v0.4/gadfly/ref5.png b/test/refimg/v0.4/gadfly/ref5.png new file mode 100644 index 00000000..a17bc594 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref5.png differ diff --git a/test/refimg/v0.4/gadfly/ref6.png b/test/refimg/v0.4/gadfly/ref6.png new file mode 100644 index 00000000..63cdb69d Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref6.png differ diff --git a/test/refimg/v0.4/gadfly/ref7.png b/test/refimg/v0.4/gadfly/ref7.png new file mode 100644 index 00000000..423b9e87 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref7.png differ diff --git a/test/refimg/v0.4/gadfly/ref8.png b/test/refimg/v0.4/gadfly/ref8.png new file mode 100644 index 00000000..e8475cf2 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref8.png differ diff --git a/test/refimg/v0.4/gadfly/ref9.png b/test/refimg/v0.4/gadfly/ref9.png new file mode 100644 index 00000000..8959c3b2 Binary files /dev/null and b/test/refimg/v0.4/gadfly/ref9.png differ diff --git a/test/runtests.jl b/test/runtests.jl index 7f64d7f7..f2292276 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,11 +3,17 @@ module PlotsTests using Plots using FactCheck +# note: wrap first include in a try block because of the ImageMagick init_deps bug +try + include("imgcomp.jl") +end +include("imgcomp.jl") + # don't actually show the plots srand(1234) # note: we wrap in a try block so that the tests only run if we have the backend installed -try +# try Pkg.installed("Gadfly") gadfly() backend() @@ -28,60 +34,55 @@ try # plot(x::AMat, y::AMat; kw...) # multiple lines (one per column of x/y... will assert size(x) == size(y)) @fact plot!(rand(10,3), rand(10,3)) --> not(nothing) - # @fact_throws plot!(rand(10,3), rand(10,2)) + image_comparison_tests(:gadfly, skip=[19]) - # plot(x::AVec, y::AVec{AVec}; kw...) # multiple lines, will assert length(x) == length(y[i]) - - - # plot(x::AVec{AVec}, y::AVec{AVec}; kw...) # multiple lines, will assert length(x[i]) == length(y[i]) - # plot(n::Integer; kw...) # n lines, all empty (for updating plots) end -catch err - warn("Skipped Gadfly due to: ", string(err)) -end +# catch err +# warn("Skipped Gadfly due to: ", string(err)) +# end -# note: we wrap in a try block so that the tests only run if we have the backend installed -try - Pkg.installed("Qwt") - qwt() - backend() - facts("Qwt") do - @fact backend(:qwt) --> Plots.QwtPackage() - @fact backend() --> Plots.QwtPackage() - @fact typeof(plot(1:10)) --> Plots.Plot{Plots.QwtPackage} +# # note: we wrap in a try block so that the tests only run if we have the backend installed +# try +# Pkg.installed("Qwt") +# qwt() +# backend() +# facts("Qwt") do +# @fact backend(:qwt) --> Plots.QwtPackage() +# @fact backend() --> Plots.QwtPackage() +# @fact typeof(plot(1:10)) --> Plots.Plot{Plots.QwtPackage} - # plot(y::AVec; kw...) # one line... x = 1:length(y) - @fact plot(1:10) --> not(nothing) - @fact length(current().o.lines) --> 1 +# # plot(y::AVec; kw...) # one line... x = 1:length(y) +# @fact plot(1:10) --> not(nothing) +# @fact length(current().o.lines) --> 1 - # plot(x::AVec, f::Function; kw...) # one line, y = f(x) - @fact plot(1:10, sin) --> not(nothing) - @fact current().o.lines[1].y --> sin(collect(1:10)) +# # plot(x::AVec, f::Function; kw...) # one line, y = f(x) +# @fact plot(1:10, sin) --> not(nothing) +# @fact current().o.lines[1].y --> sin(collect(1:10)) - # plot(x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ) - @fact plot(rand(10,2), sin) --> not(nothing) - @fact length(current().o.lines) --> 2 +# # plot(x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ) +# @fact plot(rand(10,2), sin) --> not(nothing) +# @fact length(current().o.lines) --> 2 - # plot(y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1) - @fact plot!(rand(10,2)) --> not(nothing) - @fact length(current().o.lines) --> 4 +# # plot(y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1) +# @fact plot!(rand(10,2)) --> not(nothing) +# @fact length(current().o.lines) --> 4 - # plot(x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ) - @fact plot(1:10, Function[sin,cos]) --> not(nothing) - @fact current().o.lines[1].y --> sin(collect(1:10)) - @fact current().o.lines[2].y --> cos(collect(1:10)) +# # plot(x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ) +# @fact plot(1:10, Function[sin,cos]) --> not(nothing) +# @fact current().o.lines[1].y --> sin(collect(1:10)) +# @fact current().o.lines[2].y --> cos(collect(1:10)) - # plot(y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i]) - @fact plot([11:20 ; rand(10)]) --> not(nothing) - @fact current().o.lines[1].x[4] --> 4 - @fact current().o.lines[1].y[4] --> 14 - end -catch err - warn("Skipped Qwt due to: ", string(err)) -end +# # plot(y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i]) +# @fact plot([11:20 ; rand(10)]) --> not(nothing) +# @fact current().o.lines[1].x[4] --> 4 +# @fact current().o.lines[1].y[4] --> 14 +# end +# catch err +# warn("Skipped Qwt due to: ", string(err)) +# end -try +# try Pkg.installed("PyPlot") pyplot() backend() @@ -89,38 +90,40 @@ try @fact backend(:pyplot) --> Plots.PyPlotPackage() @fact backend() --> Plots.PyPlotPackage() @fact typeof(plot(1:10)) --> Plots.Plot{Plots.PyPlotPackage} + + image_comparison_tests(:pyplot, skip=[19]) end -catch err - warn("Skipped PyPlot due to: ", string(err)) -end +# catch err +# warn("Skipped PyPlot due to: ", string(err)) +# end -try - Pkg.installed("UnicodePlots") - unicodeplots() - backend() - facts("UnicodePlots") do - @fact backend(:unicodeplots) --> Plots.UnicodePlotsPackage() - @fact backend() --> Plots.UnicodePlotsPackage() - @fact typeof(plot(1:10)) --> Plots.Plot{Plots.UnicodePlotsPackage} - end -catch err - warn("Skipped UnicodePlots due to: ", string(err)) -end +# try +# Pkg.installed("UnicodePlots") +# unicodeplots() +# backend() +# facts("UnicodePlots") do +# @fact backend(:unicodeplots) --> Plots.UnicodePlotsPackage() +# @fact backend() --> Plots.UnicodePlotsPackage() +# @fact typeof(plot(1:10)) --> Plots.Plot{Plots.UnicodePlotsPackage} +# end +# catch err +# warn("Skipped UnicodePlots due to: ", string(err)) +# end -try - Pkg.installed("Winston") - winston() - backend() - facts("Winston") do - @fact backend(:winston) --> Plots.WinstonPackage() - @fact backend() --> Plots.WinstonPackage() - @fact typeof(plot(1:10)) --> Plots.Plot{Plots.WinstonPackage} - end -catch err - warn("Skipped Winston due to: ", string(err)) -end +# try +# Pkg.installed("Winston") +# winston() +# backend() +# facts("Winston") do +# @fact backend(:winston) --> Plots.WinstonPackage() +# @fact backend() --> Plots.WinstonPackage() +# @fact typeof(plot(1:10)) --> Plots.Plot{Plots.WinstonPackage} +# end +# catch err +# warn("Skipped Winston due to: ", string(err)) +# end FactCheck.exitstatus()