diff --git a/src/backends/bokeh.jl b/src/backends/bokeh.jl index adad4777..6653285f 100644 --- a/src/backends/bokeh.jl +++ b/src/backends/bokeh.jl @@ -59,7 +59,7 @@ supported_args(::BokehBackend) = [ # :surface, # :levels, ] -supported_types(::BokehBackend) = [:none, :path, :scatter] +supported_types(::BokehBackend) = [:path, :scatter] supported_styles(::BokehBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supported_markers(::BokehBackend) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] supported_scales(::BokehBackend) = [:identity, :ln] diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 1d3dcfa8..4c75fb1f 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -24,10 +24,10 @@ supported_args(::GadflyBackend) = [ :orientation, ] supported_types(::GadflyBackend) = [ - :none, :line, :path, :steppre, :steppost, :sticks, - :scatter, :histogram2d, :hexbin, :histogram, + :path, + :scatter, :hexbin, :bar, - :hline, :vline, :contour, :shape + :contour, :shape ] supported_styles(::GadflyBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supported_markers(::GadflyBackend) = vcat(_allMarkers, Shape) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index baeb7d21..a1a44219 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -38,7 +38,7 @@ supported_args(::PyPlotBackend) = [ :clims, ] supported_types(::PyPlotBackend) = [ - :none, :line, :path, :steppre, :steppost, :shape, + :path, :steppre, :steppost, :shape, :scatter, :histogram2d, :hexbin, :histogram, :bar, :sticks, :hline, :vline, :heatmap, :pie, :image, @@ -412,7 +412,7 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) # for each plotting command, optionally build and add a series handle to the list # line plot - if st in (:path, :line, :path3d, :steppre, :steppost) + if st in (:path, :path3d, :steppre, :steppost) if d[:linewidth] > 0 handle = ax[:plot](xyargs...; label = d[:label], @@ -491,7 +491,7 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) end # add markers? - if d[:markershape] != :none && st in (:path, :line, :scatter, :path3d, + if d[:markershape] != :none && st in (:path, :scatter, :path3d, :scatter3d, :steppre, :steppost, :bar, :sticks) extrakw = KW() diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index 04f6d75d..78fd1886 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -44,7 +44,7 @@ supported_args(::QwtBackend) = [ :xscale, :yscale, ] -supported_types(::QwtBackend) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :histogram2d, :hexbin, :histogram, :bar, :hline, :vline] +supported_types(::QwtBackend) = [:path, :scatter, :hexbin, :bar] supported_markers(::QwtBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon] supported_scales(::QwtBackend) = [:identity, :log10] is_subplot_supported(::QwtBackend) = true diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 0442bcf3..3a6be5f6 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -52,8 +52,8 @@ supported_args(::UnicodePlotsBackend) = [ # :z, ] supported_types(::UnicodePlotsBackend) = [ - :path, :steppre, :steppost, :scatter, - :histogram2d, :hline, :vline + :path, :scatter, + :histogram2d ] supported_styles(::UnicodePlotsBackend) = [:auto, :solid] supported_markers(::UnicodePlotsBackend) = [:none, :auto, :ellipse] diff --git a/src/backends/winston.jl b/src/backends/winston.jl index ecae13e3..65baafd4 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -55,7 +55,7 @@ supported_args(::WinstonBackend) = [ # :yflip, # :z, ] -supported_types(::WinstonBackend) = [:none, :line, :path, :sticks, :scatter, :histogram, :bar] +supported_types(::WinstonBackend) = [:path, :scatter, :bar] supported_styles(::WinstonBackend) = [:auto, :solid, :dash, :dot, :dashdot] supported_markers(::WinstonBackend) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] supported_scales(::WinstonBackend) = [:identity, :log10] diff --git a/src/layouts.jl b/src/layouts.jl index 0e2fa547..bfc68830 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -102,7 +102,19 @@ end Base.show(io::IO, layout::AbstractLayout) = print(io, "$(typeof(layout))$(size(layout))") # create a new bbox -bbox(left, top, w, h) = BoundingBox(left, top, w, h) +function bbox(x, y, w, h; h_anchor = :left, v_anchor = :top) + left = if h_anchor == :left + x + else + x - w * (h_anchor == :right ? 1.0 : 0.5) + end + top = if v_anchor == :top + y + else + y - h * (v_anchor == :bottom ? 1.0 : 0.5) + end + BoundingBox(left, top, w, h) +end # this is the available area for drawing everything in this layout... as percentages of total canvas bbox(layout::AbstractLayout) = layout.bbox diff --git a/src/plot.jl b/src/plot.jl index 191a4d8b..3f4fbc99 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -94,6 +94,9 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...) for (idx, sp) in enumerate(plt.subplots) _initialize_subplot(plt, sp) serieslist = series_list(sp) + if sp in sp.plt.inset_subplots + push!(plt.inset_subplots, sp) + end sp.plt = plt sp.attr[:subplot_index] = idx for series in serieslist diff --git a/src/recipes.jl b/src/recipes.jl index 6ee5a62a..a1601033 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -53,7 +53,47 @@ end # ---------------------------------------------------------------------------------- +const _series_recipe_deps = Dict() +function series_recipe_dependencies(st::Symbol, deps::Symbol...) + _series_recipe_deps[st] = deps +end + +function seriestype_supported(st::Symbol) + seriestype_supported(backend(), st) +end + +# returns :no, :native, or :recipe depending on how it's supported +function seriestype_supported(pkg::AbstractBackend, st::Symbol) + # is it natively supported + if st in supported_types(pkg) + return :native + end + + haskey(_series_recipe_deps, st) || return :no + + supported = true + for dep in _series_recipe_deps[st] + if seriestype_supported(pkg, dep) == :no + supported = false + end + end + supported ? :recipe : :no +end + +macro deps(st, args...) + :(series_recipe_dependencies($(quot(st)), $(map(quot, args)...))) +end + +# get a list of all seriestypes +function all_seriestypes() + sts = Set{Symbol}(keys(_series_recipe_deps)) + for bsym in backends() + btype = _backendType[bsym] + sts = union(sts, Set{Symbol}(supported_types(btype()))) + end + sort(collect(sts)) +end # ---------------------------------------------------------------------------------- @@ -156,21 +196,23 @@ end seriestype := :path () end +@deps line path -@recipe function f(::Type{Val{:sticks}}, x, y, z) - nx = length(x) - n = 3nx - newx, newy = zeros(n), zeros(n) - for i=1:nx - rng = 3i-2:3i - newx[rng] = x[i] - newy[rng] = [0., y[i], 0.] - end - x := newx - y := newy - seriestype := :path - () -end +# @recipe function f(::Type{Val{:sticks}}, x, y, z) +# nx = length(x) +# n = 3nx +# newx, newy = zeros(n), zeros(n) +# for i=1:nx +# rng = 3i-2:3i +# newx[rng] = x[i] +# newy[rng] = [0., y[i], 0.] +# end +# x := newx +# y := newy +# seriestype := :path +# () +# end +# @deps sticks path @recipe function f(::Type{Val{:hline}}, x, y, z) xmin, xmax = axis_limits(d[:subplot][:xaxis]) @@ -182,6 +224,7 @@ end seriestype := :path () end +@deps hline path @recipe function f(::Type{Val{:vline}}, x, y, z) ymin, ymax = axis_limits(d[:subplot][:yaxis]) @@ -193,6 +236,7 @@ end seriestype := :path () end +@deps vline path # --------------------------------------------------------------------------- # steps @@ -231,6 +275,7 @@ end end () end +@deps steppre path scatter # create a path from steps @recipe function f(::Type{Val{:steppost}}, x, y, z) @@ -251,6 +296,7 @@ end end () end +@deps steppost path scatter # --------------------------------------------------------------------------- @@ -289,6 +335,7 @@ sticks_fillfrom(fr::AVec, i::Integer) = fr[mod1(i, length(fr))] end () end +@deps sticks path scatter # --------------------------------------------------------------------------- @@ -350,6 +397,7 @@ end seriestype := :path () end +@deps bar path # --------------------------------------------------------------------------- # Histograms @@ -402,6 +450,7 @@ end seriestype := :bar () end +@deps histogram bar # --------------------------------------------------------------------------- # Histogram 2D @@ -443,6 +492,7 @@ centers(v::AVec) = v[1] + cumsum(diff(v)) seriestype := :heatmap () end +@deps histogram2d heatmap # --------------------------------------------------------------------------- @@ -458,6 +508,8 @@ end () end +# note: don't add dependencies because this really isn't a drop-in replacement + # --------------------------------------------------------------------------- # Box Plot @@ -563,9 +615,8 @@ notch_width(q2, q4, N) = 1.58 * (q4-q2)/sqrt(N) end () # expects a tuple returned - - # KW[d] end +@deps boxplot shape scatter # --------------------------------------------------------------------------- # Violin Plot @@ -628,9 +679,8 @@ end d[:x], d[:y] = shape_coords(shapes) () - - # KW[d] end +@deps violin shape # --------------------------------------------------------------------------- # density @@ -649,6 +699,7 @@ end () end +@deps density path @@ -701,6 +752,7 @@ end d[:x], d[:y] = error_coords(d[:x], d[:y], error_zipit(d[:yerror])) () end +@deps yerror path @recipe function f(::Type{Val{:xerror}}, x, y, z) error_style!(d) @@ -708,6 +760,7 @@ end d[:y], d[:x] = error_coords(d[:y], d[:x], error_zipit(d[:xerror])) () end +@deps xerror path # --------------------------------------------------------------------------- @@ -807,6 +860,7 @@ end end () end +@deps quiver shape path # ---------------------------------------------------------------------------