added Showoff dependency; fix PLOTS_DEFAULTS; fix auto fill to 0; fix scale warning; tick labels with Showoff; fontsize in GR; travis deps

This commit is contained in:
Thomas Breloff 2016-07-18 15:00:02 -04:00
parent 624d33b96f
commit 3ccd1bc368
10 changed files with 67 additions and 40 deletions

View File

@ -6,3 +6,4 @@ Reexport
Compat Compat
FixedSizeArrays FixedSizeArrays
Measures Measures
Showoff

View File

@ -11,6 +11,7 @@ using FixedSizeArrays
@reexport using RecipesBase @reexport using RecipesBase
using Base.Meta using Base.Meta
@reexport using PlotUtils @reexport using PlotUtils
import Showoff
export export
AbstractPlot, AbstractPlot,
@ -236,8 +237,8 @@ function __init__()
setup_ijulia() setup_ijulia()
setup_atom() setup_atom()
if haskey(ENV, "PLOTS_DEFAULTS") if isdefined(Main, :PLOTS_DEFAULTS)
for (k,v) in eval(parse(ENV["PLOTS_DEFAULTS"])) for (k,v) in Main.PLOTS_DEFAULTS
default(k, v) default(k, v)
end end
end end

View File

@ -585,15 +585,15 @@ end
function processFillArg(d::KW, arg) function processFillArg(d::KW, arg)
fr = get(d, :fillrange, 0) # fr = get(d, :fillrange, 0)
if typeof(arg) <: Brush 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.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : plot_color(arg.color))
arg.alpha == nothing || (d[:fillalpha] = arg.alpha) arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
# fillrange function # fillrange function
elseif allFunctions(arg) elseif allFunctions(arg)
fr = arg d[:fillrange] = arg
# fillalpha # fillalpha
elseif allAlphas(arg) elseif allAlphas(arg)
@ -601,9 +601,9 @@ function processFillArg(d::KW, arg)
elseif !handleColors!(d, arg, :fillcolor) elseif !handleColors!(d, arg, :fillcolor)
fr = arg d[:fillrange] = arg
end end
d[:fillrange] = fr # d[:fillrange] = fr
return return
end end
@ -778,7 +778,7 @@ function warnOnUnsupported(pkg::AbstractBackend, d::KW)
end end
function warnOnUnsupported_scales(pkg::AbstractBackend, d::KW) function warnOnUnsupported_scales(pkg::AbstractBackend, d::KW)
for k in (:xscale, :yscale, :zscale) for k in (:xscale, :yscale, :zscale, :scale)
if haskey(d, k) if haskey(d, k)
v = d[k] v = d[k]
v = get(_scaleAliases, v, v) v = get(_scaleAliases, v, v)

View File

@ -129,9 +129,18 @@ const _inv_scale_funcs = Dict{Symbol,Function}(
:ln => exp, :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)) scalefunc(scale::Symbol) = x -> get(_scale_funcs, scale, identity)(Float64(x))
invscalefunc(scale::Symbol) = x -> get(_inv_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) function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
lims = axis_limits(axis) lims = axis_limits(axis)
@ -139,18 +148,32 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
# scale the limits # scale the limits
scale = axis[:scale] scale = axis[:scale]
scaled_lims = map(scalefunc(scale), lims) scaled_lims = map(scalefunc(scale), lims)
# @show lims scaled_lims
# get a list of well-laid-out ticks # get a list of well-laid-out ticks
cv = if ticks == nothing 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 else
ticks ticks
end end
# # expand to ensure we see all the ticks
# expand_extrema!(axis, cv)
# rescale and return values and labels # rescale and return values and labels
# @show cv
ticklabels = map(labelfunc(scale), Showoff.showoff(cv, :plain))
tickvals = map(invscalefunc(scale), cv) tickvals = map(invscalefunc(scale), cv)
basestr = scale == :log10 ? "10^" : scale == :log2 ? "2^" : scale == :ln ? "e^" : "" # @show tickvals ticklabels
tickvals, ["$basestr$cvi" for cvi in cv] # 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 end
# return (continuous_values, discrete_values) for the ticks on this axis # return (continuous_values, discrete_values) for the ticks on this axis

View File

@ -448,7 +448,7 @@ function gr_display(plt::Plot)
# update point mult # update point mult
px_per_pt = px / pt 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: # subplots:
for sp in plt.subplots for sp in plt.subplots
@ -566,7 +566,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
xticks, yticks, spine_segs, grid_segs = axis_drawing_info(sp) 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 # draw the grid lines
if sp[:grid] if sp[:grid]

View File

@ -147,14 +147,15 @@ function Base.writemime(io::IO, ::MIME"text/html", plt::Plot)
end end
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 writing to io streams... first prepare, then callback
for mime in keys(_mimeformats) 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) @eval function Base.writemime(io::IO, m::MIME{Symbol($mime)}, plt::Plot)
prepare_output(plt) prepare_output(plt)
_writemime(io, m, 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 # A backup, if no PNG generation is defined, is to try to make a PDF and use FileIO to convert
if is_installed("FileIO") if is_installed("FileIO")
@eval begin @eval import FileIO
import FileIO function _writemime(io::IO, ::MIME"image/png", plt::Plot)
function _writemime(io::IO, ::MIME"image/png", plt::Plot) fn = tempname()
fn = tempname()
# first save a pdf file # first save a pdf file
pdf(plt, fn) pdf(plt, fn)
# load that pdf into a FileIO Stream # load that pdf into a FileIO Stream
s = FileIO.load(fn * ".pdf") s = FileIO.load(fn * ".pdf")
# save a png # save a png
pngfn = fn * ".png" pngfn = fn * ".png"
FileIO.save(pngfn, s) FileIO.save(pngfn, s)
# now write from the file # now write from the file
write(io, readall(open(pngfn))) write(io, readall(open(pngfn)))
end
end end
end end

View File

@ -77,7 +77,7 @@ function seriestype_supported(pkg::AbstractBackend, st::Symbol)
end end
macro deps(st, args...) macro deps(st, args...)
:(series_recipe_dependencies($(quot(st)), $(map(quot, args)...))) :(Plots.series_recipe_dependencies($(quot(st)), $(map(quot, args)...)))
end end
# get a list of all seriestypes # get a list of all seriestypes

View File

@ -5,8 +5,10 @@ PlotUtils
StatPlots StatPlots
Reexport Reexport
Measures Measures
Showoff
FactCheck FactCheck
Images Images
ImageMagick
@osx QuartzImageIO @osx QuartzImageIO
GR GR
DataFrames DataFrames

View File

@ -30,7 +30,7 @@ facts("GR") do
@fact gr() --> Plots.GRBackend() @fact gr() --> Plots.GRBackend()
@fact backend() --> 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 end
facts("Plotly") do facts("Plotly") do

View File

@ -1,8 +1,8 @@
Pkg.clone("ImageMagick") # Pkg.clone("ImageMagick")
Pkg.build("ImageMagick") # Pkg.build("ImageMagick")
Pkg.clone("GR") # Pkg.clone("GR")
Pkg.build("GR") # Pkg.build("GR")
Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") 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.clone("https://github.com/spencerlyon2/PlotlyJS.jl.git")
# Pkg.checkout("RecipesBase") # Pkg.checkout("RecipesBase")
Pkg.clone("VisualRegressionTests") # Pkg.clone("VisualRegressionTests")
# need this to use Conda
ENV["PYTHON"] = "" ENV["PYTHON"] = ""
Pkg.add("PyPlot") Pkg.add("PyPlot")
Pkg.build("PyPlot") Pkg.build("PyPlot")