From 0fdb48bda323e1a842fca20ed11816f79187a359 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Tue, 16 Feb 2016 16:22:54 -0500 Subject: [PATCH] fixes for ticks --- src/args.jl | 6 ++++++ src/backends/gadfly.jl | 2 +- src/backends/plotly.jl | 5 ----- src/backends/pyplot.jl | 3 ++- src/utils.jl | 1 + test/imgcomp.jl | 20 ++++++++++++++------ 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/args.jl b/src/args.jl index 387a5f1c..2f57f0ec 100644 --- a/src/args.jl +++ b/src/args.jl @@ -518,6 +518,12 @@ function preprocessArgs!(d::Dict) processAxisArg(d, axisletter, arg) end delete!(d, asym) + + # turn :labels into :ticks_and_labels + tsym = symbol(axisletter * "ticks") + if haskey(d, tsym) && ticksType(d[tsym]) == :labels + d[tsym] = (1:length(d[tsym]), d[tsym]) + end end # handle line args diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index bf8ca178..48cff987 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -369,7 +369,7 @@ function addGadflyTicksGuide(gplt, ticks, isx::Bool) gfunc = isx ? Gadfly.Scale.x_discrete : Gadfly.Scale.y_discrete labelmap = Dict(zip(ticks...)) labelfunc = val -> labelmap[val] - push!(gplt.scales, gfunc(levels = ticks[1], labels = labelfunc)) + push!(gplt.scales, gfunc(levels = collect(ticks[1]), labels = labelfunc)) else error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 184a434c..2c2b86bc 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -27,11 +27,6 @@ function _initialize_backend(::PlotlyPackage; kw...) # end borrowing (thanks :) ########################### - # try - # include(joinpath(Pkg.dir("Plots"), "src", "backends", "plotly_blink.jl")) - # catch err - # warn("Error including PlotlyJS: $err\n Note: Will fall back to built-in display.") - # end end # TODO: other initialization end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 7fbc1fab..1f280ef0 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -493,7 +493,8 @@ function addPyPlotTicks(ax, ticks, isx::Bool) if ttype == :ticks ax[isx ? :set_xticks : :set_yticks](ticks) elseif ttype == :ticks_and_labels - ax[isx ? :set_xticks : :set_yticks](ticks...) + ax[isx ? :set_xticks : :set_yticks](ticks[1]) + ax[isx ? :set_xticklabels : :set_yticklabels](ticks[2]) else error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks) end diff --git a/src/utils.jl b/src/utils.jl index b0980e14..5bc7d6dc 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -206,6 +206,7 @@ isscalar(::Any) = false # ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits ticksType{T<:Real}(ticks::AVec{T}) = :ticks +ticksType{T<:AbstractString}(ticks::AVec{T}) = :labels ticksType{T<:AVec,S<:AVec}(ticks::@compat(Tuple{T,S})) = :ticks_and_labels ticksType(ticks) = :invalid diff --git a/test/imgcomp.jl b/test/imgcomp.jl index 85ff1266..bfc233df 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -16,6 +16,9 @@ using Plots, FactCheck default(size=(500,300)) +# reference image directory setup +_refdir = joinpath(Pkg.dir("ExamplePlots"), "test", "refimg", string(pkg)) + # 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) @@ -37,23 +40,28 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is png(fn) end - # reference image directory setup - refdir = joinpath(Pkg.dir("ExamplePlots"), "test", "refimg", string(pkg)) try - run(`mkdir -p $refdir`) + run(`mkdir -p $(_refdir)`) catch err display(err) end - reffn = joinpath(refdir, "ref$idx.png") + reffn = joinpath(_refdir, "ref$idx.png") # the test vtest = VisualTest(func, reffn, idx) test_images(vtest, popup=popup, sigma=sigma, eps=eps) end -function image_comparison_facts(pkg::Symbol; skip = [], debug = false, sigma = [1,1], eps = 1e-2) +function image_comparison_facts(pkg::Symbol; + skip = [], # skip these examples (int index) + only = nothing, # limit to these examples (int index) + debug = false, # print debug information? + sigma = [1,1], # number of pixels to "blur" + eps = 1e-2) # acceptable error (percent) for i in 1:length(ExamplePlots._examples) i in skip && continue - @fact image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success --> true + if only == nothing || i in only + @fact image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success --> true + end end end