From f60ad6489cf7f063bf118b11e43c4bbbb55a6dfd Mon Sep 17 00:00:00 2001 From: "Ralph A. Smith" Date: Sun, 17 Jun 2018 17:23:42 -0400 Subject: [PATCH] revisions for Julia 0.7 --- REQUIRE | 3 +-- src/Plots.jl | 23 +++++++++++++++++++++-- src/args.jl | 17 +++++++++++------ src/axes.jl | 2 +- src/backends/glvisualize.jl | 2 +- src/backends/gr.jl | 20 ++++++++++---------- src/backends/hdf5.jl | 14 +++++++------- src/backends/inspectdr.jl | 16 ++++++++-------- src/backends/pgfplots.jl | 2 +- src/backends/plotly.jl | 2 +- src/backends/plotlyjs.jl | 2 +- src/backends/pyplot.jl | 8 ++++---- src/backends/unicodeplots.jl | 4 ++-- src/backends/web.jl | 8 ++++---- src/components.jl | 15 +++++++++------ src/examples.jl | 10 ++++++---- src/layouts.jl | 10 +++++----- src/output.jl | 6 +++--- src/pipeline.jl | 4 ++-- src/plot.jl | 5 ++--- src/recipes.jl | 8 ++++---- src/series.jl | 20 ++++++++++---------- src/types.jl | 2 +- src/utils.jl | 22 +++++++++++----------- 24 files changed, 126 insertions(+), 99 deletions(-) diff --git a/REQUIRE b/REQUIRE index 0a637421..711d21d2 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,5 @@ julia 0.7 - +Compat 0.69 RecipesBase 0.2.3 PlotUtils 0.4.1 PlotThemes 0.1.3 @@ -7,7 +7,6 @@ Reexport StaticArrays 0.5 FixedPointNumbers 0.3 Measures -Dates Showoff StatsBase 0.14.0 JSON diff --git a/src/Plots.jl b/src/Plots.jl index 8c4a4d97..735aa5c6 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -12,8 +12,25 @@ import RecipesBase: plot, plot!, animate using Base.Meta @reexport using PlotUtils @reexport using PlotThemes -import Dates -import Dates.Date + +if VERSION >= v"0.7-" + import Dates + using Dates: Date, DateTime + using Printf: @printf, @sprintf + using REPL: REPLDisplay + using Base64: base64encode + using Base.Sys: isapple, islinux, iswindows, isbsd + import Pkg + const euler_e = Base.MathConstants.e +else + using Compat + using Compat.Sys: isapple, islinux, iswindows, isbsd + import Compat: maximum + maximum(arg::Tuple) = Base.maximum(arg) + using Base.REPL: REPLDisplay + const euler_e = Base.e +end + import Showoff import StatsBase import JSON @@ -266,6 +283,8 @@ xgrid!(args...; kw...) = plot!(; xgrid = args ygrid!(args...; kw...) = plot!(; ygrid = args, kw...) let PlotOrSubplot = Union{Plot, Subplot} + global title!, xlabel!, ylabel!, xlims!, ylims!, zlims!, xticks!, yticks! + global xgrid!, ygrid!, annotate!, xflip!, yflip!, xaxis!, yaxis! title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...) xlabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; xlabel = s, kw...) ylabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; ylabel = s, kw...) diff --git a/src/args.jl b/src/args.jl index 671485d0..24f12d7e 100644 --- a/src/args.jl +++ b/src/args.jl @@ -15,7 +15,7 @@ function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}) for (k,v) in aliases s = string(k) if '_' in s - aliases[Symbol(replace(s, "_", ""))] = v + aliases[Symbol(replace(s, "_" => ""))] = v end end end @@ -176,7 +176,11 @@ const _positionAliases = Dict{Symbol,Symbol}( const _allScales = [:identity, :ln, :log2, :log10, :asinh, :sqrt] const _logScales = [:ln, :log2, :log10] -const _logScaleBases = Dict(:ln => e, :log2 => 2.0, :log10 => 10.0) +const _logScaleBases = Dict( + :ln => euler_e, + :log2 => 2.0, + :log10 => 10.0 +) const _scaleAliases = Dict{Symbol,Symbol}( :none => :identity, :log => :log10, @@ -188,7 +192,7 @@ const _allGridSyms = [:x, :y, :z, :all, :both, :on, :yes, :show, :none, :off, :no, :hide] const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing] -hasgrid(arg::Void, letter) = false +hasgrid(arg::Nothing, letter) = false hasgrid(arg::Bool, letter) = arg function hasgrid(arg::Symbol, letter) if arg in _allGridSyms @@ -206,7 +210,7 @@ const _allShowaxisSyms = [:x, :y, :z, :all, :both, :on, :yes, :show, :off, :no, :hide] const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)] -showaxis(arg::Void, letter) = false +showaxis(arg::Nothing, letter) = false showaxis(arg::Bool, letter) = arg function showaxis(arg::Symbol, letter) if arg in _allGridSyms @@ -654,6 +658,7 @@ function handleColors!(d::KW, arg, csym::Symbol) d[csym] = c end return true + catch end false end @@ -1028,7 +1033,7 @@ function extractGroupArgs(vs::Tuple, args...) end # allow passing NamedTuples for a named legend entry -@require NamedTuples begin +@require NamedTuples="73a701b4-84e1-5df0-88ff-1968ee2ee8dc" begin legendEntryFromTuple(ns::NamedTuples.NamedTuple) = join(["$k = $v" for (k, v) in zip(keys(ns), values(ns))], ", ") @@ -1131,7 +1136,7 @@ function convertLegendValue(val::Symbol) end end convertLegendValue(val::Bool) = val ? :best : :none -convertLegendValue(val::Void) = :none +convertLegendValue(val::Nothing) = :none convertLegendValue(v::Tuple{S,T}) where {S<:Real, T<:Real} = v convertLegendValue(v::AbstractArray) = map(convertLegendValue, v) diff --git a/src/axes.jl b/src/axes.jl index 1410b28b..5e422837 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -310,7 +310,7 @@ function expand_extrema!(axis::Axis, v::Number) end # these shouldn't impact the extrema -expand_extrema!(axis::Axis, ::Void) = axis[:extrema] +expand_extrema!(axis::Axis, ::Nothing) = axis[:extrema] expand_extrema!(axis::Axis, ::Bool) = axis[:extrema] diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index b8a4ed04..241609d0 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -9,7 +9,7 @@ TODO * fix units in all visuals (e.g dotted lines, marker scale, surfaces) =# -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl")) end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d8605ea5..5e01e23c 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -3,7 +3,7 @@ # significant contributions by @jheinen -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl")) end @@ -144,7 +144,7 @@ gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(_cycle(c,1))) gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1))) gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1))) gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1)) -function gr_set_transparency(::Void) end +function gr_set_transparency(::Nothing) end # -------------------------------------------------------------------------------------- @@ -196,7 +196,7 @@ gr_inqtext(x, y, s::Symbol) = gr_inqtext(x, y, string(s)) function gr_inqtext(x, y, s) if length(s) >= 2 && s[1] == '$' && s[end] == '$' GR.inqtextext(x, y, s[2:end-1]) - elseif search(s, '\\') != 0 || contains(s, "10^{") + elseif something(findfirst(isequal('\\'), s), 0) != 0 || occursin("10^{", s) GR.inqtextext(x, y, s) else GR.inqtext(x, y, s) @@ -208,7 +208,7 @@ gr_text(x, y, s::Symbol) = gr_text(x, y, string(s)) function gr_text(x, y, s) if length(s) >= 2 && s[1] == '$' && s[end] == '$' GR.mathtex(x, y, s[2:end-1]) - elseif search(s, '\\') != 0 || contains(s, "10^{") + elseif something(findfirst(isequal('\\'), s), 0) != 0 || occursin("10^{", s) GR.textext(x, y, s) else GR.text(x, y, s) @@ -502,16 +502,16 @@ function gr_legend_pos(s::Symbol,w,h) if str == "best" str = "topright" end - if contains(str,"right") + if occursin("right",str) xpos = viewport_plotarea[2] - 0.05 - w - elseif contains(str,"left") + elseif occursin("left",str) xpos = viewport_plotarea[1] + 0.11 else xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 - w/2 +.04 end - if contains(str,"top") + if occursin("top",str) ypos = viewport_plotarea[4] - 0.06 - elseif contains(str,"bottom") + elseif occursin("bottom",str) ypos = viewport_plotarea[3] + h + 0.06 else ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + h/2 @@ -1358,10 +1358,10 @@ const _gr_mimeformats = Dict( "image/svg+xml" => "svg", ) -const _gr_wstype_default = @static if is_linux() +const _gr_wstype_default = @static if islinux() "x11" # "cairox11" -elseif is_apple() +elseif isapple() "quartz" else "use_default" diff --git a/src/backends/hdf5.jl b/src/backends/hdf5.jl index 4de26b71..171bf4ea 100644 --- a/src/backends/hdf5.jl +++ b/src/backends/hdf5.jl @@ -28,7 +28,7 @@ Read from .hdf5 file using: - Should be reliable for archival purposes. ==# -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "hdf5.jl")) end @@ -39,7 +39,7 @@ struct HDF5PlotNative; end #Indentifies a data element that can natively be hand struct HDF5CTuple; end #Identifies a "complex" tuple structure mutable struct HDF5Plot_PlotRef - ref::Union{Plot, Void} + ref::Union{Plot, Nothing} end @@ -148,7 +148,7 @@ function _initialize_backend(::HDF5Backend) #Possible element types of high-level data types: const telem2str = Dict{String, Type}( "NATIVE" => HDF5PlotNative, - "VOID" => Void, + "VOID" => Nothing, "BOOL" => Bool, "SYMBOL" => Symbol, "TUPLE" => Tuple, @@ -315,9 +315,9 @@ function _hdf5plot_gwrite(grp, k::String, v::Array{Any}) warn("Cannot write Array: $k=$v") end =# -function _hdf5plot_gwrite(grp, k::String, v::Void) +function _hdf5plot_gwrite(grp, k::String, v::Nothing) grp[k] = 0 - _hdf5plot_writetype(grp, k, Void) + _hdf5plot_writetype(grp, k, Nothing) end function _hdf5plot_gwrite(grp, k::String, v::Bool) grp[k] = Int(v) @@ -344,7 +344,7 @@ end function _hdf5plot_gwrite(grp, k::String, d::Dict) # warn("Cannot write dict: $k=$d") end -function _hdf5plot_gwrite(grp, k::String, v::Range) +function _hdf5plot_gwrite(grp, k::String, v::AbstractRange) _hdf5plot_gwrite(grp, k, collect(v)) #For now end function _hdf5plot_gwrite(grp, k::String, v::ARGB{N0f8}) @@ -476,7 +476,7 @@ function _hdf5plot_readcount(grp) #Read directly from group end _hdf5plot_convert(T::Type{HDF5PlotNative}, v) = v -_hdf5plot_convert(T::Type{Void}, v) = nothing +_hdf5plot_convert(T::Type{Nothing}, v) = nothing _hdf5plot_convert(T::Type{Bool}, v) = (v!=0) _hdf5plot_convert(T::Type{Symbol}, v) = Symbol(v) _hdf5plot_convert(T::Type{Tuple}, v) = tuple(v...) #With Vector{T<:Number} diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 2a22055f..b54c987f 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -13,7 +13,7 @@ Add in functionality to Plots.jl: :aspect_ratio, =# -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl")) end @@ -166,13 +166,13 @@ function _initialize_backend(::InspectDRBackend; kw...) export InspectDR #Glyph used when plotting "Shape"s: - const INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline( + INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline( 2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y ) mutable struct InspecDRPlotRef - mplot::Union{Void, InspectDR.Multiplot} - gui::Union{Void, InspectDR.GtkPlot} + mplot::Union{Nothing, InspectDR.Multiplot} + gui::Union{Nothing, InspectDR.GtkPlot} end _inspectdr_getmplot(::Any) = nothing @@ -347,8 +347,8 @@ end # --------------------------------------------------------------------------- function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) - const plot = sp.o - const strip = plot.strips[1] #Only 1 strip supported with Plots.jl + plot = sp.o + strip = plot.strips[1] #Only 1 strip supported with Plots.jl xaxis = sp[:xaxis]; yaxis = sp[:yaxis] xgrid_show = xaxis[:grid] @@ -406,7 +406,7 @@ end # called just before updating layout bounding boxes... in case you need to prep # for the calcs function _before_layout_calcs(plt::Plot{InspectDRBackend}) - const mplot = _inspectdr_getmplot(plt.o) + mplot = _inspectdr_getmplot(plt.o) if nothing == mplot; return; end mplot.title = plt[:plot_title] @@ -506,7 +506,7 @@ const _inspectdr_mimeformats_nodpi = Dict( # "application/postscript" => "ps", #TODO: support once Cairo supports PSSurface "application/pdf" => "pdf" ) -_inspectdr_show(io::IO, mime::MIME, ::Void, w, h) = +_inspectdr_show(io::IO, mime::MIME, ::Nothing, w, h) = throw(ErrorException("Cannot show(::IO, ...) plot - not yet generated")) function _inspectdr_show(io::IO, mime::MIME, mplot, w, h) InspectDR._show(io, mime, mplot, Float64(w), Float64(h)) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 8692dafd..93e7800b 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -2,7 +2,7 @@ # significant contributions by: @pkofod -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pgfplots.jl")) end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 333a4276..7bef25d2 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -1,7 +1,7 @@ # https://plot.ly/javascript/getting-started -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) end diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 8cbdfa5e..4b74f60a 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -1,4 +1,4 @@ -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl")) end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index c5b2947b..ed0cbd05 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1,7 +1,7 @@ # https://github.com/stevengj/PyPlot.jl -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl")) end @@ -683,8 +683,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) if typeof(z) <: AbstractMatrix || typeof(z) <: Surface x, y, z = map(Array, (x,y,z)) if !ismatrix(x) || !ismatrix(y) - x = repmat(x', length(y), 1) - y = repmat(y, 1, length(series[:x])) + x = repeat(x', length(y), 1) + y = repeat(y, 1, length(series[:x])) end z = transpose_z(series, z) if st == :surface @@ -923,7 +923,7 @@ function py_set_scale(ax, axis::Axis) "linear" else kw[Symbol(:base,letter)] = if scale == :ln - e + Base.MathConstants.e elseif scale == :log2 2 elseif scale == :log10 diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index eb48d8ad..aa5db517 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -1,7 +1,7 @@ # https://github.com/Evizero/UnicodePlots.jl -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "unicodeplots.jl")) end @@ -183,7 +183,7 @@ function png(plt::AbstractPlot{UnicodePlotsBackend}, fn::AbstractString) gui(plt) # @osx_only begin - @static if is_apple() + @static if isapple() # BEGIN HACK # wait while the plot gets drawn diff --git a/src/backends/web.jl b/src/backends/web.jl index e38ad782..875f9609 100644 --- a/src/backends/web.jl +++ b/src/backends/web.jl @@ -2,7 +2,7 @@ # NOTE: backend should implement `html_body` and `html_head` # CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl -@require Revise begin +@require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl")) end @@ -23,13 +23,13 @@ function standalone_html(plt::AbstractPlot; title::AbstractString = get(plt.attr end function open_browser_window(filename::AbstractString) - @static if is_apple() + @static if isapple() return run(`open $(filename)`) end - @static if is_linux() || is_bsd() # is_bsd() addition is as yet untested, but based on suggestion in https://github.com/JuliaPlots/Plots.jl/issues/681 + @static if islinux() || isbsd() # is_bsd() addition is as yet untested, but based on suggestion in https://github.com/JuliaPlots/Plots.jl/issues/681 return run(`xdg-open $(filename)`) end - @static if is_windows() + @static if iswindows() return run(`$(ENV["COMSPEC"]) /c start "" "$(filename)"`) end warn("Unknown OS... cannot open browser window.") diff --git a/src/components.jl b/src/components.jl index ceb87e32..081a21ba 100644 --- a/src/components.jl +++ b/src/components.jl @@ -58,7 +58,7 @@ end "get an array of tuples of points on a circle with radius `r`" function partialcircle(start_θ, end_θ, n = 20, r=1) - Tuple{Float64,Float64}[(r*cos(u),r*sin(u)) for u in linspace(start_θ, end_θ, n)] + Tuple{Float64,Float64}[(r*cos(u),r*sin(u)) for u in range(start_θ, stop=end_θ, length=n)] end "interleave 2 vectors into each other (like a zipper's teeth)" @@ -68,7 +68,8 @@ function weave(x,y; ordering = Vector[x,y]) while !done for o in ordering try - push!(ret, shift!(o)) + push!(ret, popfirst!(o)) + catch end end done = isempty(x) && isempty(y) @@ -388,6 +389,7 @@ function stroke(args...; alpha = nothing) elseif T <: Symbol || T <: AbstractString try color = parse(Colorant, string(arg)) + catch end elseif allAlphas(arg) alpha = arg @@ -420,6 +422,7 @@ function brush(args...; alpha = nothing) elseif T <: Symbol || T <: AbstractString try color = parse(Colorant, string(arg)) + catch end elseif allAlphas(arg) alpha = arg @@ -468,7 +471,7 @@ function series_annotations(strs::AbstractVector, args...) SeriesAnnotations(strs, fnt, shp, scalefactor) end series_annotations(anns::SeriesAnnotations) = anns -series_annotations(::Void) = nothing +series_annotations(::Nothing) = nothing function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) anns = series[:series_annotations] @@ -483,7 +486,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) # end # @show msw msh - if anns != nothing && !isnull(anns.baseshape) + if anns != nothing && (anns.baseshape != nothing) # we use baseshape to overwrite the markershape attribute # with a list of custom shapes for each msw,msh = anns.scalefactor @@ -531,7 +534,7 @@ function Base.next(ea::EachAnn, i) ((_cycle(ea.x,i), _cycle(ea.y,i), str, fnt), i+1) end -annotations(::Void) = [] +annotations(::Nothing) = [] annotations(anns::AVec) = anns annotations(anns) = Any[anns] annotations(sa::SeriesAnnotations) = sa @@ -747,7 +750,7 @@ end @deprecate curve_points coords -coords(curve::BezierCurve, n::Integer = 30; range = [0,1]) = map(curve, linspace(range..., n)) +coords(curve::BezierCurve, n::Integer = 30; limits = [0,1]) = map(curve, range(limits[1],stop=limits[2], length=n)) # build a BezierCurve which leaves point p vertically upwards and arrives point q vertically upwards. # may create a loop if necessary. Assumes the view is [0,1] diff --git a/src/examples.jl b/src/examples.jl index 57ed7b3e..24bca280 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -8,7 +8,9 @@ mutable struct PlotExample end # the _examples we'll run for each -const _examples = PlotExample[ +# FIXME: suppress explicit typing of array until parser is fixed +#const _examples = PlotExample[ +const _examples = [ PlotExample("Lines", "A simple line plot of the columns.", @@ -157,7 +159,7 @@ PlotExample("Marker types", markers = reshape(markers, 1, length(markers)) n = length(markers) x = linspace(0,10,n+2)[2:end-1] - y = repmat(reshape(reverse(x),1,:), n, 1) + y = repeat(reshape(reverse(x),1,:), n, 1) scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10)) end)] ), @@ -269,8 +271,8 @@ unfilled contour from a matrix. x = 1:0.5:20 y = 1:0.5:10 f(x,y) = (3x+y^2)*abs(sin(x)+cos(y)) - X = repmat(reshape(x,1,:), length(y), 1) - Y = repmat(y, 1, length(x)) + X = repeat(reshape(x,1,:), length(y), 1) + Y = repeat(y, 1, length(x)) Z = map(f, X, Y) p1 = contour(x, y, f, fill=true) p2 = contour(x, y, Z) diff --git a/src/layouts.jl b/src/layouts.jl index 63924374..ace16174 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -268,7 +268,7 @@ function GridLayout(dims...; widths = zeros(dims[2]), heights = zeros(dims[1]), kw...) - grid = Matrix{AbstractLayout}(dims...) + grid = Matrix{AbstractLayout}(undef,dims...) layout = GridLayout( parent, (20mm, 5mm, 2mm, 10mm), @@ -357,10 +357,10 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0 # get the max horizontal (left and right) padding over columns, # and max vertical (bottom and top) padding over rows # TODO: add extra padding here - pad_left = maximum(minpad_left, 1) - pad_top = maximum(minpad_top, 2) - pad_right = maximum(minpad_right, 1) - pad_bottom = maximum(minpad_bottom, 2) + pad_left = maximum(minpad_left, dims=1) + pad_top = maximum(minpad_top, dims=2) + pad_right = maximum(minpad_right, dims=1) + pad_bottom = maximum(minpad_bottom, dims=2) # make sure the perimeter match the parent pad_left[1] = max(pad_left[1], minimum_perimeter[1]) diff --git a/src/output.jl b/src/output.jl index 1f9da687..8b87604f 100644 --- a/src/output.jl +++ b/src/output.jl @@ -146,7 +146,7 @@ function Base.display(::PlotsDisplay, plt::Plot) end # override the REPL display to open a gui window -Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::Plot) = gui(plt) +Base.display(::REPLDisplay, ::MIME"text/plain", plt::Plot) = gui(plt) _do_plot_show(plt, showval::Bool) = showval && gui(plt) @@ -254,7 +254,7 @@ end # IJulia # --------------------------------------------------------- -@require IJulia begin +@require IJulia="7073ff75-c697-5162-941a-fcdaad2a7d2a" begin if IJulia.inited """ @@ -310,7 +310,7 @@ end # --------------------------------------------------------- # Atom PlotPane # --------------------------------------------------------- -@require Juno begin +@require Juno="e5e0dc1b-0480-54bc-9374-aad01c23163d" begin import Hiccup, Media if Juno.isactive() diff --git a/src/pipeline.jl b/src/pipeline.jl index d1af402d..4a7c1cd1 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -70,7 +70,7 @@ function _process_userrecipes(plt::Plot, d::KW, args) # grab the first in line to be processed and either add it to the kw_list or # pass it through apply_recipe to generate a list of RecipeData objects (data + attributes) # for further processing. - next_series = shift!(still_to_process) + next_series = popfirst!(still_to_process) # recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes if !(typeof(next_series) <: RecipeData) error("Inputs couldn't be processed... expected RecipeData but got: $next_series") @@ -329,7 +329,7 @@ function _override_seriestype_check(d::KW, st::Symbol) # do we want to override the series type? if !is3d(st) && !(st in (:contour,:contour3d)) z = d[:z] - if !isa(z, Void) && (size(d[:x]) == size(d[:y]) == size(z)) + if !isa(z, Nothing) && (size(d[:x]) == size(d[:y]) == size(z)) st = (st == :scatter ? :scatter3d : :path3d) d[:seriestype] = st end diff --git a/src/plot.jl b/src/plot.jl index 0507a57b..c6b0ed5e 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -46,9 +46,8 @@ When you pass in matrices, it splits by columns. To see the list of available at function, where `attr` is the symbol `:Series:`, `:Subplot:`, `:Plot` or `:Axis`. Pass any attribute to `plotattr` as a String to look up its docstring; e.g. `plotattr("seriestype")`. """ - -# this creates a new plot with args/kw and sets it to be the current plot function plot(args...; kw...) +# this creates a new plot with args/kw and sets it to be the current plot d = KW(kw) preprocessArgs!(d) @@ -193,7 +192,7 @@ function _plot!(plt::Plot, d::KW, args::Tuple) still_to_process = kw_list kw_list = KW[] while !isempty(still_to_process) - next_kw = shift!(still_to_process) + next_kw = popfirst!(still_to_process) _process_plotrecipe(plt, next_kw, kw_list, still_to_process) end diff --git a/src/recipes.jl b/src/recipes.jl index dfb1fd54..a246fd89 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -80,7 +80,7 @@ end @recipe function f(::Type{Val{:hline}}, x, y, z) n = length(y) - newx = repmat(Float64[-1, 1, NaN], n) + newx = repeat(Float64[-1, 1, NaN], n) newy = vec(Float64[yi for i=1:3,yi=y]) x := newx y := newy @@ -92,7 +92,7 @@ end @recipe function f(::Type{Val{:vline}}, x, y, z) n = length(y) newx = vec(Float64[yi for i=1:3,yi=y]) - newy = repmat(Float64[-1, 1, NaN], n) + newy = repeat(Float64[-1, 1, NaN], n) x := newx y := newy seriestype := :straightline @@ -620,10 +620,10 @@ _hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Symbol) where {N _hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) where {N} = binning _hist_edges(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) where {N} = - map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...)) + map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...,)) _hist_edges(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) where {N} = - map(dim -> _hist_edge(vs, dim, binning), (1:N...)) + map(dim -> _hist_edge(vs, dim, binning), (1:N...,)) _hist_norm_mode(mode::Symbol) = mode _hist_norm_mode(mode::Bool) = mode ? :pdf : :none diff --git a/src/series.jl b/src/series.jl index 9af76774..1eff25a5 100644 --- a/src/series.jl +++ b/src/series.jl @@ -14,7 +14,7 @@ all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surfac convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))") # missing -convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing +convertToAnyVector(v::Nothing, d::KW) = Any[nothing], nothing # fixed number of blank series convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing @@ -46,7 +46,7 @@ convertToAnyVector(v::Volume, d::KW) = Any[v], nothing # convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing # # dates -convertToAnyVector{D<:Union{Date,DateTime}}(dts::AVec{D}, d::KW) = Any[dts], nothing +convertToAnyVector(dts::AVec{D}, d::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing # list of things (maybe other vectors, functions, or something else) function convertToAnyVector(v::AVec, d::KW) @@ -72,19 +72,19 @@ end # TODO: can we avoid the copy here? one error that crops up is that mapping functions over the same array # result in that array being shared. push!, etc will add too many items to that array -compute_x(x::Void, y::Void, z) = 1:size(z,1) -compute_x(x::Void, y, z) = 1:size(y,1) +compute_x(x::Nothing, y::Nothing, z) = 1:size(z,1) +compute_x(x::Nothing, y, z) = 1:size(y,1) compute_x(x::Function, y, z) = map(x, y) compute_x(x, y, z) = copy(x) -# compute_y(x::Void, y::Function, z) = error() -compute_y(x::Void, y::Void, z) = 1:size(z,2) +# compute_y(x::Nothing, y::Function, z) = error() +compute_y(x::Nothing, y::Nothing, z) = 1:size(z,2) compute_y(x, y::Function, z) = map(y, x) compute_y(x, y, z) = copy(y) compute_z(x, y, z::Function) = map(z, x, y) compute_z(x, y, z::AbstractMatrix) = Surface(z) -compute_z(x, y, z::Void) = nothing +compute_z(x, y, z::Nothing) = nothing compute_z(x, y, z) = copy(z) nobigs(v::AVec{BigFloat}) = map(Float64, v) @@ -99,9 +99,9 @@ nobigs(v) = v end # not allowed -compute_xyz(x::Void, y::FuncOrFuncs{F}, z) where {F<:Function} = error("If you want to plot the function `$y`, you need to define the x values!") -compute_xyz(x::Void, y::Void, z::FuncOrFuncs{F}) where {F<:Function} = error("If you want to plot the function `$z`, you need to define x and y values!") -compute_xyz(x::Void, y::Void, z::Void) = error("x/y/z are all nothing!") +compute_xyz(x::Nothing, y::FuncOrFuncs{F}, z) where {F<:Function} = error("If you want to plot the function `$y`, you need to define the x values!") +compute_xyz(x::Nothing, y::Nothing, z::FuncOrFuncs{F}) where {F<:Function} = error("If you want to plot the function `$z`, you need to define x and y values!") +compute_xyz(x::Nothing, y::Nothing, z::Nothing) = error("x/y/z are all nothing!") # -------------------------------------------------------------------- diff --git a/src/types.jl b/src/types.jl index bd53715b..3b63392b 100644 --- a/src/types.jl +++ b/src/types.jl @@ -6,7 +6,7 @@ const AVec = AbstractVector const AMat = AbstractMatrix const KW = Dict{Symbol,Any} -struct PlotsDisplay <: Display end +struct PlotsDisplay <: AbstractDisplay end # ----------------------------------------------------------- diff --git a/src/utils.jl b/src/utils.jl index 2334d96a..52f39d30 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -259,7 +259,7 @@ float_extended_type(x::AbstractArray{T}) where {T<:Real} = Float64 nop() = nothing notimpl() = error("This has not been implemented yet") -isnothing(x::Void) = true +isnothing(x::Nothing) = true isnothing(x) = false _cycle(wrapper::InputWrapper, idx::Int) = wrapper.obj @@ -305,7 +305,7 @@ function _expand_limits(lims, x) e1, e2 = ignorenan_extrema(x) lims[1] = NaNMath.min(lims[1], e1) lims[2] = NaNMath.max(lims[2], e2) - # catch err + catch err # warn(err) end nothing @@ -343,7 +343,7 @@ function replaceAliases!(d::KW, aliases::Dict{Symbol,Symbol}) end end -createSegments(z) = collect(repmat(reshape(z,1,:),2,1))[2:end] +createSegments(z) = collect(repeat(reshape(z,1,:),2,1))[2:end] Base.first(c::Colorant) = c Base.first(x::Symbol) = x @@ -355,7 +355,7 @@ sortedkeys(d::Dict) = sort(collect(keys(d))) const _scale_base = Dict{Symbol, Real}( :log10 => 10, :log2 => 2, - :ln => e, + :ln => euler_e ) function _heatmap_edges(v::AVec) @@ -450,8 +450,8 @@ limsType(lims) = :invalid # axis_Symbol(letter, postfix) = Symbol(letter * postfix) # axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix) -Base.convert(::Type{Vector{T}}, rng::Range{T}) where {T<:Real} = T[x for x in rng] -Base.convert(::Type{Vector{T}}, rng::Range{S}) where {T<:Real,S<:Real} = T[x for x in rng] +Base.convert(::Type{Vector{T}}, rng::AbstractRange{T}) where {T<:Real} = T[x for x in rng] +Base.convert(::Type{Vector{T}}, rng::AbstractRange{S}) where {T<:Real,S<:Real} = T[x for x in rng] Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b))) @@ -846,8 +846,8 @@ end extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n) extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + ignorenan_maximum(v)) -extendSeriesData(v::Range{T}, z::Real) where {T} = extendSeriesData(float(collect(v)), z) -extendSeriesData(v::Range{T}, z::AVec) where {T} = extendSeriesData(float(collect(v)), z) +extendSeriesData(v::AbstractRange{T}, z::Real) where {T} = extendSeriesData(float(collect(v)), z) +extendSeriesData(v::AbstractRange{T}, z::AVec) where {T} = extendSeriesData(float(collect(v)), z) extendSeriesData(v::AVec{T}, z::Real) where {T} = (push!(v, convert(T, z)); v) extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Vector{T}, z)); v) @@ -856,7 +856,7 @@ extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Ve # NOTE: backends should implement the following methods to get/set the x/y/z data objects tovec(v::AbstractVector) = v -tovec(v::Void) = zeros(0) +tovec(v::Nothing) = zeros(0) function getxy(plt::Plot, i::Integer) d = plt.series_list[i].d @@ -1138,9 +1138,9 @@ function convert_sci_unicode(label::AbstractString) "×10" => "×10^{", ) for key in keys(unicode_dict) - label = replace(label, key, unicode_dict[key]) + label = replace(label, key => unicode_dict[key]) end - if contains(label, "10^{") + if occursin("10^{", label) label = string(label, "}") end label