Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ctarn committed Jul 15, 2024
1 parent 84548cc commit 1f84aba
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 65 deletions.
54 changes: 27 additions & 27 deletions ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ end
end

@reference_test "Pie with Segment-specific Radius" begin
fig = Makie.Figure()
ax = Makie.Axis(fig[1, 1]; autolimitaspect=1)
fig = Figure()
ax = Axis(fig[1, 1]; autolimitaspect=1)

kw = (; offset_radius=0.4, strokecolor=:transparent, strokewidth=0)
Makie.pie!(ax, ones(7); radius=sqrt.(2:8) * 3, kw..., color=Makie.wong_colors(0.8)[1:7])
pie!(ax, ones(7); radius=sqrt.(2:8) * 3, kw..., color=Makie.wong_colors(0.8)[1:7])

vs = [2, 3, 4, 5, 6, 7, 8]
vs_inner = [1, 1, 1, 1, 2, 2, 2]
Expand All @@ -387,16 +387,16 @@ end

lp = Makie.LinePattern(; direction=Makie.Vec2f(1, -1), width=2, tilesize=(12, 12), linecolor=:white, background_color=:transparent)
# draw the inner pie twice since `color` can not be vector of `LinePattern` currently
Makie.pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])
Makie.pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=lp)
Makie.pie!(ax, 20, 0, vs; radius=rs, inner_radius=rs_inner, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])
pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])
pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=lp)
pie!(ax, 20, 0, vs; radius=rs, inner_radius=rs_inner, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])

display(fig)
end

@reference_test "Pie Position" begin
fig = Makie.Figure()
ax = Makie.Axis(fig[1, 1]; autolimitaspect=1)
fig = Figure()
ax = Axis(fig[1, 1]; autolimitaspect=1)

vs = 0:6 |> Vector
vs_ = vs ./ sum(vs) .* (3/2*π)
Expand All @@ -406,25 +406,25 @@ end
Δr1 = [0, 0, 0.2, 0, 0.2, 0, 0]
Δr2 = [0, 0, 0.2, 0, 0, 0, 0]

Makie.pie!(ax, vs; color=cs)
Makie.pie!(ax, 3 .+ Δx, 0, vs; color=cs)
Makie.pie!(ax, 0, 3 .+ Δy, vs; color=cs)
Makie.pie!(ax, 3 .+ Δx, 3 .+ Δy, vs; color=cs)

Makie.pie!(ax, 7, 0, vs; color=cs, offset_radius=Δr1)
Makie.pie!(ax, 7, 3, vs; color=cs, offset_radius=0.2)
Makie.pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, offset_radius=0.2)
Makie.pie!(ax, 10, 0, vs_; color=cs, offset_radius=Δr1, normalize=false, offset=π/2)

Makie.pie!(ax, Makie.Point2(0.5, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
Makie.pie!(ax, Makie.Point2.(3.5, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
Makie.pie!(ax, Makie.Point2.(6.5 .+ Δx, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
Makie.pie!(ax, Makie.Point2.(9.5 .+ Δx, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)

Makie.pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
Makie.pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
Makie.pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
Makie.pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, vs; color=cs)
pie!(ax, 3 .+ Δx, 0, vs; color=cs)
pie!(ax, 0, 3 .+ Δy, vs; color=cs)
pie!(ax, 3 .+ Δx, 3 .+ Δy, vs; color=cs)

pie!(ax, 7, 0, vs; color=cs, offset_radius=Δr1)
pie!(ax, 7, 3, vs; color=cs, offset_radius=0.2)
pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, offset_radius=0.2)
pie!(ax, 10, 0, vs_; color=cs, offset_radius=Δr1, normalize=false, offset=π/2)

pie!(ax, Point2(0.5, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
pie!(ax, Point2.(3.5, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
pie!(ax, Point2.(6.5 .+ Δx, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
pie!(ax, Point2.(9.5 .+ Δx, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)

pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)

fig
end
Expand Down
56 changes: 27 additions & 29 deletions docs/src/reference/plots/pie.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ f
```

```@figure
import Makie, CairoMakie
fig = Makie.Figure()
ax = Makie.Axis(fig[1, 1]; autolimitaspect=1)
fig = Figure()
ax = Axis(fig[1, 1]; autolimitaspect=1)
kw = (; offset_radius=0.4, strokecolor=:transparent, strokewidth=0)
Makie.pie!(ax, ones(7); radius=sqrt.(2:8) * 3, kw..., color=Makie.wong_colors(0.8)[1:7])
pie!(ax, ones(7); radius=sqrt.(2:8) * 3, kw..., color=Makie.wong_colors(0.8)[1:7])
vs = [2, 3, 4, 5, 6, 7, 8]
vs_inner = [1, 1, 1, 1, 2, 2, 2]
Expand All @@ -51,16 +49,16 @@ rs_inner = sqrt.(vs_inner ./ vs) * rs
lp = Makie.LinePattern(; direction=Makie.Vec2f(1, -1), width=2, tilesize=(12, 12), linecolor=:white, background_color=:transparent)
# draw the inner pie twice since `color` can not be vector of `LinePattern` currently
Makie.pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])
Makie.pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=lp)
Makie.pie!(ax, 20, 0, vs; radius=rs, inner_radius=rs_inner, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])
pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])
pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=lp)
pie!(ax, 20, 0, vs; radius=rs, inner_radius=rs_inner, kw..., color=Makie.wong_colors(0.8)[eachindex(vs)])
display(fig)
```

```@figure
fig = Makie.Figure()
ax = Makie.Axis(fig[1, 1]; autolimitaspect=1)
fig = Figure()
ax = Axis(fig[1, 1]; autolimitaspect=1)
vs = 0:6 |> Vector
vs_ = vs ./ sum(vs) .* (3/2*π)
Expand All @@ -70,25 +68,25 @@ cs = Makie.wong_colors()
Δr1 = [0, 0, 0.2, 0, 0.2, 0, 0]
Δr2 = [0, 0, 0.2, 0, 0, 0, 0]
Makie.pie!(ax, vs; color=cs)
Makie.pie!(ax, 3 .+ Δx, 0, vs; color=cs)
Makie.pie!(ax, 0, 3 .+ Δy, vs; color=cs)
Makie.pie!(ax, 3 .+ Δx, 3 .+ Δy, vs; color=cs)
Makie.pie!(ax, 7, 0, vs; color=cs, offset_radius=Δr1)
Makie.pie!(ax, 7, 3, vs; color=cs, offset_radius=0.2)
Makie.pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, offset_radius=0.2)
Makie.pie!(ax, 10, 0, vs_; color=cs, offset_radius=Δr1, normalize=false, offset=π/2)
Makie.pie!(ax, Makie.Point2(0.5, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
Makie.pie!(ax, Makie.Point2.(3.5, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
Makie.pie!(ax, Makie.Point2.(6.5 .+ Δx, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
Makie.pie!(ax, Makie.Point2.(9.5 .+ Δx, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
Makie.pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
Makie.pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
Makie.pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
Makie.pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, vs; color=cs)
pie!(ax, 3 .+ Δx, 0, vs; color=cs)
pie!(ax, 0, 3 .+ Δy, vs; color=cs)
pie!(ax, 3 .+ Δx, 3 .+ Δy, vs; color=cs)
pie!(ax, 7, 0, vs; color=cs, offset_radius=Δr1)
pie!(ax, 7, 3, vs; color=cs, offset_radius=0.2)
pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, offset_radius=0.2)
pie!(ax, 10, 0, vs_; color=cs, offset_radius=Δr1, normalize=false, offset=π/2)
pie!(ax, Point2(0.5, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
pie!(ax, Point2.(3.5, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
pie!(ax, Point2.(6.5 .+ Δx, -3), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
pie!(ax, Point2.(9.5 .+ Δx, -3 .+ Δy), vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2)
pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, offset_radius=0.2, normalize=false, offset=π/2)
fig
```
Expand Down
20 changes: 11 additions & 9 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
radius = length(radius) == 1 ? fill(only(radius), length(vals)) : radius
inner_radius = length(inner_radius) == 1 ? fill(only(inner_radius), length(vals)) : inner_radius
offset_radius = length(offset_radius) == 1 ? fill(only(offset_radius), length(vals)) : offset_radius
Expand All @@ -61,17 +63,17 @@ function plot!(plot::Pie)

# curve points
points = map(LinRange(sta, en, nvertices)) do rad
Point2f(cos(rad + offset) * r + x, sin(rad + offset) * r + y)
Point2(cos(rad + offset) * r + x, sin(rad + offset) * r + y)
end

# add inner points (either curve or one point)
if inner_r != 0
inner_points = map(LinRange(en, sta, nvertices)) do rad
Point2f(cos(rad + offset) * inner_r + x, sin(rad + offset) * inner_r + y)
Point2(cos(rad + offset) * inner_r + x, sin(rad + offset) * inner_r + y)
end
append!(points, inner_points)
else
push!(points, Point2f(x, y))
push!(points, Point2(x, y))
end

points
Expand Down

0 comments on commit 1f84aba

Please sign in to comment.