starting no-conditional reorg; replaced FixedSizeArrays with StaticArrays

This commit is contained in:
Tom Breloff 2017-01-18 12:08:20 -05:00
parent 3b570edea1
commit 9d038ea05e
6 changed files with 70 additions and 35 deletions

View File

@ -4,6 +4,6 @@ RecipesBase
PlotUtils PlotUtils
PlotThemes PlotThemes
Reexport Reexport
FixedSizeArrays
Measures Measures
Showoff Showoff
StaticArrays

View File

@ -3,7 +3,7 @@ __precompile__(true)
module Plots module Plots
using Reexport using Reexport
using FixedSizeArrays using StaticArrays
@reexport using RecipesBase @reexport using RecipesBase
using Base.Meta using Base.Meta
@reexport using PlotUtils @reexport using PlotUtils

View File

@ -19,10 +19,11 @@ macro init_backend(s)
export $sym export $sym
$sym(; kw...) = (default(; kw...); backend(Symbol($str))) $sym(; kw...) = (default(; kw...); backend(Symbol($str)))
backend_name(::$T) = Symbol($str) backend_name(::$T) = Symbol($str)
backend_package_name(::$T) = Symbol("Plots", string(s))
push!(_backends, Symbol($str)) push!(_backends, Symbol($str))
_backendType[Symbol($str)] = $T _backendType[Symbol($str)] = $T
_backendSymbol[$T] = Symbol($str) _backendSymbol[$T] = Symbol($str)
include("backends/" * $str * ".jl") # include("backends/" * $str * ".jl")
end) end)
end end
@ -148,7 +149,7 @@ function pickDefaultBackend()
# the ordering/inclusion of this package list is my semi-arbitrary guess at # 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 # which one someone will want to use if they have the package installed...accounting for
# features, speed, and robustness # 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 if Pkg.installed(pkgstr) != nothing
return backend(Symbol(lowercase(pkgstr))) return backend(Symbol(lowercase(pkgstr)))
end end
@ -263,23 +264,32 @@ function merge_with_base_supported(v::AVec)
end end
# @init_backend PyPlot
# @init_backend Immerse # @init_backend UnicodePlots
# @init_backend Gadfly
@init_backend PyPlot
# @init_backend Qwt
@init_backend UnicodePlots
# @init_backend Winston
# @init_backend Bokeh
@init_backend Plotly @init_backend Plotly
@init_backend PlotlyJS # @init_backend PlotlyJS
@init_backend GR @init_backend GR
@init_backend GLVisualize # @init_backend GLVisualize
@init_backend PGFPlots # @init_backend PGFPlots
@init_backend InspectDR # @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 # create the various `is_xxx_supported` and `supported_xxxs` methods
# by default they pass through to checking membership in `_gr_xxx` # by default they pass through to checking membership in `_gr_xxx`
for s in (:attr, :seriestype, :marker, :style, :scale) for s in (:attr, :seriestype, :marker, :style, :scale)
@ -294,13 +304,38 @@ for s in (:attr, :seriestype, :marker, :style, :scale)
for bend in backends() for bend in backends()
bend_type = typeof(_backend_instance(bend)) bend_type = typeof(_backend_instance(bend))
v = Symbol("_", bend, "_", s) # v = Symbol("_", bend, "_", s)
v = Symbol("_", s)
@eval begin @eval begin
$f(::$bend_type, $s::Symbol) = $s in $v $f(::$bend_type, $s::Symbol) = $s in $v[$(quot(bend))]
$f2(::$bend_type) = $v $f2(::$bend_type) = $v[$(quot(bend))]
end end
end 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())

View File

@ -1,7 +1,7 @@
typealias P2 FixedSizeArrays.Vec{2,Float64} typealias P2 StaticArrays.SVector{2,Float64}
typealias P3 FixedSizeArrays.Vec{3,Float64} typealias P3 StaticArrays.SVector{3,Float64}
nanpush!(a::AbstractVector{P2}, b) = (push!(a, P2(NaN,NaN)); push!(a, b)) 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)) 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} control_points::Vector{T}
end end
@ -646,7 +646,7 @@ function (bc::BezierCurve)(t::Real)
end end
Base.mean(x::Real, y::Real) = 0.5*(x+y) 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 @deprecate curve_points coords

View File

@ -482,13 +482,13 @@ end
# #
# # 2D FixedSizeArrays # # 2D FixedSizeArrays
@recipe f{T<:Number}(xy::AVec{FixedSizeArrays.Vec{2,T}}) = unzip(xy) @recipe f{T<:Number}(xy::AVec{StaticArrays.SVector{2,T}}) = unzip(xy)
@recipe f{T<:Number}(xy::FixedSizeArrays.Vec{2,T}) = [xy[1]], [xy[2]] @recipe f{T<:Number}(xy::StaticArrays.SVector{2,T}) = [xy[1]], [xy[2]]
# #
# # 3D FixedSizeArrays # # 3D FixedSizeArrays
@recipe f{T<:Number}(xyz::AVec{FixedSizeArrays.Vec{3,T}}) = unzip(xyz) @recipe f{T<:Number}(xyz::AVec{StaticArrays.SVector{3,T}}) = unzip(xyz)
@recipe f{T<:Number}(xyz::FixedSizeArrays.Vec{3,T}) = [xyz[1]], [xyz[2]], [xyz[3]] @recipe f{T<:Number}(xyz::StaticArrays.SVector{3,T}) = [xyz[1]], [xyz[2]], [xyz[3]]
# #
# # -------------------------------------------------------------------- # # --------------------------------------------------------------------

View File

@ -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,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{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::AVec{StaticArrays.SVector{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::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::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::FixedSizeArrays.Vec{3,T}) = T[xyz[1]], T[xyz[2]], T[xyz[3]] 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::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::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[3]], T[xyuv[4]] 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 # given 2-element lims and a vector of data x, widen lims to account for the extrema of x
function _expand_limits(lims, x) function _expand_limits(lims, x)