Skip to content

Commit

Permalink
better arg conv for pie
Browse files Browse the repository at this point in the history
  • Loading branch information
ctarn committed Jul 15, 2024
1 parent 05478b5 commit 604c0c6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/basic_recipes/pie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ Creates a pie chart from the given `values`.
MakieCore.mixin_generic_plot_attributes()...
end

convert_arguments(::Type{<:Pie}, values::Vector) = (0, 0, values)
convert_arguments(::Type{<:Pie}, point::Point, values::Vector) = (point[1], point[2], values)
convert_arguments(::Type{<:Pie}, point, values::Vector) = (getindex.(point, 1), getindex.(point, 2), values)
convert_arguments(::Type{<:Pie}, xs, ys, values::Vector) = (xs, ys, values)
convert_arguments(PT::Type{<:Pie}, values::RealVector) = convert_arguments(PT, 0.0, 0.0, values)
convert_arguments(PT::Type{<:Pie}, point::VecTypes{2}, values::RealVector) = convert_arguments(PT, point[1], point[2], values)
convert_arguments(PT::Type{<:Pie}, ps::AbstractVector{<:VecTypes{2}}, values::RealVector) = convert_arguments(PT, getindex.(ps, 1), getindex.(ps, 2), values)
convert_arguments(::Type{<:Pie}, xs::Union{Real,RealVector}, ys::Union{Real,RealVector}, values::RealVector) = begin
xs = length(xs) == 1 ? fill(only(xs), length(values)) : xs
ys = length(ys) == 1 ? fill(only(ys), length(values)) : ys
return (float_convert(xs), float_convert(ys), float_convert(values))
end

function plot!(plot::Pie)
xs = plot[1]
ys = plot[2]
values = plot[3]

polys = lift(plot, xs, ys, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset_radius, plot.offset, plot.normalize) do xs, ys, vals, vertex_per_deg, radius, inner_radius, offset_radius, offset, normalize
xs = length(xs) == 1 ? fill(only(xs), length(vals)) : xs
ys = length(ys) == 1 ? fill(only(ys), length(vals)) : ys
offset_radius = length(offset_radius) == 1 ? fill(only(offset_radius), length(vals)) : offset_radius

T = eltype(vals)
Expand Down

0 comments on commit 604c0c6

Please sign in to comment.