diff --git a/REQUIRE b/REQUIRE index 67e5f781..9cced79d 100644 --- a/REQUIRE +++ b/REQUIRE @@ -4,6 +4,6 @@ RecipesBase PlotUtils PlotThemes Reexport -FixedSizeArrays Measures Showoff +StaticArrays diff --git a/src/Plots.jl b/src/Plots.jl index c957ab8a..7522d28b 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -3,7 +3,7 @@ __precompile__(true) module Plots using Reexport -using FixedSizeArrays +using StaticArrays @reexport using RecipesBase using Base.Meta @reexport using PlotUtils diff --git a/src/backends.jl b/src/backends.jl index 779b91cc..740a8dda 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -19,10 +19,11 @@ macro init_backend(s) export $sym $sym(; kw...) = (default(; kw...); backend(Symbol($str))) backend_name(::$T) = Symbol($str) + backend_package_name(::$T) = Symbol("Plots", string(s)) push!(_backends, Symbol($str)) _backendType[Symbol($str)] = $T _backendSymbol[$T] = Symbol($str) - include("backends/" * $str * ".jl") + # include("backends/" * $str * ".jl") end) end @@ -148,7 +149,7 @@ function pickDefaultBackend() # the ordering/inclusion of this package list is my semi-arbitrary guess at # which one someone will want to use if they have the package installed...accounting for # features, speed, and robustness - for pkgstr in ("PyPlot", "GR", "PlotlyJS", "Immerse", "Gadfly", "UnicodePlots") + for pkgstr in ("GR", "PlotlyJS", "PyPlot", "UnicodePlots") if Pkg.installed(pkgstr) != nothing return backend(Symbol(lowercase(pkgstr))) end @@ -263,23 +264,32 @@ function merge_with_base_supported(v::AVec) end - -# @init_backend Immerse -# @init_backend Gadfly -@init_backend PyPlot -# @init_backend Qwt -@init_backend UnicodePlots -# @init_backend Winston -# @init_backend Bokeh +# @init_backend PyPlot +# @init_backend UnicodePlots @init_backend Plotly -@init_backend PlotlyJS +# @init_backend PlotlyJS @init_backend GR -@init_backend GLVisualize -@init_backend PGFPlots -@init_backend InspectDR +# @init_backend GLVisualize +# @init_backend PGFPlots +# @init_backend InspectDR + +_initialize_backend(::PlotlyBackend) = include("backends/plotly.jl") + +function _initialize_backend(b::AbstractBackend) + bname = backend_name(b) + @eval import $(backend_package_name(b)) +end # --------------------------------------------------------- +const _attr = KW() +const _seriestype = KW() +const _marker = KW() +const _style = KW() +const _scale = KW() + +using Base.Meta + # create the various `is_xxx_supported` and `supported_xxxs` methods # by default they pass through to checking membership in `_gr_xxx` for s in (:attr, :seriestype, :marker, :style, :scale) @@ -294,13 +304,38 @@ for s in (:attr, :seriestype, :marker, :style, :scale) for bend in backends() bend_type = typeof(_backend_instance(bend)) - v = Symbol("_", bend, "_", s) + # v = Symbol("_", bend, "_", s) + v = Symbol("_", s) @eval begin - $f(::$bend_type, $s::Symbol) = $s in $v - $f2(::$bend_type) = $v + $f(::$bend_type, $s::Symbol) = $s in $v[$(quot(bend))] + $f2(::$bend_type) = $v[$(quot(bend))] end end end -# is_subplot_supported(::AbstractBackend) = false -# is_subplot_supported() = is_subplot_supported(backend()) +# --------------------------------------------------------- + +# # create the various `is_xxx_supported` and `supported_xxxs` methods +# # by default they pass through to checking membership in `_gr_xxx` +# for s in (:attr, :seriestype, :marker, :style, :scale) +# f = Symbol("is_", s, "_supported") +# f2 = Symbol("supported_", s, "s") +# @eval begin +# $f(::AbstractBackend, $s) = false +# $f(bend::AbstractBackend, $s::AbstractVector) = all(v -> $f(bend, v), $s) +# $f($s) = $f(backend(), $s) +# $f2() = $f2(backend()) +# end +# +# for bend in backends() +# bend_type = typeof(_backend_instance(bend)) +# v = Symbol("_", bend, "_", s) +# @eval begin +# $f(::$bend_type, $s::Symbol) = $s in $v +# $f2(::$bend_type) = $v +# end +# end +# end +# +# # is_subplot_supported(::AbstractBackend) = false +# # is_subplot_supported() = is_subplot_supported(backend()) diff --git a/src/components.jl b/src/components.jl index bbb2f9c2..9777977b 100644 --- a/src/components.jl +++ b/src/components.jl @@ -1,7 +1,7 @@ -typealias P2 FixedSizeArrays.Vec{2,Float64} -typealias P3 FixedSizeArrays.Vec{3,Float64} +typealias P2 StaticArrays.SVector{2,Float64} +typealias P3 StaticArrays.SVector{3,Float64} nanpush!(a::AbstractVector{P2}, b) = (push!(a, P2(NaN,NaN)); push!(a, b)) nanappend!(a::AbstractVector{P2}, b) = (push!(a, P2(NaN,NaN)); append!(a, b)) @@ -632,7 +632,7 @@ end # ----------------------------------------------------------------------- -type BezierCurve{T <: FixedSizeArrays.Vec} +type BezierCurve{T <: StaticArrays.SVector} control_points::Vector{T} end @@ -646,7 +646,7 @@ function (bc::BezierCurve)(t::Real) end Base.mean(x::Real, y::Real) = 0.5*(x+y) -Base.mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) +Base.mean{N,T<:Real}(ps::StaticArrays.SVector{N,T}...) = sum(ps) / length(ps) @deprecate curve_points coords diff --git a/src/series.jl b/src/series.jl index f7233c1a..fe940734 100644 --- a/src/series.jl +++ b/src/series.jl @@ -482,13 +482,13 @@ end # # # 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{T<:Number}(xy::AVec{StaticArrays.SVector{2,T}}) = unzip(xy) +@recipe f{T<:Number}(xy::StaticArrays.SVector{2,T}) = [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{T<:Number}(xyz::AVec{StaticArrays.SVector{3,T}}) = unzip(xyz) +@recipe f{T<:Number}(xyz::StaticArrays.SVector{3,T}) = [xyz[1]], [xyz[2]], [xyz[3]] # # # -------------------------------------------------------------------- diff --git a/src/utils.jl b/src/utils.jl index da1d1cb6..967893fd 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -271,14 +271,14 @@ unzip{X,Y}(xy::AVec{Tuple{X,Y}}) = [t[1] for t in xy], [t[2] for t 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{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{T}(xy::AVec{StaticArrays.SVector{2,T}}) = T[t[1] for t in xy], T[t[2] for t in xy] +unzip{T}(xy::StaticArrays.SVector{2,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{T}(xyz::AVec{StaticArrays.SVector{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::StaticArrays.SVector{3,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{T}(xyuv::AVec{StaticArrays.SVector{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::StaticArrays.SVector{4,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)