From ef29b4a5b025d23bb232f85799a3811ed301ef8d Mon Sep 17 00:00:00 2001 From: "femtocleaner[bot]" Date: Tue, 17 Oct 2017 09:59:09 +0000 Subject: [PATCH] Fix deprecations --- src/Plots.jl | 48 +++++++------- src/animation.jl | 8 +-- src/args.jl | 6 +- src/axes.jl | 4 +- src/backends.jl | 6 +- src/backends/glvisualize.jl | 22 +++---- src/backends/gr.jl | 2 +- src/backends/hdf5.jl | 16 ++--- src/backends/inspectdr.jl | 12 ++-- src/backends/plotly.jl | 4 +- src/components.jl | 46 ++++++------- src/deprecated/backends/gadfly.jl | 8 +-- src/deprecated/backends/gadfly_shapes.jl | 2 +- src/deprecated/backends/immerse.jl | 4 +- src/deprecated/backends/qwt.jl | 4 +- src/deprecated/backends/winston.jl | 2 +- src/deprecated/colors.jl | 24 +++---- src/deprecated/series_args.jl | 10 +-- src/examples.jl | 2 +- src/layouts.jl | 14 ++-- src/output.jl | 6 +- src/pipeline.jl | 2 +- src/plot.jl | 2 +- src/recipes.jl | 40 ++++++------ src/series.jl | 60 ++++++++--------- src/subplots.jl | 2 +- src/types.jl | 16 ++--- src/utils.jl | 82 ++++++++++++------------ 28 files changed, 227 insertions(+), 227 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index e2ffa95c..d4f05cc5 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -110,13 +110,13 @@ export # --------------------------------------------------------- import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 -ignorenan_minimum{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.minimum(x) +ignorenan_minimum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.minimum(x) ignorenan_minimum(x) = Base.minimum(x) -ignorenan_maximum{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.maximum(x) +ignorenan_maximum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.maximum(x) ignorenan_maximum(x) = Base.maximum(x) -ignorenan_mean{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.mean(x) +ignorenan_mean(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.mean(x) ignorenan_mean(x) = Base.mean(x) -ignorenan_extrema{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.extrema(x) +ignorenan_extrema(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.extrema(x) ignorenan_extrema(x) = Base.extrema(x) # --------------------------------------------------------- @@ -215,13 +215,13 @@ xlabel!(s::AbstractString; kw...) = plot!(; xlabel = s, kw...) ylabel!(s::AbstractString; kw...) = plot!(; ylabel = s, kw...) "Set xlims for an existing plot" -xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; xlims = lims, kw...) +xlims!(lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(; xlims = lims, kw...) "Set ylims for an existing plot" -ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; ylims = lims, kw...) +ylims!(lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(; ylims = lims, kw...) "Set zlims for an existing plot" -zlims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; zlims = lims, kw...) +zlims!(lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(; zlims = lims, kw...) xlims!(xmin::Real, xmax::Real; kw...) = plot!(; xlims = (xmin,xmax), kw...) ylims!(ymin::Real, ymax::Real; kw...) = plot!(; ylims = (ymin,ymax), kw...) @@ -229,19 +229,19 @@ zlims!(zmin::Real, zmax::Real; kw...) = plot!(; zlims = (zmi "Set xticks for an existing plot" -xticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; xticks = v, kw...) +xticks!(v::AVec{T}; kw...) where {T<:Real} = plot!(; xticks = v, kw...) "Set yticks for an existing plot" -yticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; yticks = v, kw...) +yticks!(v::AVec{T}; kw...) where {T<:Real} = plot!(; yticks = v, kw...) -xticks!{T<:Real,S<:AbstractString}( - ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; xticks = (ticks,labels), kw...) -yticks!{T<:Real,S<:AbstractString}( - ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; yticks = (ticks,labels), kw...) +xticks!( +ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(; xticks = (ticks,labels), kw...) +yticks!( +ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(; yticks = (ticks,labels), kw...) "Add annotations to an existing plot" annotate!(anns...; kw...) = plot!(; annotation = anns, kw...) -annotate!{T<:Tuple}(anns::AVec{T}; kw...) = plot!(; annotation = anns, kw...) +annotate!(anns::AVec{T}; kw...) where {T<:Tuple} = plot!(; annotation = anns, kw...) "Flip the current plots' x axis" xflip!(flip::Bool = true; kw...) = plot!(; xflip = flip, kw...) @@ -261,22 +261,22 @@ let PlotOrSubplot = Union{Plot, Subplot} 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...) - xlims!{T<:Real,S<:Real}(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) = plot!(plt; xlims = lims, kw...) - ylims!{T<:Real,S<:Real}(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) = plot!(plt; ylims = lims, kw...) - zlims!{T<:Real,S<:Real}(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) = plot!(plt; zlims = lims, kw...) + xlims!(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(plt; xlims = lims, kw...) + ylims!(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(plt; ylims = lims, kw...) + zlims!(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(plt; zlims = lims, kw...) xlims!(plt::PlotOrSubplot, xmin::Real, xmax::Real; kw...) = plot!(plt; xlims = (xmin,xmax), kw...) ylims!(plt::PlotOrSubplot, ymin::Real, ymax::Real; kw...) = plot!(plt; ylims = (ymin,ymax), kw...) zlims!(plt::PlotOrSubplot, zmin::Real, zmax::Real; kw...) = plot!(plt; zlims = (zmin,zmax), kw...) - xticks!{T<:Real}(plt::PlotOrSubplot, ticks::AVec{T}; kw...) = plot!(plt; xticks = ticks, kw...) - yticks!{T<:Real}(plt::PlotOrSubplot, ticks::AVec{T}; kw...) = plot!(plt; yticks = ticks, kw...) - xticks!{T<:Real,S<:AbstractString}(plt::PlotOrSubplot, - ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; xticks = (ticks,labels), kw...) - yticks!{T<:Real,S<:AbstractString}(plt::PlotOrSubplot, - ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; yticks = (ticks,labels), kw...) + xticks!(plt::PlotOrSubplot, ticks::AVec{T}; kw...) where {T<:Real} = plot!(plt; xticks = ticks, kw...) + yticks!(plt::PlotOrSubplot, ticks::AVec{T}; kw...) where {T<:Real} = plot!(plt; yticks = ticks, kw...) + xticks!(plt::PlotOrSubplot, + ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(plt; xticks = (ticks,labels), kw...) + yticks!(plt::PlotOrSubplot, + ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(plt; yticks = (ticks,labels), kw...) xgrid!(plt::PlotOrSubplot, args...; kw...) = plot!(plt; xgrid = args, kw...) ygrid!(plt::PlotOrSubplot, args...; kw...) = plot!(plt; ygrid = args, kw...) annotate!(plt::PlotOrSubplot, anns...; kw...) = plot!(plt; annotation = anns, kw...) - annotate!{T<:Tuple}(plt::PlotOrSubplot, anns::AVec{T}; kw...) = plot!(plt; annotation = anns, kw...) + annotate!(plt::PlotOrSubplot, anns::AVec{T}; kw...) where {T<:Tuple} = plot!(plt; annotation = anns, kw...) xflip!(plt::PlotOrSubplot, flip::Bool = true; kw...) = plot!(plt; xflip = flip, kw...) yflip!(plt::PlotOrSubplot, flip::Bool = true; kw...) = plot!(plt; yflip = flip, kw...) xaxis!(plt::PlotOrSubplot, args...; kw...) = plot!(plt; xaxis = args, kw...) diff --git a/src/animation.jl b/src/animation.jl index 4afa01cf..b7a13684 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -1,5 +1,5 @@ "Represents an animation object" -immutable Animation +struct Animation dir::String frames::Vector{String} end @@ -14,7 +14,7 @@ end Add a plot (the current plot if not specified) to an existing animation """ -function frame{P<:AbstractPlot}(anim::Animation, plt::P=current()) +function frame(anim::Animation, plt::P=current()) where P<:AbstractPlot i = length(anim.frames) + 1 filename = @sprintf("%06d.png", i) png(plt, joinpath(anim.dir, filename)) @@ -25,7 +25,7 @@ giffn() = (isijulia() ? "tmp.gif" : tempname()*".gif") movfn() = (isijulia() ? "tmp.mov" : tempname()*".mov") mp4fn() = (isijulia() ? "tmp.mp4" : tempname()*".mp4") -type FrameIterator +mutable struct FrameIterator itr every::Int kw @@ -54,7 +54,7 @@ end # ----------------------------------------------- "Wraps the location of an animated gif so that it can be displayed" -immutable AnimatedGif +struct AnimatedGif filename::String end diff --git a/src/args.jl b/src/args.jl index f049f68f..81cf03f8 100644 --- a/src/args.jl +++ b/src/args.jl @@ -889,7 +889,7 @@ end # ----------------------------------------------------------------------------- "A special type that will break up incoming data into groups, and allow for easier creation of grouped plots" -type GroupBy +mutable struct GroupBy groupLabels::Vector # length == numGroups groupIds::Vector{Vector{Int}} # list of indices for each group end @@ -916,7 +916,7 @@ function extractGroupArgs(vs::Tuple, args...) end # expecting a mapping of "group label" to "group indices" -function extractGroupArgs{T, V<:AVec{Int}}(idxmap::Dict{T,V}, args...) +function extractGroupArgs(idxmap::Dict{T,V}, args...) where {T, V<:AVec{Int}} groupLabels = sortedkeys(idxmap) groupIds = Vector{Int}[collect(idxmap[k]) for k in groupLabels] GroupBy(groupLabels, groupIds) @@ -1007,7 +1007,7 @@ function convertLegendValue(val::Symbol) end convertLegendValue(val::Bool) = val ? :best : :none convertLegendValue(val::Void) = :none -convertLegendValue{S<:Real, T<:Real}(v::Tuple{S,T}) = v +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 25e45694..4288cde3 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -293,13 +293,13 @@ expand_extrema!(axis::Axis, ::Void) = axis[:extrema] expand_extrema!(axis::Axis, ::Bool) = axis[:extrema] -function expand_extrema!{MIN<:Number,MAX<:Number}(axis::Axis, v::Tuple{MIN,MAX}) +function expand_extrema!(axis::Axis, v::Tuple{MIN,MAX}) where {MIN<:Number,MAX<:Number} ex = axis[:extrema] ex.emin = NaNMath.min(v[1], ex.emin) ex.emax = NaNMath.max(v[2], ex.emax) ex end -function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N}) +function expand_extrema!(axis::Axis, v::AVec{N}) where N<:Number ex = axis[:extrema] for vi in v expand_extrema!(ex, vi) diff --git a/src/backends.jl b/src/backends.jl index b445807c..1dd5d8ad 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -1,5 +1,5 @@ -immutable NoBackend <: AbstractBackend end +struct NoBackend <: AbstractBackend end const _backendType = Dict{Symbol, DataType}(:none => NoBackend) const _backendSymbol = Dict{DataType, Symbol}(NoBackend => :none) @@ -18,7 +18,7 @@ macro init_backend(s) sym = Symbol(str) T = Symbol(string(s) * "Backend") esc(quote - immutable $T <: AbstractBackend end + struct $T <: AbstractBackend end export $sym $sym(; kw...) = (default(; kw...); backend(Symbol($str))) backend_name(::$T) = Symbol($str) @@ -123,7 +123,7 @@ _update_plot_object(plt::Plot) = nothing # --------------------------------------------------------- -type CurrentBackend +mutable struct CurrentBackend sym::Symbol pkg::AbstractBackend end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index bbd5605a..716ce78a 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -69,9 +69,9 @@ function _initialize_backend(::GLVisualizeBackend; kw...) import GLVisualize: visualize import Plots.GL import UnicodeFun - Plots.slice_arg{C<:Colorant}(img::Matrix{C}, idx::Int) = img + Plots.slice_arg(img::Matrix{C}, idx::Int) where {C<:Colorant} = img is_marker_supported(::GLVisualizeBackend, shape::GLVisualize.AllPrimitives) = true - is_marker_supported{C<:Colorant}(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) = true + is_marker_supported(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) where {C<:Colorant} = true is_marker_supported(::GLVisualizeBackend, shape::Shape) = true const GL = Plots end @@ -214,13 +214,13 @@ function extract_limits(sp, d, kw_args) nothing end -to_vec{T <: StaticArrays.StaticVector}(::Type{T}, vec::T) = vec -to_vec{T <: StaticArrays.StaticVector}(::Type{T}, s::Number) = T(s) +to_vec(::Type{T}, vec::T) where {T <: StaticArrays.StaticVector} = vec +to_vec(::Type{T}, s::Number) where {T <: StaticArrays.StaticVector} = T(s) -to_vec{T <: StaticArrays.StaticVector{2}}(::Type{T}, vec::StaticArrays.StaticVector{3}) = T(vec[1], vec[2]) -to_vec{T <: StaticArrays.StaticVector{3}}(::Type{T}, vec::StaticArrays.StaticVector{2}) = T(vec[1], vec[2], 0) +to_vec(::Type{T}, vec::StaticArrays.StaticVector{3}) where {T <: StaticArrays.StaticVector{2}} = T(vec[1], vec[2]) +to_vec(::Type{T}, vec::StaticArrays.StaticVector{2}) where {T <: StaticArrays.StaticVector{3}} = T(vec[1], vec[2], 0) -to_vec{T <: StaticArrays.StaticVector}(::Type{T}, vecs::AbstractVector) = map(x-> to_vec(T, x), vecs) +to_vec(::Type{T}, vecs::AbstractVector) where {T <: StaticArrays.StaticVector} = map(x-> to_vec(T, x), vecs) function extract_marker(d, kw_args) dim = Plots.is3d(d) ? 3 : 2 @@ -275,7 +275,7 @@ end function extract_surface(d) map(_extract_surface, (d[:x], d[:y], d[:z])) end -function topoints{P}(::Type{P}, array) +function topoints(::Type{P}, array) where P [P(x) for x in zip(array...)] end function extract_points(d) @@ -283,7 +283,7 @@ function extract_points(d) array = (d[:x], d[:y], d[:z])[1:dim] topoints(Point{dim, Float32}, array) end -function make_gradient{C <: Colorant}(grad::Vector{C}) +function make_gradient(grad::Vector{C}) where C <: Colorant grad end function make_gradient(grad::ColorGradient) @@ -338,7 +338,7 @@ function extract_color(d, sym) end gl_color(c::PlotUtils.ColorGradient) = c.colors -gl_color{T<:Colorant}(c::Vector{T}) = c +gl_color(c::Vector{T}) where {T<:Colorant} = c gl_color(c::RGBA{Float32}) = c gl_color(c::Colorant) = RGBA{Float32}(c) @@ -1212,7 +1212,7 @@ function gl_image(img, kw_args) visualize(img, Style(:default), kw_args) end -function handle_segment{P}(lines, line_segments, points::Vector{P}, segment) +function handle_segment(lines, line_segments, points::Vector{P}, segment) where P (isempty(segment) || length(segment) < 2) && return if length(segment) == 2 append!(line_segments, view(points, segment)) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 96ca08f4..791055ed 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -482,7 +482,7 @@ function gr_legend_pos(s::Symbol,w,h) (xpos,ypos) end -function gr_legend_pos{S<:Real, T<:Real}(v::Tuple{S,T},w,h) +function gr_legend_pos(v::Tuple{S,T},w,h) where {S<:Real, T<:Real} xpos = v[1] * (viewport_plotarea[2] - viewport_plotarea[1]) + viewport_plotarea[1] ypos = v[2] * (viewport_plotarea[4] - viewport_plotarea[3]) + viewport_plotarea[3] (xpos,ypos) diff --git a/src/backends/hdf5.jl b/src/backends/hdf5.jl index a3a200ad..3adc912a 100644 --- a/src/backends/hdf5.jl +++ b/src/backends/hdf5.jl @@ -32,10 +32,10 @@ Read from .hdf5 file using: import FixedPointNumbers: N0f8 #In core Julia #Dispatch types: -immutable HDF5PlotNative; end #Indentifies a data element that can natively be handled by HDF5 -immutable HDF5CTuple; end #Identifies a "complex" tuple structure +struct HDF5PlotNative; end #Indentifies a data element that can natively be handled by HDF5 +struct HDF5CTuple; end #Identifies a "complex" tuple structure -type HDF5Plot_PlotRef +mutable struct HDF5Plot_PlotRef ref::Union{Plot, Void} end @@ -276,11 +276,11 @@ function _hdf5plot_overwritetype(grp, T::Type) #Write directly to group HDF5.a_delete(grp, _hdf5plot_datatypeid) HDF5.a_write(grp, _hdf5plot_datatypeid, tstr) end -function _hdf5plot_writetype{T<:Any}(grp, ::Type{Array{T}}) +function _hdf5plot_writetype(grp, ::Type{Array{T}}) where T<:Any tstr = HDF5PLOT_MAP_TELEM2STR[Array] #ANY HDF5.a_write(grp, _hdf5plot_datatypeid, tstr) end -function _hdf5plot_writetype{T<:BoundingBox}(grp, ::Type{T}) +function _hdf5plot_writetype(grp, ::Type{T}) where T<:BoundingBox tstr = HDF5PLOT_MAP_TELEM2STR[BoundingBox] HDF5.a_write(grp, _hdf5plot_datatypeid, tstr) end @@ -305,7 +305,7 @@ function _hdf5plot_gwrite(grp, k::String, v) #Default grp[k] = v _hdf5plot_writetype(grp, k, HDF5PlotNative) end -function _hdf5plot_gwrite{T<:Number}(grp, k::String, v::Array{T}) #Default for arrays +function _hdf5plot_gwrite(grp, k::String, v::Array{T}) where T<:Number #Default for arrays grp[k] = v _hdf5plot_writetype(grp, k, HDF5PlotNative) end @@ -355,7 +355,7 @@ function _hdf5plot_gwrite(grp, k::String, v::Colorant) _hdf5plot_gwrite(grp, k, ARGB{N0f8}(v)) end #Custom vector (when not using simple numeric type): -function _hdf5plot_gwritearray{T}(grp, k::String, v::Array{T}) +function _hdf5plot_gwritearray(grp, k::String, v::Array{T}) where T if "annotations" == k; return #Hack. Does not yet support annotations. end @@ -380,7 +380,7 @@ function _hdf5plot_gwrite(grp, k::String, v::Extrema) grp[k] = [v.emin, v.emax] _hdf5plot_writetype(grp, k, Extrema) end -function _hdf5plot_gwrite{T}(grp, k::String, v::Length{T}) +function _hdf5plot_gwrite(grp, k::String, v::Length{T}) where T grp[k] = v.value _hdf5plot_writetype(grp, k, [HDF5PLOT_MAP_TELEM2STR[Length], string(T)]) end diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index a8224634..65f019a0 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -131,7 +131,7 @@ end function _inspectdr_getscale(s::Symbol, yaxis::Bool) #TODO: Support :asinh, :sqrt - kwargs = yaxis? (:tgtmajor=>8, :tgtminor=>2): () #More grid lines on y-axis + kwargs = yaxis ? (:tgtmajor=>8, :tgtminor=>2) : () #More grid lines on y-axis if :log2 == s return InspectDR.AxisScale(:log2; kwargs...) elseif :log10 == s @@ -163,7 +163,7 @@ function _initialize_backend(::InspectDRBackend; kw...) 2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y ) - type InspecDRPlotRef + mutable struct InspecDRPlotRef mplot::Union{Void, InspectDR.Multiplot} gui::Union{Void, InspectDR.GtkPlot} end @@ -172,7 +172,7 @@ function _initialize_backend(::InspectDRBackend; kw...) _inspectdr_getmplot(r::InspecDRPlotRef) = r.mplot _inspectdr_getgui(::Any) = nothing - _inspectdr_getgui(gplot::InspectDR.GtkPlot) = (gplot.destroyed? nothing: gplot) + _inspectdr_getgui(gplot::InspectDR.GtkPlot) = (gplot.destroyed ? nothing : gplot) _inspectdr_getgui(r::InspecDRPlotRef) = _inspectdr_getgui(r.gui) end end @@ -235,7 +235,7 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) #Don't do anything without a "subplot" object: Will process later. if nothing == plot; return; end - _vectorize(v) = isa(v, Vector)? v: collect(v) #InspectDR only supports vectors + _vectorize(v) = isa(v, Vector) ? v : collect(v) #InspectDR only supports vectors x = _vectorize(series[:x]); y = _vectorize(series[:y]) #No support for polar grid... but can still perform polar transformation: @@ -278,7 +278,7 @@ For st in :shape: end end - i = (nmax >= 2? div(nmax, 2): nmax) #Must pick one set of colors for legend + i = (nmax >= 2 ? div(nmax, 2) : nmax) #Must pick one set of colors for legend if i > 1 #Add dummy waveform for legend entry: linewidth = series[:linewidth] linecolor = _inspectdr_mapcolor(_cycle(series[:linecolor], i)) @@ -296,7 +296,7 @@ For st in :shape: #NOTE: In Plots.jl, :scatter plots have 0-linewidths (I think). linewidth = series[:linewidth] #More efficient & allows some support for markerstrokewidth: - _style = (0==linewidth? :none: series[:linestyle]) + _style = (0==linewidth ? :none : series[:linestyle]) wfrm = InspectDR.add(plot, x, y, id=series[:label]) wfrm.line = InspectDR.line( style = _style, diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index c67511d2..f5ee90fa 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -122,7 +122,7 @@ const _plotly_legend_pos = KW( ) plotly_legend_pos(pos::Symbol) = get(_plotly_legend_pos, pos, [1.,1.]) -plotly_legend_pos{S<:Real, T<:Real}(v::Tuple{S,T}) = v +plotly_legend_pos(v::Tuple{S,T}) where {S<:Real, T<:Real} = v function plotly_font(font::Font, color = font.color) KW( @@ -441,7 +441,7 @@ end plotly_data(v) = collect(v) plotly_data(surf::Surface) = surf.surf -plotly_data{R<:Rational}(v::AbstractArray{R}) = float(v) +plotly_data(v::AbstractArray{R}) where {R<:Rational} = float(v) plotly_surface_data(series::Series, a::AbstractVector) = a plotly_surface_data(series::Series, a::AbstractMatrix) = transpose_z(series, a, false) diff --git a/src/components.jl b/src/components.jl index eba135c2..25784f1e 100644 --- a/src/components.jl +++ b/src/components.jl @@ -11,7 +11,7 @@ compute_angle(v::P2) = (angle = atan2(v[2], v[1]); angle < 0 ? 2π - angle : ang # ------------------------------------------------------------- -immutable Shape +struct Shape x::Vector{Float64} y::Vector{Float64} # function Shape(x::AVec, y::AVec) @@ -246,7 +246,7 @@ end # ----------------------------------------------------------------------- -type Font +mutable struct Font family::AbstractString pointsize::Int halign::Symbol @@ -336,7 +336,7 @@ function scalefontsizes() end "Wrap a string with font info" -immutable PlotText +struct PlotText str::AbstractString font::Font end @@ -359,7 +359,7 @@ Base.length(t::PlotText) = length(t.str) # ----------------------------------------------------------------------- -immutable Stroke +struct Stroke width color alpha @@ -401,7 +401,7 @@ function stroke(args...; alpha = nothing) end -immutable Brush +struct Brush size # fillrange, markersize, or any other sizey attribute color alpha @@ -434,7 +434,7 @@ end # ----------------------------------------------------------------------- -type SeriesAnnotations +mutable struct SeriesAnnotations strs::AbstractVector # the labels/names font::Font baseshape::Nullable @@ -513,7 +513,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) return end -type EachAnn +mutable struct EachAnn anns x y @@ -538,12 +538,12 @@ annotations(sa::SeriesAnnotations) = sa # ----------------------------------------------------------------------- "type which represents z-values for colors and sizes (and anything else that might come up)" -immutable ZValues +struct ZValues values::Vector{Float64} zrange::Tuple{Float64,Float64} end -function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (ignorenan_minimum(values), ignorenan_maximum(values))) +function zvalues(values::AVec{T}, zrange::Tuple{T,T} = (ignorenan_minimum(values), ignorenan_maximum(values))) where T<:Real ZValues(collect(float(values)), map(Float64, zrange)) end @@ -552,7 +552,7 @@ end abstract type AbstractSurface end "represents a contour or surface mesh" -immutable Surface{M<:AMat} <: AbstractSurface +struct Surface{M<:AMat} <: AbstractSurface surf::M end @@ -564,7 +564,7 @@ for f in (:length, :size) @eval Base.$f(surf::Surface, args...) = $f(surf.surf, args...) end Base.copy(surf::Surface) = Surface(copy(surf.surf)) -Base.eltype{T}(surf::Surface{T}) = eltype(T) +Base.eltype(surf::Surface{T}) where {T} = eltype(T) function expand_extrema!(a::Axis, surf::Surface) ex = a[:extrema] @@ -575,7 +575,7 @@ function expand_extrema!(a::Axis, surf::Surface) end "For the case of representing a surface as a function of x/y... can possibly avoid allocations." -immutable SurfaceFunction <: AbstractSurface +struct SurfaceFunction <: AbstractSurface f::Function end @@ -585,19 +585,19 @@ end # # I don't want to clash with ValidatedNumerics, but this would be nice: # ..(a::T, b::T) = (a,b) -immutable Volume{T} +struct Volume{T} v::Array{T,3} x_extents::Tuple{T,T} y_extents::Tuple{T,T} z_extents::Tuple{T,T} end -default_extents{T}(::Type{T}) = (zero(T), one(T)) +default_extents(::Type{T}) where {T} = (zero(T), one(T)) -function Volume{T}(v::Array{T,3}, - x_extents = default_extents(T), - y_extents = default_extents(T), - z_extents = default_extents(T)) +function Volume(v::Array{T,3}, + x_extents = default_extents(T), + y_extents = default_extents(T), + z_extents = default_extents(T)) where T Volume(v, x_extents, y_extents, z_extents) end @@ -605,13 +605,13 @@ Base.Array(vol::Volume) = vol.v for f in (:length, :size) @eval Base.$f(vol::Volume, args...) = $f(vol.v, args...) end -Base.copy{T}(vol::Volume{T}) = Volume{T}(copy(vol.v), vol.x_extents, vol.y_extents, vol.z_extents) -Base.eltype{T}(vol::Volume{T}) = T +Base.copy(vol::Volume{T}) where {T} = Volume{T}(copy(vol.v), vol.x_extents, vol.y_extents, vol.z_extents) +Base.eltype(vol::Volume{T}) where {T} = T # ----------------------------------------------------------------------- # style is :open or :closed (for now) -immutable Arrow +struct Arrow style::Symbol side::Symbol # :head (default), :tail, or :both headlength::Float64 @@ -673,14 +673,14 @@ end # ----------------------------------------------------------------------- "Represents data values with formatting that should apply to the tick labels." -immutable Formatted{T} +struct Formatted{T} data::T formatter::Function end # ----------------------------------------------------------------------- "create a BezierCurve for plotting" -type BezierCurve{T <: FixedSizeArrays.Vec} +mutable struct BezierCurve{T <: FixedSizeArrays.Vec} control_points::Vector{T} end diff --git a/src/deprecated/backends/gadfly.jl b/src/deprecated/backends/gadfly.jl index bb501db2..53453b9e 100644 --- a/src/deprecated/backends/gadfly.jl +++ b/src/deprecated/backends/gadfly.jl @@ -558,7 +558,7 @@ function createGadflyAnnotationObject(x, y, txt::PlotText) )) end -function _add_annotations{X,Y,V}(plt::Plot{GadflyBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{GadflyBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns push!(plt.o.guides, createGadflyAnnotationObject(ann...)) end @@ -614,7 +614,7 @@ function getxy(plt::Plot{GadflyBackend}, i::Integer) mapping[:x], mapping[:y] end -function setxy!{X,Y}(plt::Plot{GadflyBackend}, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot{GadflyBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} for mapping in getGadflyMappings(plt, i) mapping[:x], mapping[:y] = xy end @@ -677,7 +677,7 @@ setGadflyDisplaySize(plt::Plot) = setGadflyDisplaySize(plt.attr[:size]...) # ------------------------------------------------------------------------- -function doshow{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, func, plt::AbstractPlot{P}) +function doshow(io::IO, func, plt::AbstractPlot{P}) where P<:Union{GadflyBackend,ImmerseBackend} gplt = getGadflyContext(plt) setGadflyDisplaySize(plt) Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) @@ -692,7 +692,7 @@ getGadflyWriteFunc(::MIME"application/x-tex") = Gadfly.PGF getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m) for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex") - @eval function Base.show{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, ::$mime, plt::AbstractPlot{P}) + @eval function Base.show(io::IO, ::$mime, plt::AbstractPlot{P}) where P<:Union{GadflyBackend,ImmerseBackend} func = getGadflyWriteFunc($mime()) doshow(io, func, plt) end diff --git a/src/deprecated/backends/gadfly_shapes.jl b/src/deprecated/backends/gadfly_shapes.jl index 9c70c90c..1a818993 100644 --- a/src/deprecated/backends/gadfly_shapes.jl +++ b/src/deprecated/backends/gadfly_shapes.jl @@ -2,7 +2,7 @@ # Geometry which displays arbitrary shapes at given (x, y) positions. # note: vertices is a list of shapes -immutable ShapeGeometry <: Gadfly.GeometryElement +struct ShapeGeometry <: Gadfly.GeometryElement vertices::AbstractVector #{Tuple{Float64,Float64}} tag::Symbol diff --git a/src/deprecated/backends/immerse.jl b/src/deprecated/backends/immerse.jl index b8679cf3..58950480 100644 --- a/src/deprecated/backends/immerse.jl +++ b/src/deprecated/backends/immerse.jl @@ -61,7 +61,7 @@ end # ---------------------------------------------------------------- -function _add_annotations{X,Y,V}(plt::Plot{ImmerseBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{ImmerseBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns push!(getGadflyContext(plt).guides, createGadflyAnnotationObject(ann...)) end @@ -76,7 +76,7 @@ function getxy(plt::Plot{ImmerseBackend}, i::Integer) mapping[:x], mapping[:y] end -function setxy!{X,Y}(plt::Plot{ImmerseBackend}, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot{ImmerseBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} for mapping in getGadflyMappings(plt, i) mapping[:x], mapping[:y] = xy end diff --git a/src/deprecated/backends/qwt.jl b/src/deprecated/backends/qwt.jl index 2173c599..6bffd322 100644 --- a/src/deprecated/backends/qwt.jl +++ b/src/deprecated/backends/qwt.jl @@ -218,7 +218,7 @@ function createQwtAnnotation(plt::Plot, x, y, val::AbstractString) marker[:attach](plt.o.widget) end -function _add_annotations{X,Y,V}(plt::Plot{QwtBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{QwtBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns createQwtAnnotation(plt, ann...) end @@ -233,7 +233,7 @@ function getxy(plt::Plot{QwtBackend}, i::Int) series.x, series.y end -function setxy!{X,Y}(plt::Plot{QwtBackend}, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot{QwtBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} series = plt.o.lines[i] series.x, series.y = xy plt diff --git a/src/deprecated/backends/winston.jl b/src/deprecated/backends/winston.jl index 8e7b97c7..22694be8 100644 --- a/src/deprecated/backends/winston.jl +++ b/src/deprecated/backends/winston.jl @@ -217,7 +217,7 @@ function createWinstonAnnotationObject(plt::Plot{WinstonBackend}, x, y, val::Abs Winston.text(x, y, val) end -function _add_annotations{X,Y,V}(plt::Plot{WinstonBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{WinstonBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns createWinstonAnnotationObject(plt, ann...) end diff --git a/src/deprecated/colors.jl b/src/deprecated/colors.jl index f73d5db6..8247529a 100644 --- a/src/deprecated/colors.jl +++ b/src/deprecated/colors.jl @@ -34,9 +34,9 @@ getColorVector(scheme::ColorScheme) = [getColor(scheme)] colorscheme(scheme::ColorScheme) = scheme colorscheme(s::AbstractString; kw...) = colorscheme(Symbol(s); kw...) colorscheme(s::Symbol; kw...) = haskey(_gradients, s) ? ColorGradient(s; kw...) : ColorWrapper(convertColor(s); kw...) -colorscheme{T<:Real}(s::Symbol, vals::AVec{T}; kw...) = ColorGradient(s, vals; kw...) +colorscheme(s::Symbol, vals::AVec{T}; kw...) where {T<:Real} = ColorGradient(s, vals; kw...) colorscheme(cs::AVec, vs::AVec; kw...) = ColorGradient(cs, vs; kw...) -colorscheme{T<:Colorant}(cs::AVec{T}; kw...) = ColorGradient(cs; kw...) +colorscheme(cs::AVec{T}; kw...) where {T<:Colorant} = ColorGradient(cs; kw...) colorscheme(f::Function; kw...) = ColorFunction(f; kw...) colorscheme(v::AVec; kw...) = ColorVector(v; kw...) colorscheme(m::AMat; kw...) = size(m,1) == 1 ? map(c->colorscheme(c; kw...), m) : [colorscheme(m[:,i]; kw...) for i in 1:size(m,2)]' @@ -98,7 +98,7 @@ const _gradients = KW( :lighttest => map(c -> lighten(c, 0.3), _testColors), ) -function register_gradient_colors{C<:Colorant}(name::Symbol, colors::AVec{C}) +function register_gradient_colors(name::Symbol, colors::AVec{C}) where C<:Colorant _gradients[name] = colors end @@ -109,11 +109,11 @@ default_gradient() = ColorGradient(:inferno) # -------------------------------------------------------------- "Continuous gradient between values. Wraps a list of bounding colors and the values they represent." -immutable ColorGradient <: ColorScheme +struct ColorGradient <: ColorScheme colors::Vector values::Vector - function ColorGradient{S<:Real}(cs::AVec, vals::AVec{S} = linspace(0, 1, length(cs)); alpha = nothing) + function ColorGradient(cs::AVec, vals::AVec{S} = linspace(0, 1, length(cs)); alpha = nothing) where S<:Real if length(cs) == length(vals) return new(convertColor(cs,alpha), collect(vals)) end @@ -138,7 +138,7 @@ Base.getindex(cs::ColorGradient, z::Number) = getColorZ(cs, z) # create a gradient from a symbol (blues, reds, etc) and vector of boundary values -function ColorGradient{T<:Real}(s::Symbol, vals::AVec{T} = 0:0; kw...) +function ColorGradient(s::Symbol, vals::AVec{T} = 0:0; kw...) where T<:Real haskey(_gradients, s) || error("Invalid gradient symbol. Choose from: ", sort(collect(keys(_gradients)))) cs = _gradients[s] if vals == 0:0 @@ -208,7 +208,7 @@ end # -------------------------------------------------------------- "Wraps a function, taking an index and returning a Colorant" -immutable ColorFunction <: ColorScheme +struct ColorFunction <: ColorScheme f::Function end @@ -217,7 +217,7 @@ getColor(scheme::ColorFunction, idx::Int) = scheme.f(idx) # -------------------------------------------------------------- "Wraps a function, taking an z-value and returning a Colorant" -immutable ColorZFunction <: ColorScheme +struct ColorZFunction <: ColorScheme f::Function end @@ -226,7 +226,7 @@ getColorZ(scheme::ColorZFunction, z::Real) = scheme.f(z) # -------------------------------------------------------------- "Wraps a vector of colors... may be vector of Symbol/String/Colorant" -immutable ColorVector <: ColorScheme +struct ColorVector <: ColorScheme v::Vector{Colorant} ColorVector(v::AVec; alpha = nothing) = new(convertColor(v,alpha)) end @@ -238,7 +238,7 @@ getColorVector(scheme::ColorVector) = scheme.v # -------------------------------------------------------------- "Wraps a single color" -immutable ColorWrapper <: ColorScheme +struct ColorWrapper <: ColorScheme c::RGBA ColorWrapper(c::Colorant; alpha = nothing) = new(convertColor(c, alpha)) end @@ -347,8 +347,8 @@ function get_color_palette(palette, bgcolor::Union{Colorant,ColorWrapper}, numco RGBA[getColorZ(grad, z) for z in zrng] end -function get_color_palette{C<:Colorant}(palette::Vector{C}, - bgcolor::Union{Colorant,ColorWrapper}, numcolors::Integer) +function get_color_palette(palette::Vector{C}, +bgcolor::Union{Colorant,ColorWrapper}, numcolors::Integer) where C<:Colorant palette end diff --git a/src/deprecated/series_args.jl b/src/deprecated/series_args.jl index 2d7536f4..b5b02594 100644 --- a/src/deprecated/series_args.jl +++ b/src/deprecated/series_args.jl @@ -5,21 +5,21 @@ # This should cut down on boilerplate code and allow more focused dispatch on type # note: returns meta information... mainly for use with automatic labeling from DataFrames for now -const FuncOrFuncs = @compat(Union{Function, AVec{Function}}) +const FuncOrFuncs = Union{Function, AVec{Function}} all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none)) # missing -convertToAnyVector(v::@compat(Void), d::KW) = Any[nothing], nothing +convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing # fixed number of blank series convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing # numeric vector -convertToAnyVector{T<:Number}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:Number} = Any[v], nothing # string vector -convertToAnyVector{T<:@compat(AbstractString)}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:AbstractString} = Any[v], nothing function convertToAnyVector(v::AMat, d::KW) if all3D(d) @@ -39,7 +39,7 @@ convertToAnyVector(s::Surface, d::KW) = Any[s], 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) diff --git a/src/examples.jl b/src/examples.jl index ed62e00e..3f8acaa3 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -1,7 +1,7 @@ """ Holds all data needed for a documentation example... header, description, and plotting expression (Expr) """ -type PlotExample +mutable struct PlotExample header::AbstractString desc::AbstractString exprs::Vector{Expr} diff --git a/src/layouts.jl b/src/layouts.jl index 9bd4d3b2..63924374 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -13,7 +13,7 @@ Base.zero(::Type{typeof(mm)}) = 0mm Base.one(::Type{typeof(mm)}) = 1mm Base.typemin(::typeof(mm)) = -Inf*mm Base.typemax(::typeof(mm)) = Inf*mm -Base.convert{F<:AbstractFloat}(::Type{F}, l::AbsoluteLength) = convert(F, l.value) +Base.convert(::Type{F}, l::AbsoluteLength) where {F<:AbstractFloat} = convert(F, l.value) # TODO: these are unintuitive and may cause tricky bugs # Base.:+(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * (1 + m2.value)) @@ -95,7 +95,7 @@ end # ----------------------------------------------------------- # points combined by x/y, pct, and length -type MixedMeasures +mutable struct MixedMeasures xy::Float64 pct::Float64 len::AbsoluteLength @@ -216,7 +216,7 @@ bottompad(layout::AbstractLayout) = 0mm # RootLayout # this is the parent of the top-level layout -immutable RootLayout <: AbstractLayout end +struct RootLayout <: AbstractLayout end Base.parent(::RootLayout) = nothing parent_bbox(::RootLayout) = defaultbox @@ -226,7 +226,7 @@ bbox(::RootLayout) = defaultbox # EmptyLayout # contains blank space -type EmptyLayout <: AbstractLayout +mutable struct EmptyLayout <: AbstractLayout parent::AbstractLayout bbox::BoundingBox attr::KW # store label, width, and height for initialization @@ -244,7 +244,7 @@ _update_min_padding!(layout::EmptyLayout) = nothing # GridLayout # nested, gridded layout with optional size percentages -type GridLayout <: AbstractLayout +mutable struct GridLayout <: AbstractLayout parent::AbstractLayout minpad::Tuple # leftpad, toppad, rightpad, bottompad bbox::BoundingBox @@ -481,12 +481,12 @@ function layout_args(n::Integer) GridLayout(nr, nc), n end -function layout_args{I<:Integer}(sztup::NTuple{2,I}) +function layout_args(sztup::NTuple{2,I}) where I<:Integer nr, nc = sztup GridLayout(nr, nc), nr*nc end -function layout_args{I<:Integer}(sztup::NTuple{3,I}) +function layout_args(sztup::NTuple{3,I}) where I<:Integer n, nr, nc = sztup nr, nc = compute_gridsize(n, nr, nc) GridLayout(nr, nc), n diff --git a/src/output.jl b/src/output.jl index f26b6720..37849d8b 100644 --- a/src/output.jl +++ b/src/output.jl @@ -193,7 +193,7 @@ function Base.show(io::IO, ::MIME"text/html", plt::Plot) end end -function _show{B}(io::IO, m, plt::Plot{B}) +function _show(io::IO, m, plt::Plot{B}) where B # Base.show_backtrace(STDOUT, backtrace()) warn("_show is not defined for this backend. m=", string(m)) end @@ -203,7 +203,7 @@ end # for writing to io streams... first prepare, then callback for mime in keys(_mimeformats) - @eval function Base.show{B}(io::IO, m::MIME{Symbol($mime)}, plt::Plot{B}) + @eval function Base.show(io::IO, m::MIME{Symbol($mime)}, plt::Plot{B}) where B prepare_output(plt) _show(io, m, plt) end @@ -293,7 +293,7 @@ end Media.media(Plot, Media.Plot) - _show{B}(io::IO, m::MIME"text/plain", plt::Plot{B}) = print(io, "Plot{$B}()") + _show(io::IO, m::MIME"text/plain", plt::Plot{B}) where {B} = print(io, "Plot{$B}()") function Juno.render(e::Juno.Editor, plt::Plot) Juno.render(e, nothing) diff --git a/src/pipeline.jl b/src/pipeline.jl index a0f17ba4..e8607337 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -301,7 +301,7 @@ end # getting ready to add the series... last update to subplot from anything # that might have been added during series recipes -function _prepare_subplot{T}(plt::Plot{T}, d::KW) +function _prepare_subplot(plt::Plot{T}, d::KW) where T st::Symbol = d[:seriestype] sp::Subplot{T} = d[:subplot] sp_idx = get_subplot_index(plt, sp) diff --git a/src/plot.jl b/src/plot.jl index 8968df8c..38034bec 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -1,5 +1,5 @@ -type CurrentPlot +mutable struct CurrentPlot nullableplot::Nullable{AbstractPlot} end const CURRENT_PLOT = CurrentPlot(Nullable{AbstractPlot}()) diff --git a/src/recipes.jl b/src/recipes.jl index 5501351a..6e49fb03 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -47,7 +47,7 @@ end num_series(x::AMat) = size(x,2) num_series(x) = 1 -RecipesBase.apply_recipe{T}(d::KW, ::Type{T}, plt::AbstractPlot) = throw(MethodError("Unmatched plot recipe: $T")) +RecipesBase.apply_recipe(d::KW, ::Type{T}, plt::AbstractPlot) where {T} = throw(MethodError("Unmatched plot recipe: $T")) # --------------------------------------------------------------------------- @@ -343,9 +343,9 @@ _bin_centers(v::AVec) = (v[1:end-1] + v[2:end]) / 2 _is_positive(x) = (x > 0) && !(x ≈ 0) -_positive_else_nan{T}(::Type{T}, x::Real) = _is_positive(x) ? T(x) : T(NaN) +_positive_else_nan(::Type{T}, x::Real) where {T} = _is_positive(x) ? T(x) : T(NaN) -function _scale_adjusted_values{T<:AbstractFloat}(::Type{T}, V::AbstractVector, scale::Symbol) +function _scale_adjusted_values(::Type{T}, V::AbstractVector, scale::Symbol) where T<:AbstractFloat if scale in _logScales [_positive_else_nan(T, x) for x in V] else @@ -354,7 +354,7 @@ function _scale_adjusted_values{T<:AbstractFloat}(::Type{T}, V::AbstractVector, end -function _binbarlike_baseline{T<:Real}(min_value::T, scale::Symbol) +function _binbarlike_baseline(min_value::T, scale::Symbol) where T<:Real if (scale in _logScales) !isnan(min_value) ? min_value / T(_logScaleBases[scale]^log10(2)) : T(1E-3) else @@ -363,7 +363,7 @@ function _binbarlike_baseline{T<:Real}(min_value::T, scale::Symbol) end -function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol) +function _preprocess_binbarlike_weights(::Type{T}, w, wscale::Symbol) where T<:AbstractFloat w_adj = _scale_adjusted_values(T, w, wscale) w_min = ignorenan_minimum(w_adj) w_max = ignorenan_maximum(w_adj) @@ -499,7 +499,7 @@ Plots.@deps stepbins path wand_edges(x...) = (warn("Load the StatPlots package in order to use :wand bins. Defaulting to :auto", once = true); :auto) -function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) +function _auto_binning_nbins(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) where N _cl(x) = ceil(Int, NaNMath.max(x, one(x))) _iqr(v) = (q = quantile(v, 0.75) - quantile(v, 0.25); q > 0 ? q : oftype(q, 1)) _span(v) = ignorenan_maximum(v) - ignorenan_minimum(v) @@ -533,20 +533,20 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode end end -_hist_edge{N}(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Integer) = StatsBase.histrange(vs[dim], binning, :left) -_hist_edge{N}(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Symbol) = _hist_edge(vs, dim, _auto_binning_nbins(vs, dim, mode = binning)) -_hist_edge{N}(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) = binning +_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Integer) where {N} = StatsBase.histrange(vs[dim], binning, :left) +_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Symbol) where {N} = _hist_edge(vs, dim, _auto_binning_nbins(vs, dim, mode = binning)) +_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) where {N} = binning -_hist_edges{N}(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) = +_hist_edges(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) where {N} = map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...)) -_hist_edges{N}(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) = +_hist_edges(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) where {N} = map(dim -> _hist_edge(vs, dim, binning), (1:N...)) _hist_norm_mode(mode::Symbol) = mode _hist_norm_mode(mode::Bool) = mode ? :pdf : :none -function _make_hist{N}(vs::NTuple{N,AbstractVector}, binning; normed = false, weights = nothing) +function _make_hist(vs::NTuple{N,AbstractVector}, binning; normed = false, weights = nothing) where N edges = _hist_edges(vs, binning) h = float( weights == nothing ? StatsBase.fit(StatsBase.Histogram, vs, edges, closed = :left) : @@ -590,7 +590,7 @@ end @deps scatterhist scatterbins -@recipe function f{T, E}(h::StatsBase.Histogram{T, 1, E}) +@recipe function f(h::StatsBase.Histogram{T, 1, E}) where {T, E} seriestype --> :barbins st_map = Dict( @@ -611,7 +611,7 @@ end end -@recipe function f{H <: StatsBase.Histogram}(hv::AbstractVector{H}) +@recipe function f(hv::AbstractVector{H}) where H <: StatsBase.Histogram for h in hv @series begin h @@ -658,7 +658,7 @@ end @deps histogram2d bins2d -@recipe function f{T, E}(h::StatsBase.Histogram{T, 2, E}) +@recipe function f(h::StatsBase.Histogram{T, 2, E}) where {T, E} seriestype --> :bins2d (h.edges[1], h.edges[2], Surface(h.weights)) end @@ -855,7 +855,7 @@ end # TODO: move OHLC to PlotRecipes finance.jl "Represent Open High Low Close data (used in finance)" -type OHLC{T<:Real} +mutable struct OHLC{T<:Real} open::T high::T low::T @@ -894,10 +894,10 @@ end # to squash ambiguity warnings... @recipe f(x::AVec{Function}, v::AVec{OHLC}) = error() -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(x::AVec{Function}, v::AVec{Tuple{R1,R2,R3,R4}}) = error() +@recipe f(x::AVec{Function}, v::AVec{Tuple{R1,R2,R3,R4}}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = error() # this must be OHLC? -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(x::AVec, ohlc::AVec{Tuple{R1,R2,R3,R4}}) = x, OHLC[OHLC(t...) for t in ohlc] +@recipe f(x::AVec, ohlc::AVec{Tuple{R1,R2,R3,R4}}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = x, OHLC[OHLC(t...) for t in ohlc] @recipe function f(x::AVec, v::AVec{OHLC}) seriestype := :path @@ -987,7 +987,7 @@ datetimeformatter(dt) = string(DateTime(Dates.UTM(dt))) # ------------------------------------------------- # Complex Numbers -@recipe function f{T<:Number}(A::Array{Complex{T}}) +@recipe function f(A::Array{Complex{T}}) where T<:Number xguide --> "Re(x)" yguide --> "Im(x)" real.(A), imag.(A) @@ -996,7 +996,7 @@ end # Splits a complex matrix to its real and complex parts # Reals defaults solid, imaginary defaults dashed # Label defaults are changed to match the real-imaginary reference / indexing -@recipe function f{T<:Real,T2}(x::AbstractArray{T},y::Array{Complex{T2}}) +@recipe function f(x::AbstractArray{T},y::Array{Complex{T2}}) where {T<:Real,T2} ylabel --> "Re(y)" zlabel --> "Im(y)" x,real.(y),imag.(y) diff --git a/src/series.jl b/src/series.jl index c0d7d4c2..1f00bb6e 100644 --- a/src/series.jl +++ b/src/series.jl @@ -20,10 +20,10 @@ convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing # numeric vector -convertToAnyVector{T<:Number}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:Number} = Any[v], nothing # string vector -convertToAnyVector{T<:AbstractString}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:AbstractString} = Any[v], nothing function convertToAnyVector(v::AMat, d::KW) if all3D(d) @@ -99,8 +99,8 @@ nobigs(v) = v end # not allowed -compute_xyz{F<:Function}(x::Void, y::FuncOrFuncs{F}, z) = error("If you want to plot the function `$y`, you need to define the x values!") -compute_xyz{F<:Function}(x::Void, y::Void, z::FuncOrFuncs{F}) = error("If you want to plot the function `$z`, you need to define x and y values!") +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!") # -------------------------------------------------------------------- @@ -109,7 +109,7 @@ compute_xyz(x::Void, y::Void, z::Void) = error("x/y/z are all nothing!") # we are going to build recipes to do the processing and splitting of the args # ensure we dispatch to the slicer -immutable SliceIt end +struct SliceIt end # the catch-all recipes @recipe function f(::Type{SliceIt}, x, y, z) @@ -163,10 +163,10 @@ immutable SliceIt end end # this is the default "type recipe"... just pass the object through -@recipe f{T<:Any}(::Type{T}, v::T) = v +@recipe f(::Type{T}, v::T) where {T<:Any} = v # this should catch unhandled "series recipes" and error with a nice message -@recipe f{V<:Val}(::Type{V}, x, y, z) = error("The backend must not support the series type $V, and there isn't a series recipe defined.") +@recipe f(::Type{V}, x, y, z) where {V<:Val} = error("The backend must not support the series type $V, and there isn't a series recipe defined.") _apply_type_recipe(d, v) = RecipesBase.apply_recipe(d, typeof(v), v)[1].args[1] @@ -201,7 +201,7 @@ end # end # don't do anything for ints or floats -_apply_type_recipe{T<:Union{Integer,AbstractFloat}}(d, v::AbstractArray{T}) = v +_apply_type_recipe(d, v::AbstractArray{T}) where {T<:Union{Integer,AbstractFloat}} = v # handle "type recipes" by converting inputs, and then either re-calling or slicing @recipe function f(x, y, z) @@ -274,7 +274,7 @@ end @recipe f(n::Integer) = is3d(get(plotattributes,:seriestype,:path)) ? (SliceIt, n, n, n) : (SliceIt, n, n, nothing) # return a surface if this is a 3d plot, otherwise let it be sliced up -@recipe function f{T<:Union{Integer,AbstractFloat}}(mat::AMat{T}) +@recipe function f(mat::AMat{T}) where T<:Union{Integer,AbstractFloat} if all3D(plotattributes) n,m = size(mat) wrap_surfaces(plotattributes) @@ -285,7 +285,7 @@ end end # if a matrix is wrapped by Formatted, do similar logic, but wrap data with Surface -@recipe function f{T<:AbstractMatrix}(fmt::Formatted{T}) +@recipe function f(fmt::Formatted{T}) where T<:AbstractMatrix if all3D(plotattributes) mat = fmt.data n,m = size(mat) @@ -297,7 +297,7 @@ end end # assume this is a Volume, so construct one -@recipe function f{T<:Number}(vol::AbstractArray{T,3}, args...) +@recipe function f(vol::AbstractArray{T,3}, args...) where T<:Number seriestype := :volume SliceIt, nothing, Volume(vol, args...), nothing end @@ -305,7 +305,7 @@ end # # images - grays -@recipe function f{T<:Gray}(mat::AMat{T}) +@recipe function f(mat::AMat{T}) where T<:Gray if is_seriestype_supported(:image) seriestype := :image n, m = size(mat) @@ -320,7 +320,7 @@ end # # images - colors -@recipe function f{T<:Colorant}(mat::AMat{T}) +@recipe function f(mat::AMat{T}) where T<:Colorant n, m = size(mat) if is_seriestype_supported(:image) @@ -358,7 +358,7 @@ end # function without range... use the current range of the x-axis -@recipe function f{F<:Function}(f::FuncOrFuncs{F}) +@recipe function f(f::FuncOrFuncs{F}) where F<:Function plt = plotattributes[:plot_object] xmin, xmax = try axis_limits(plt[1][:xaxis]) @@ -397,7 +397,7 @@ end # # if functions come first, just swap the order (not to be confused with parametric functions... # # as there would be more than one function passed in) -@recipe function f{F<:Function}(f::FuncOrFuncs{F}, x) +@recipe function f(f::FuncOrFuncs{F}, x) where F<:Function F2 = typeof(x) @assert !(F2 <: Function || (F2 <: AbstractArray && F2.parameters[1] <: Function)) # otherwise we'd hit infinite recursion here x, f @@ -465,19 +465,19 @@ end xs = adapted_grid(f, (xmin, xmax)) xs, f end -@recipe function f{F<:Function}(fs::AbstractArray{F}, xmin::Number, xmax::Number) +@recipe function f(fs::AbstractArray{F}, xmin::Number, xmax::Number) where F<:Function xs = Any[adapted_grid(f, (xmin, xmax)) for f in fs] xs, fs end -@recipe f{F<:Function,G<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, u::AVec) = mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u) -@recipe f{F<:Function,G<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, umin::Number, umax::Number, n = 200) = fx, fy, linspace(umin, umax, n) +@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, u::AVec) where {F<:Function,G<:Function} = mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u) +@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, umin::Number, umax::Number, n = 200) where {F<:Function,G<:Function} = fx, fy, linspace(umin, umax, n) # # # special handling... 3D parametric function(s) -@recipe function f{F<:Function,G<:Function,H<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, u::AVec) +@recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, u::AVec) where {F<:Function,G<:Function,H<:Function} mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u) end -@recipe function f{F<:Function,G<:Function,H<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, umin::Number, umax::Number, numPoints = 200) +@recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, umin::Number, umax::Number, numPoints = 200) where {F<:Function,G<:Function,H<:Function} fx, fy, fz, linspace(umin, umax, numPoints) end @@ -492,28 +492,28 @@ end # # # (x,y) tuples -@recipe f{R1<:Number,R2<:Number}(xy::AVec{Tuple{R1,R2}}) = unzip(xy) -@recipe f{R1<:Number,R2<:Number}(xy::Tuple{R1,R2}) = [xy[1]], [xy[2]] +@recipe f(xy::AVec{Tuple{R1,R2}}) where {R1<:Number,R2<:Number} = unzip(xy) +@recipe f(xy::Tuple{R1,R2}) where {R1<:Number,R2<:Number} = [xy[1]], [xy[2]] # # # (x,y,z) tuples -@recipe f{R1<:Number,R2<:Number,R3<:Number}(xyz::AVec{Tuple{R1,R2,R3}}) = unzip(xyz) -@recipe f{R1<:Number,R2<:Number,R3<:Number}(xyz::Tuple{R1,R2,R3}) = [xyz[1]], [xyz[2]], [xyz[3]] +@recipe f(xyz::AVec{Tuple{R1,R2,R3}}) where {R1<:Number,R2<:Number,R3<:Number} = unzip(xyz) +@recipe f(xyz::Tuple{R1,R2,R3}) where {R1<:Number,R2<:Number,R3<:Number} = [xyz[1]], [xyz[2]], [xyz[3]] # these might be points+velocity, or OHLC or something else -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::AVec{Tuple{R1,R2,R3,R4}}) = get(plotattributes,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv) -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::Tuple{R1,R2,R3,R4}) = [xyuv[1]], [xyuv[2]], [xyuv[3]], [xyuv[4]] +@recipe f(xyuv::AVec{Tuple{R1,R2,R3,R4}}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = get(plotattributes,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv) +@recipe f(xyuv::Tuple{R1,R2,R3,R4}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = [xyuv[1]], [xyuv[2]], [xyuv[3]], [xyuv[4]] # # # 2D FixedSizeArrays -@recipe f{T<:Number}(xy::AVec{FixedSizeArrays.Vec{2,T}}) = unzip(xy) -@recipe f{T<:Number}(xy::FixedSizeArrays.Vec{2,T}) = [xy[1]], [xy[2]] +@recipe f(xy::AVec{FixedSizeArrays.Vec{2,T}}) where {T<:Number} = unzip(xy) +@recipe f(xy::FixedSizeArrays.Vec{2,T}) where {T<:Number} = [xy[1]], [xy[2]] # # # 3D FixedSizeArrays -@recipe f{T<:Number}(xyz::AVec{FixedSizeArrays.Vec{3,T}}) = unzip(xyz) -@recipe f{T<:Number}(xyz::FixedSizeArrays.Vec{3,T}) = [xyz[1]], [xyz[2]], [xyz[3]] +@recipe f(xyz::AVec{FixedSizeArrays.Vec{3,T}}) where {T<:Number} = unzip(xyz) +@recipe f(xyz::FixedSizeArrays.Vec{3,T}) where {T<:Number} = [xyz[1]], [xyz[2]], [xyz[3]] # # # -------------------------------------------------------------------- diff --git a/src/subplots.jl b/src/subplots.jl index 5629125f..a47bc8ee 100644 --- a/src/subplots.jl +++ b/src/subplots.jl @@ -1,6 +1,6 @@ -function Subplot{T<:AbstractBackend}(::T; parent = RootLayout()) +function Subplot(::T; parent = RootLayout()) where T<:AbstractBackend Subplot{T}( parent, Series[], diff --git a/src/types.jl b/src/types.jl index 3e07587b..bd53715b 100644 --- a/src/types.jl +++ b/src/types.jl @@ -6,20 +6,20 @@ const AVec = AbstractVector const AMat = AbstractMatrix const KW = Dict{Symbol,Any} -immutable PlotsDisplay <: Display end +struct PlotsDisplay <: Display end # ----------------------------------------------------------- -immutable InputWrapper{T} +struct InputWrapper{T} obj::T end -wrap{T}(obj::T) = InputWrapper{T}(obj) +wrap(obj::T) where {T} = InputWrapper{T}(obj) Base.isempty(wrapper::InputWrapper) = false # ----------------------------------------------------------- -type Series +mutable struct Series d::KW end @@ -29,7 +29,7 @@ attr!(series::Series, v, k::Symbol) = (series.d[k] = v) # ----------------------------------------------------------- # a single subplot -type Subplot{T<:AbstractBackend} <: AbstractLayout +mutable struct Subplot{T<:AbstractBackend} <: AbstractLayout parent::AbstractLayout series_list::Vector{Series} # arguments for each series minpad::Tuple # leftpad, toppad, rightpad, bottompad @@ -45,12 +45,12 @@ Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}") # ----------------------------------------------------------- # simple wrapper around a KW so we can hold all attributes pertaining to the axis in one place -type Axis +mutable struct Axis sps::Vector{Subplot} d::KW end -type Extrema +mutable struct Extrema emin::Float64 emax::Float64 end @@ -63,7 +63,7 @@ const SubplotMap = Dict{Any, Subplot} # ----------------------------------------------------------- -type Plot{T<:AbstractBackend} <: AbstractPlot{T} +mutable struct Plot{T<:AbstractBackend} <: AbstractPlot{T} backend::T # the backend type n::Int # number of series attr::KW # arguments for the whole plot diff --git a/src/utils.jl b/src/utils.jl index 65142bfc..81cd3571 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -114,7 +114,7 @@ function regressionXY(x, y) regx, regy end -function replace_image_with_heatmap{T<:Colorant}(z::Array{T}) +function replace_image_with_heatmap(z::Array{T}) where T<:Colorant @show T, size(z) n, m = size(z) # idx = 0 @@ -138,14 +138,14 @@ end # --------------------------------------------------------------- "Build line segments for plotting" -type Segments{T} +mutable struct Segments{T} pts::Vector{T} end # Segments() = Segments{Float64}(zeros(0)) Segments() = Segments(Float64) -Segments{T}(::Type{T}) = Segments(T[]) +Segments(::Type{T}) where {T} = Segments(T[]) Segments(p::Int) = Segments(NTuple{2,Float64}[]) @@ -157,7 +157,7 @@ to_nan(::Type{NTuple{2,Float64}}) = (NaN, NaN) coords(segs::Segments{Float64}) = segs.pts coords(segs::Segments{NTuple{2,Float64}}) = Float64[p[1] for p in segs.pts], Float64[p[2] for p in segs.pts] -function Base.push!{T}(segments::Segments{T}, vs...) +function Base.push!(segments::Segments{T}, vs...) where T if !isempty(segments.pts) push!(segments.pts, to_nan(T)) end @@ -167,7 +167,7 @@ function Base.push!{T}(segments::Segments{T}, vs...) segments end -function Base.push!{T}(segments::Segments{T}, vs::AVec) +function Base.push!(segments::Segments{T}, vs::AVec) where T if !isempty(segments.pts) push!(segments.pts, to_nan(T)) end @@ -181,7 +181,7 @@ end # ----------------------------------------------------- # helper to manage NaN-separated segments -type SegmentsIterator +mutable struct SegmentsIterator args::Tuple n::Int end @@ -232,8 +232,8 @@ end # Find minimal type that can contain NaN and x # To allow use of NaN separated segments with categorical x axis -float_extended_type{T}(x::AbstractArray{T}) = Union{T,Float64} -float_extended_type{T<:Real}(x::AbstractArray{T}) = Float64 +float_extended_type(x::AbstractArray{T}) where {T} = Union{T,Float64} +float_extended_type(x::AbstractArray{T}) where {T<:Real} = Float64 # ------------------------------------------------------------------------------------ @@ -259,27 +259,27 @@ _cycle(grad::ColorGradient, idx::Int) = _cycle(grad.colors, idx) _cycle(grad::ColorGradient, indices::AVec{Int}) = _cycle(grad.colors, indices) makevec(v::AVec) = v -makevec{T}(v::T) = T[v] +makevec(v::T) where {T} = T[v] "duplicate a single value, or pass the 2-tuple through" maketuple(x::Real) = (x,x) -maketuple{T,S}(x::Tuple{T,S}) = x +maketuple(x::Tuple{T,S}) where {T,S} = x mapFuncOrFuncs(f::Function, u::AVec) = map(f, u) -mapFuncOrFuncs{F<:Function}(fs::AVec{F}, u::AVec) = [map(f, u) for f in fs] +mapFuncOrFuncs(fs::AVec{F}, u::AVec) where {F<:Function} = [map(f, u) for f in fs] -unzip{X,Y}(xy::AVec{Tuple{X,Y}}) = [t[1] for t in xy], [t[2] for t in xy] -unzip{X,Y,Z}(xyz::AVec{Tuple{X,Y,Z}}) = [t[1] for t in xyz], [t[2] for t in xyz], [t[3] for t in xyz] -unzip{X,Y,U,V}(xyuv::AVec{Tuple{X,Y,U,V}}) = [t[1] for t in xyuv], [t[2] for t in xyuv], [t[3] for t in xyuv], [t[4] for t in xyuv] +unzip(xy::AVec{Tuple{X,Y}}) where {X,Y} = [t[1] for t in xy], [t[2] for t in xy] +unzip(xyz::AVec{Tuple{X,Y,Z}}) where {X,Y,Z} = [t[1] for t in xyz], [t[2] for t in xyz], [t[3] for t in xyz] +unzip(xyuv::AVec{Tuple{X,Y,U,V}}) where {X,Y,U,V} = [t[1] for t in xyuv], [t[2] for t in xyuv], [t[3] for t in xyuv], [t[4] for t in xyuv] -unzip{T}(xy::AVec{FixedSizeArrays.Vec{2,T}}) = T[t[1] for t in xy], T[t[2] for t in xy] -unzip{T}(xy::FixedSizeArrays.Vec{2,T}) = T[xy[1]], T[xy[2]] +unzip(xy::AVec{FixedSizeArrays.Vec{2,T}}) where {T} = T[t[1] for t in xy], T[t[2] for t in xy] +unzip(xy::FixedSizeArrays.Vec{2,T}) where {T} = T[xy[1]], T[xy[2]] -unzip{T}(xyz::AVec{FixedSizeArrays.Vec{3,T}}) = T[t[1] for t in xyz], T[t[2] for t in xyz], T[t[3] for t in xyz] -unzip{T}(xyz::FixedSizeArrays.Vec{3,T}) = T[xyz[1]], T[xyz[2]], T[xyz[3]] +unzip(xyz::AVec{FixedSizeArrays.Vec{3,T}}) where {T} = T[t[1] for t in xyz], T[t[2] for t in xyz], T[t[3] for t in xyz] +unzip(xyz::FixedSizeArrays.Vec{3,T}) where {T} = T[xyz[1]], T[xyz[2]], T[xyz[3]] -unzip{T}(xyuv::AVec{FixedSizeArrays.Vec{4,T}}) = T[t[1] for t in xyuv], T[t[2] for t in xyuv], T[t[3] for t in xyuv], T[t[4] for t in xyuv] -unzip{T}(xyuv::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[3]], T[xyuv[4]] +unzip(xyuv::AVec{FixedSizeArrays.Vec{4,T}}) where {T} = T[t[1] for t in xyuv], T[t[2] for t in xyuv], T[t[3] for t in xyuv], T[t[4] for t in xyuv] +unzip(xyuv::FixedSizeArrays.Vec{4,T}) where {T} = T[xyuv[1]], T[xyuv[2]], T[xyuv[3]], T[xyuv[4]] # given 2-element lims and a vector of data x, widen lims to account for the extrema of x function _expand_limits(lims, x) @@ -388,7 +388,7 @@ isatom() = isdefined(Main, :Atom) && Main.Atom.isconnected() function is_installed(pkgstr::AbstractString) try - Pkg.installed(pkgstr) === nothing ? false: true + Pkg.installed(pkgstr) === nothing ? false : true catch false end @@ -410,20 +410,20 @@ isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert) isvertical(series::Series) = isvertical(series.d) -ticksType{T<:Real}(ticks::AVec{T}) = :ticks -ticksType{T<:AbstractString}(ticks::AVec{T}) = :labels -ticksType{T<:AVec,S<:AVec}(ticks::Tuple{T,S}) = :ticks_and_labels +ticksType(ticks::AVec{T}) where {T<:Real} = :ticks +ticksType(ticks::AVec{T}) where {T<:AbstractString} = :labels +ticksType(ticks::Tuple{T,S}) where {T<:AVec,S<:AVec} = :ticks_and_labels ticksType(ticks) = :invalid -limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits +limsType(lims::Tuple{T,S}) where {T<:Real,S<:Real} = :limits limsType(lims::Symbol) = lims == :auto ? :auto : :invalid limsType(lims) = :invalid # axis_Symbol(letter, postfix) = Symbol(letter * postfix) # axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix) -Base.convert{T<:Real}(::Type{Vector{T}}, rng::Range{T}) = T[x for x in rng] -Base.convert{T<:Real,S<:Real}(::Type{Vector{T}}, rng::Range{S}) = T[x for x in rng] +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.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b))) @@ -727,7 +727,7 @@ end # --------------------------------------------------------------- # --------------------------------------------------------------- -type DebugMode +mutable struct DebugMode on::Bool end const _debugMode = DebugMode(false) @@ -765,10 +765,10 @@ 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{T}(v::Range{T}, z::Real) = extendSeriesData(float(collect(v)), z) -extendSeriesData{T}(v::Range{T}, z::AVec) = extendSeriesData(float(collect(v)), z) -extendSeriesData{T}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v) -extendSeriesData{T}(v::AVec{T}, z::AVec) = (append!(v, convert(Vector{T}, z)); 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::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) # ------------------------------------------------------- @@ -786,14 +786,14 @@ function getxyz(plt::Plot, i::Integer) tovec(d[:x]), tovec(d[:y]), tovec(d[:z]) end -function setxy!{X,Y}(plt::Plot, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot, xy::Tuple{X,Y}, i::Integer) where {X,Y} series = plt.series_list[i] series.d[:x], series.d[:y] = xy sp = series.d[:subplot] reset_extrema!(sp) _series_updated(plt, series) end -function setxyz!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) +function setxyz!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z} series = plt.series_list[i] series.d[:x], series.d[:y], series.d[:z] = xyz sp = series.d[:subplot] @@ -801,7 +801,7 @@ function setxyz!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) _series_updated(plt, series) end -function setxyz!{X,Y,Z<:AbstractMatrix}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) +function setxyz!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z<:AbstractMatrix} setxyz!(plt, (xyz[1], xyz[2], Surface(xyz[3])), i) end @@ -810,8 +810,8 @@ end # indexing notation # Base.getindex(plt::Plot, i::Integer) = getxy(plt, i) -Base.setindex!{X,Y}(plt::Plot, xy::Tuple{X,Y}, i::Integer) = (setxy!(plt, xy, i); plt) -Base.setindex!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) = (setxyz!(plt, xyz, i); plt) +Base.setindex!(plt::Plot, xy::Tuple{X,Y}, i::Integer) where {X,Y} = (setxy!(plt, xy, i); plt) +Base.setindex!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z} = (setxyz!(plt, xyz, i); plt) # ------------------------------------------------------- @@ -923,10 +923,10 @@ function Base.append!(plt::Plot, i::Integer, x::AVec, y::AVec, z::AVec) end # tuples -Base.push!{X,Y}(plt::Plot, xy::Tuple{X,Y}) = push!(plt, 1, xy...) -Base.push!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}) = push!(plt, 1, xyz...) -Base.push!{X,Y}(plt::Plot, i::Integer, xy::Tuple{X,Y}) = push!(plt, i, xy...) -Base.push!{X,Y,Z}(plt::Plot, i::Integer, xyz::Tuple{X,Y,Z}) = push!(plt, i, xyz...) +Base.push!(plt::Plot, xy::Tuple{X,Y}) where {X,Y} = push!(plt, 1, xy...) +Base.push!(plt::Plot, xyz::Tuple{X,Y,Z}) where {X,Y,Z} = push!(plt, 1, xyz...) +Base.push!(plt::Plot, i::Integer, xy::Tuple{X,Y}) where {X,Y} = push!(plt, i, xy...) +Base.push!(plt::Plot, i::Integer, xyz::Tuple{X,Y,Z}) where {X,Y,Z} = push!(plt, i, xyz...) # ------------------------------------------------------- # push/append for all series