From 3ccd1bc3685b01288c227f8fd29fe2f40f34586e Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 18 Jul 2016 15:00:02 -0400 Subject: [PATCH] added Showoff dependency; fix PLOTS_DEFAULTS; fix auto fill to 0; fix scale warning; tick labels with Showoff; fontsize in GR; travis deps --- REQUIRE | 1 + src/Plots.jl | 5 +++-- src/args.jl | 12 ++++++------ src/axes.jl | 29 ++++++++++++++++++++++++++--- src/backends/gr.jl | 4 ++-- src/output.jl | 39 +++++++++++++++++++-------------------- src/recipes.jl | 2 +- test/REQUIRE | 2 ++ test/runtests.jl | 2 +- test/travis_commands.jl | 11 ++++++----- 10 files changed, 67 insertions(+), 40 deletions(-) diff --git a/REQUIRE b/REQUIRE index 915d34df..0303ac8f 100644 --- a/REQUIRE +++ b/REQUIRE @@ -6,3 +6,4 @@ Reexport Compat FixedSizeArrays Measures +Showoff diff --git a/src/Plots.jl b/src/Plots.jl index 6affa79d..8caff4de 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -11,6 +11,7 @@ using FixedSizeArrays @reexport using RecipesBase using Base.Meta @reexport using PlotUtils +import Showoff export AbstractPlot, @@ -236,8 +237,8 @@ function __init__() setup_ijulia() setup_atom() - if haskey(ENV, "PLOTS_DEFAULTS") - for (k,v) in eval(parse(ENV["PLOTS_DEFAULTS"])) + if isdefined(Main, :PLOTS_DEFAULTS) + for (k,v) in Main.PLOTS_DEFAULTS default(k, v) end end diff --git a/src/args.jl b/src/args.jl index 0a03355c..82a4e822 100644 --- a/src/args.jl +++ b/src/args.jl @@ -585,15 +585,15 @@ end function processFillArg(d::KW, arg) - fr = get(d, :fillrange, 0) + # fr = get(d, :fillrange, 0) if typeof(arg) <: Brush - arg.size == nothing || (fr = arg.size) + arg.size == nothing || (d[:fillrange] = arg.size) arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : plot_color(arg.color)) arg.alpha == nothing || (d[:fillalpha] = arg.alpha) # fillrange function elseif allFunctions(arg) - fr = arg + d[:fillrange] = arg # fillalpha elseif allAlphas(arg) @@ -601,9 +601,9 @@ function processFillArg(d::KW, arg) elseif !handleColors!(d, arg, :fillcolor) - fr = arg + d[:fillrange] = arg end - d[:fillrange] = fr + # d[:fillrange] = fr return end @@ -778,7 +778,7 @@ function warnOnUnsupported(pkg::AbstractBackend, d::KW) end function warnOnUnsupported_scales(pkg::AbstractBackend, d::KW) - for k in (:xscale, :yscale, :zscale) + for k in (:xscale, :yscale, :zscale, :scale) if haskey(d, k) v = d[k] v = get(_scaleAliases, v, v) diff --git a/src/axes.jl b/src/axes.jl index 5e78b1a3..ce9e3260 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -129,9 +129,18 @@ const _inv_scale_funcs = Dict{Symbol,Function}( :ln => exp, ) +const _label_func = Dict{Symbol,Function}( + :log10 => x -> "10^$x", + :log2 => x -> "2^$x", + :ln => x -> "e^$x", + # :log2 => exp2, + # :ln => exp, +) + scalefunc(scale::Symbol) = x -> get(_scale_funcs, scale, identity)(Float64(x)) invscalefunc(scale::Symbol) = x -> get(_inv_scale_funcs, scale, identity)(Float64(x)) +labelfunc(scale::Symbol) = get(_label_func, scale, string) function optimal_ticks_and_labels(axis::Axis, ticks = nothing) lims = axis_limits(axis) @@ -139,18 +148,32 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) # scale the limits scale = axis[:scale] scaled_lims = map(scalefunc(scale), lims) + # @show lims scaled_lims # get a list of well-laid-out ticks cv = if ticks == nothing - optimize_ticks(scaled_lims...)[1] + optimize_ticks(scaled_lims..., + k_min = 5, # minimum number of ticks + k_max = 8, # maximum number of ticks + span_buffer = 0.0 # padding buffer in case nice ticks are closeby + )[1] else ticks end + # # expand to ensure we see all the ticks + # expand_extrema!(axis, cv) + # rescale and return values and labels + # @show cv + ticklabels = map(labelfunc(scale), Showoff.showoff(cv, :plain)) + tickvals = map(invscalefunc(scale), cv) - basestr = scale == :log10 ? "10^" : scale == :log2 ? "2^" : scale == :ln ? "e^" : "" - tickvals, ["$basestr$cvi" for cvi in cv] + # @show tickvals ticklabels + # ticklabels = Showoff.showoff(tickvals, scale == :log10 ? :scientific : :auto) + tickvals, ticklabels + # basestr = scale == :log10 ? "10^" : scale == :log2 ? "2^" : scale == :ln ? "e^" : "" + # tickvals, ["$basestr$cvi" for cvi in cv] end # return (continuous_values, discrete_values) for the ticks on this axis diff --git a/src/backends/gr.jl b/src/backends/gr.jl index cc81f90b..b093e631 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -448,7 +448,7 @@ function gr_display(plt::Plot) # update point mult px_per_pt = px / pt - _gr_point_mult[1] = px_per_pt / max(h,w) + _gr_point_mult[1] = 1.5 * px_per_pt / max(h,w) # subplots: for sp in plt.subplots @@ -566,7 +566,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end xticks, yticks, spine_segs, grid_segs = axis_drawing_info(sp) - # @show xticks yticks spine_segs grid_segs + # @show xticks yticks #spine_segs grid_segs # draw the grid lines if sp[:grid] diff --git a/src/output.jl b/src/output.jl index 12852900..e115a4bf 100644 --- a/src/output.jl +++ b/src/output.jl @@ -147,14 +147,15 @@ function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) end end +function _writemime(io::IO, m, plt::Plot) + warn("_writemime is not defined for this backend. m=", string(m)) +end +function _display(plt::Plot) + warn("_display is not defined for this backend.") +end + # for writing to io streams... first prepare, then callback for mime in keys(_mimeformats) - @eval function _writemime(io::IO, m, plt::Plot) - warn("_writemime is not defined for this backend. m=", string(m)) - end - @eval function _display(plt::Plot) - warn("_display is not defined for this backend.") - end @eval function Base.writemime(io::IO, m::MIME{Symbol($mime)}, plt::Plot) prepare_output(plt) _writemime(io, m, plt) @@ -166,24 +167,22 @@ end # A backup, if no PNG generation is defined, is to try to make a PDF and use FileIO to convert if is_installed("FileIO") - @eval begin - import FileIO - function _writemime(io::IO, ::MIME"image/png", plt::Plot) - fn = tempname() + @eval import FileIO + function _writemime(io::IO, ::MIME"image/png", plt::Plot) + fn = tempname() - # first save a pdf file - pdf(plt, fn) + # first save a pdf file + pdf(plt, fn) - # load that pdf into a FileIO Stream - s = FileIO.load(fn * ".pdf") + # load that pdf into a FileIO Stream + s = FileIO.load(fn * ".pdf") - # save a png - pngfn = fn * ".png" - FileIO.save(pngfn, s) + # save a png + pngfn = fn * ".png" + FileIO.save(pngfn, s) - # now write from the file - write(io, readall(open(pngfn))) - end + # now write from the file + write(io, readall(open(pngfn))) end end diff --git a/src/recipes.jl b/src/recipes.jl index ff54c667..4db0654b 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -77,7 +77,7 @@ function seriestype_supported(pkg::AbstractBackend, st::Symbol) end macro deps(st, args...) - :(series_recipe_dependencies($(quot(st)), $(map(quot, args)...))) + :(Plots.series_recipe_dependencies($(quot(st)), $(map(quot, args)...))) end # get a list of all seriestypes diff --git a/test/REQUIRE b/test/REQUIRE index cf3ef4b9..e8355306 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -5,8 +5,10 @@ PlotUtils StatPlots Reexport Measures +Showoff FactCheck Images +ImageMagick @osx QuartzImageIO GR DataFrames diff --git a/test/runtests.jl b/test/runtests.jl index 92a491df..1c86e54e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -30,7 +30,7 @@ facts("GR") do @fact gr() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend() - # @linux_only image_comparison_facts(:gr, skip=[], eps=img_eps) + @linux_only image_comparison_facts(:gr, skip=[], eps=img_eps) end facts("Plotly") do diff --git a/test/travis_commands.jl b/test/travis_commands.jl index 5f1b7126..bb2b16e4 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -1,8 +1,8 @@ -Pkg.clone("ImageMagick") -Pkg.build("ImageMagick") +# Pkg.clone("ImageMagick") +# Pkg.build("ImageMagick") -Pkg.clone("GR") -Pkg.build("GR") +# Pkg.clone("GR") +# Pkg.build("GR") Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") @@ -17,8 +17,9 @@ Pkg.clone("StatPlots") # Pkg.clone("https://github.com/spencerlyon2/PlotlyJS.jl.git") # Pkg.checkout("RecipesBase") -Pkg.clone("VisualRegressionTests") +# Pkg.clone("VisualRegressionTests") +# need this to use Conda ENV["PYTHON"] = "" Pkg.add("PyPlot") Pkg.build("PyPlot")