diff --git a/src/axes.jl b/src/axes.jl index be8d318c..0979186a 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -576,18 +576,6 @@ end # ------------------------------------------------------------------------- -function pie_labels(sp::Subplot, series::Series) - plotattributes = series.plotattributes - if haskey(plotattributes,:x_discrete_indices) - dvals = sp.attr[:xaxis].plotattributes[:discrete_values] - [dvals[idx] for idx in plotattributes[:x_discrete_indices]] - else - plotattributes[:x] - end -end - -# ------------------------------------------------------------------------- - # compute the line segments which should be drawn for this axis function axis_drawing_info(sp::Subplot) xaxis, yaxis = sp[:xaxis], sp[:yaxis] diff --git a/src/backends.jl b/src/backends.jl index e47085de..5cac875f 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -341,10 +341,18 @@ const _gr_attr = merge_with_base_supported([ :contour_labels, ]) const _gr_seriestype = [ - :path, :scatter, :straightline, - :heatmap, :pie, :image, - :contour, :path3d, :scatter3d, :surface, :wireframe, :volume, - :shape + :path, + :scatter, + :straightline, + :heatmap, + :image, + :contour, + :path3d, + :scatter3d, + :surface, + :wireframe, + :volume, + :shape, ] const _gr_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] const _gr_marker = _allMarkers @@ -408,9 +416,17 @@ const _plotly_attr = merge_with_base_supported([ ]) const _plotly_seriestype = [ - :path, :scatter, :pie, :heatmap, - :contour, :surface, :wireframe, :path3d, :scatter3d, :shape, :scattergl, - :straightline + :path, + :scatter, + :heatmap, + :contour, + :surface, + :wireframe, + :path3d, + :scatter3d, + :shape, + :scattergl, + :straightline, ] const _plotly_style = [:auto, :solid, :dash, :dot, :dashdot] const _plotly_marker = [ @@ -533,12 +549,22 @@ const _pyplot_attr = merge_with_base_supported([ :contour_labels, ]) const _pyplot_seriestype = [ - :path, :steppre, :steppost, :shape, :straightline, - :scatter, :hexbin, #:histogram2d, :histogram, - # :bar, - :heatmap, :pie, :image, - :contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe - ] + :path, + :steppre, + :steppost, + :shape, + :straightline, + :scatter, + :hexbin, + :heatmap, + :image, + :contour, + :contour3d, + :path3d, + :scatter3d, + :surface, + :wireframe, +] const _pyplot_style = [:auto, :solid, :dash, :dot, :dashdot] const _pyplot_marker = vcat(_allMarkers, :pixel) const _pyplot_scale = [:identity, :ln, :log2, :log10] @@ -605,12 +631,22 @@ const _hdf5_attr = merge_with_base_supported([ :colorbar_title, ]) const _hdf5_seriestype = [ - :path, :steppre, :steppost, :shape, :straightline, - :scatter, :hexbin, #:histogram2d, :histogram, - # :bar, - :heatmap, :pie, :image, - :contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe - ] + :path, + :steppre, + :steppost, + :shape, + :straightline, + :scatter, + :hexbin, + :heatmap, + :image, + :contour, + :contour3d, + :path3d, + :scatter3d, + :surface, + :wireframe, +] const _hdf5_style = [:auto, :solid, :dash, :dot, :dashdot] const _hdf5_marker = vcat(_allMarkers, :pixel) const _hdf5_scale = [:identity, :ln, :log2, :log10] diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 2df14b29..9c35e440 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1048,9 +1048,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # axes_2d = true for series in series_list(sp) st = series[:seriestype] - if st == :pie - draw_axes = false - end if st in (:heatmap, :image) outside_ticks = true x, y = heatmap_edges(series[:x], sp[:xaxis][:scale], series[:y], sp[:yaxis][:scale], size(series[:z])) @@ -1704,54 +1701,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_draw_markers(series, x2, y2, clims) end - # TODO: replace with pie recipe - elseif st == :pie - GR.selntran(0) - GR.setfillintstyle(GR.INTSTYLE_SOLID) - xmin, xmax, ymin, ymax = viewport_plotarea - ymax -= 0.1 * (xmax - xmin) - xcenter = 0.5 * (xmin + xmax) - ycenter = 0.5 * (ymin + ymax) - if xmax - xmin > ymax - ymin - r = 0.5 * (ymax - ymin) - xmin, xmax = xcenter - r, xcenter + r - else - r = 0.5 * (xmax - xmin) - ymin, ymax = ycenter - r, ycenter + r - end - labels = pie_labels(sp, series) - slices = series[:y] - numslices = length(slices) - total = sum(slices) - a1 = 0 - x = zeros(3) - y = zeros(3) - for i in 1:numslices - a2 = round(Int, a1 + (slices[i] / total) * 360.0) - GR.setfillcolorind(980 + (i-1) % 20) - GR.fillarc(xmin, xmax, ymin, ymax, a1, a2) - α = 0.5 * (a1 + a2) - cosf = r * cos(α * pi / 180) - sinf = r * sin(α * pi / 180) - x[1] = xcenter + cosf - y[1] = ycenter + sinf - x[2] = x[1] + 0.1 * cosf - y[2] = y[1] + 0.1 * sinf - y[3] = y[2] - if 90 <= α < 270 - x[3] = x[2] - 0.05 - GR.settextalign(GR.TEXT_HALIGN_RIGHT, GR.TEXT_VALIGN_HALF) - gr_text(x[3] - 0.01, y[3], string(labels[i])) - else - x[3] = x[2] + 0.05 - GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) - gr_text(x[3] + 0.01, y[3], string(labels[i])) - end - gr_polyline(x, y) - a1 = a2 - end - GR.selntran(1) - elseif st == :shape x, y = shape_data(series) for (i,rng) in enumerate(iter_segments(x, y)) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 580420c6..f66c517c 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -757,7 +757,6 @@ function pgfx_should_add_to_legend(series::Series) :contourf, :contour3d, :heatmap, - :pie, :image, ) ) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index b06de5ca..6839dc4e 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -543,12 +543,6 @@ function plotly_series(plt::Plot, series::Series) plotattributes_out[:showscale] = hascolorbar(sp) end - elseif st == :pie - plotattributes_out[:type] = "pie" - plotattributes_out[:labels] = pie_labels(sp, series) - plotattributes_out[:values] = y - plotattributes_out[:hoverinfo] = "label+percent+name" - else @warn("Plotly: seriestype $st isn't supported.") return KW() diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 19d151f3..55ca7f3f 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -784,21 +784,6 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) push!(handles, handle) end - if st == :pie - handle = ax."pie"(y; - # colors = # a vector of colors? - labels = pie_labels(sp, series) - )[1] - push!(handles, handle) - - # # expand extrema... get list of Wedge objects - # for wedge in handle - # path = wedge[:get_path]() - # for - lim = 1.1 - expand_extrema!(sp, -lim, lim, -lim, lim) - end - series[:serieshandle] = handles # # smoothing diff --git a/src/examples.jl b/src/examples.jl index c4257e82..4b1f7e49 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -999,7 +999,6 @@ _backend_skips = Dict( 10, # histogram2d 16, # pgfplots thinks the upper panel is too small 22, # contourf - 23, # pie 25, # @df 30, # @df 31, # animation diff --git a/src/pipeline.jl b/src/pipeline.jl index c7be171f..4865b257 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -330,7 +330,7 @@ function _expand_subplot_extrema(sp::Subplot, plotattributes::AKW, st::Symbol) ymin, ymax = ignorenan_extrema(plotattributes[:y]) expand_extrema!(sp[:xaxis], (xmin, xmax)) expand_extrema!(sp[:yaxis], (ymin, ymax)) - elseif !(st in (:pie, :histogram, :bins2d, :histogram2d)) + elseif !(st in (:histogram, :bins2d, :histogram2d)) expand_extrema!(sp, plotattributes) end # expand for zerolines (axes through origin) diff --git a/src/recipes.jl b/src/recipes.jl index 246f80ae..7e12a7b1 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -885,6 +885,28 @@ end end +# --------------------------------------------------------------------------- +# pie +@recipe function f(::Type{Val{:pie}}, x, y, z) + framestyle --> :none + aspect_ratio --> true + s = sum(y) + θ = 0 + for i in eachindex(y) + θ_new = θ + 2π * y[i] / s + coords = [(0.0, 0.0); partialcircle(θ, θ_new, 50)] + @series begin + seriestype := :shape + label --> string(x[i]) + x := first.(coords) + y := last.(coords) + end + θ = θ_new + end +end +@deps pie shape + + # --------------------------------------------------------------------------- # scatter 3d diff --git a/src/shorthands.jl b/src/shorthands.jl index 7c48e925..63bec003 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -381,8 +381,7 @@ julia> curves([1,2,3,4],[1,1,2,4]) @shorthands curves "Plot a pie diagram" -pie(args...; kw...) = plot(args...; kw..., seriestype = :pie, aspect_ratio = :equal, grid=false, xticks=nothing, yticks=nothing) -pie!(args...; kw...) = plot!(args...; kw..., seriestype = :pie, aspect_ratio = :equal, grid=false, xticks=nothing, yticks=nothing) +@shorthands pie "Plot with seriestype :path3d" plot3d(args...; kw...) = plot(args...; kw..., seriestype = :path3d) diff --git a/src/subplots.jl b/src/subplots.jl index ef6efda5..35167349 100644 --- a/src/subplots.jl +++ b/src/subplots.jl @@ -42,12 +42,24 @@ get_subplot_index(plt::Plot, sp::Subplot) = findfirst(x -> x === sp, plt.subplot series_list(sp::Subplot) = sp.series_list # filter(series -> series.plotattributes[:subplot] === sp, sp.plt.series_list) function should_add_to_legend(series::Series) - series.plotattributes[:primary] && series.plotattributes[:label] != "" && - !(series.plotattributes[:seriestype] in ( - :hexbin,:bins2d,:histogram2d,:hline,:vline, - :contour,:contourf,:contour3d,:surface,:wireframe, - :heatmap, :pie, :image - )) + series.plotattributes[:primary] && + series.plotattributes[:label] != "" && + !( + series.plotattributes[:seriestype] in ( + :hexbin, + :bins2d, + :histogram2d, + :hline, + :vline, + :contour, + :contourf, + :contour3d, + :surface, + :wireframe, + :heatmap, + :image, + ) + ) end # ----------------------------------------------------------------------