From 28a2812971487d820f7f3a74ab7fb7bf9c300a20 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sat, 13 Jul 2024 23:06:47 +0800 Subject: [PATCH 01/16] add position to `pie` --- src/basic_recipes/pie.jl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index 39783283fcc..c7e716a0fa0 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -17,6 +17,12 @@ Creates a pie chart from the given `values`. inner_radius = 0 "The angular offset of the first pie segment from the (1, 0) vector in radians." offset = 0 + "Position of pie segments (x-value, scalar or `length(values)` vector)" + x = 0 + "Position of pie segments (y-value, scalar or `length(values)` vector)" + y = 0 + "Position of pie segments (r-value as polar coordinate, scalar or `length(values)` vector)" + r = 0 MakieCore.mixin_generic_plot_attributes()... end @@ -24,7 +30,10 @@ function plot!(plot::Pie) values = plot[1] - polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize) do vals, vertex_per_deg, radius, inner_radius, offset, normalize + polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize, plot.x, plot.y, plot.r) do vals, vertex_per_deg, radius, inner_radius, offset, normalize, x, y, r + xs = length(x) == 1 ? fill(only(x), length(vals)) : x + ys = length(y) == 1 ? fill(only(y), length(vals)) : y + rs = length(r) == 1 ? fill(only(r), length(vals)) : r T = eltype(vals) @@ -37,25 +46,26 @@ function plot!(plot::Pie) end # create vector of a vector of points for each piece - vertex_arrays = map(boundaries[1:end-1], boundaries[2:end]) do sta, en + vertex_arrays = map(boundaries[1:end-1], boundaries[2:end], xs, ys, rs) do sta, en, x, y, r + x += cos((en + sta) / 2 + offset) * r + y += sin((en + sta) / 2 + offset) * r distance = en - sta # how many vertices are needed for the curve? nvertices = max(2, ceil(Int, rad2deg(distance) * vertex_per_deg)) # curve points points = map(LinRange(sta, en, nvertices)) do rad - Point2f(cos(rad + offset), sin(rad + offset)) .* radius + Point2f(cos(rad + offset) * radius + x, sin(rad + offset) * radius + y) end # add inner points (either curve or one point) if inner_radius != 0 inner_points = map(LinRange(en, sta, nvertices)) do rad - Point2f(cos(rad + offset), sin(rad + offset)) .* inner_radius + Point2f(cos(rad + offset) * inner_radius + x, sin(rad + offset) * inner_radius + y) end - append!(points, inner_points) else - push!(points, Point2f(0, 0)) + push!(points, Point2f(x, y)) end points From 0c853653000885829badb618a0f8623a7f2e7cb2 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sat, 13 Jul 2024 23:16:49 +0800 Subject: [PATCH 02/16] docs: add test for pie --- ReferenceTests/src/tests/examples2d.jl | 28 +++++++++++++++++++++++++ docs/src/reference/plots/pie.md | 29 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index e737223e4ea..051d4dcbf7d 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -373,6 +373,34 @@ end pie(0.1:0.1:1.0, normalize=false, axis=(;aspect=DataAspect())) end +@reference_test "Pie Position" begin + fig = Makie.Figure() + ax = Makie.Axis(fig[1, 1]; autolimitaspect=1) + + vs = 0:6 + cs = Makie.wong_colors() + Δx = [1, 1, 1, -1, -1, -1, 1] ./ 10 + Δy = [1, 1, 1, 1, 1, -1, -1] ./ 10 + Δ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, x=0, y=0) + Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=0) + Makie.pie!(ax, vs; color=cs, x=0, y=3 .+ Δy) + Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=3 .+ Δy) + + Makie.pie!(ax, vs; color=cs, x=7, y=0, r=Δr1) + Makie.pie!(ax, vs; color=cs, x=7, y=3, r=0.2) + Makie.pie!(ax, vs; color=cs, x=10 .+ Δx, y=3 .+ Δy, r=0.2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=10, y=0, r=Δr1, normalize=false, offset=π/2) + + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-4, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-4, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) + fig +end + @reference_test "intersecting polygon" begin x = LinRange(0, 2pi, 100) poly(Point2f.(zip(sin.(x), sin.(2x))), color = :white, strokecolor = :blue, strokewidth = 10) diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 05e65348da6..796f698d49a 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -35,6 +35,35 @@ f, ax, plt = pie([π/2, 2π/3, π/4], f ``` +```@figure +fig = Makie.Figure() +ax = Makie.Axis(fig[1, 1]; autolimitaspect=1) + +vs = 0:6 +cs = Makie.wong_colors() +Δx = [1, 1, 1, -1, -1, -1, 1] ./ 10 +Δy = [1, 1, 1, 1, 1, -1, -1] ./ 10 +Δ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, x=0, y=0) +Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=0) +Makie.pie!(ax, vs; color=cs, x=0, y=3 .+ Δy) +Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=3 .+ Δy) + +Makie.pie!(ax, vs; color=cs, x=7, y=0, r=Δr1) +Makie.pie!(ax, vs; color=cs, x=7, y=3, r=0.2) +Makie.pie!(ax, vs; color=cs, x=10 .+ Δx, y=3 .+ Δy, r=0.2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=10, y=0, r=Δr1, normalize=false, offset=π/2) + +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-4, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-4, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) + +fig +``` + ## Attributes ```@attrdocs From 7a188db66355ac2eb610279ca421eb308b2d7dce Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sat, 13 Jul 2024 23:26:40 +0800 Subject: [PATCH 03/16] log: add changes to `pie` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 958c9d22511..d5e13e006aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] - Correct a bug in the `project` function when projecting using a `Scene`. [#3909](https://github.com/MakieOrg/Makie.jl/pull/3909). +- Add position for `pie` plot [#4027](https://github.com/MakieOrg/Makie.jl/pull/4027). ## [0.21.5] - 2024-07-07 From cb973bcf65ebcbbfdcff4e1054bab048d6eba514 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sat, 13 Jul 2024 23:35:26 +0800 Subject: [PATCH 04/16] docs: better `pie` position doc --- ReferenceTests/src/tests/examples2d.jl | 13 +++++++++---- docs/src/reference/plots/pie.md | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index 051d4dcbf7d..cd652deedfa 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -394,10 +394,15 @@ end Makie.pie!(ax, vs; color=cs, x=10 .+ Δx, y=3 .+ Δy, r=0.2) Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=10, y=0, r=Δr1, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-4, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-4, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-3, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-3, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) + + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=0.5, y=-6, r=0.2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=3.5, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=6.5 .+ Δx, y=-6, r=0.2, normalize=false, offset=π/2) + Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=9.5 .+ Δx, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) fig end diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 796f698d49a..aaaa8dbce4a 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -56,10 +56,15 @@ Makie.pie!(ax, vs; color=cs, x=7, y=3, r=0.2) Makie.pie!(ax, vs; color=cs, x=10 .+ Δx, y=3 .+ Δy, r=0.2) Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=10, y=0, r=Δr1, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-4, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-4, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-4 .+ Δy, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-3, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-3, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) + +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=0.5, y=-6, r=0.2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=3.5, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=6.5 .+ Δx, y=-6, r=0.2, normalize=false, offset=π/2) +Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=9.5 .+ Δx, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) fig ``` From 838a172a00b84bee616db7d2161d0def204d0656 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sun, 14 Jul 2024 01:25:01 +0800 Subject: [PATCH 05/16] adjust args of `pie` --- ReferenceTests/src/tests/examples2d.jl | 41 +++++++++++++------------- docs/src/reference/plots/pie.md | 41 +++++++++++++------------- src/basic_recipes/pie.jl | 25 +++++++++------- 3 files changed, 57 insertions(+), 50 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index cd652deedfa..53d800e8f7f 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -377,32 +377,33 @@ end fig = Makie.Figure() ax = Makie.Axis(fig[1, 1]; autolimitaspect=1) - vs = 0:6 + vs = 0:6 |> Vector + vs_ = vs ./ sum(vs) .* (3/2*π) cs = Makie.wong_colors() Δx = [1, 1, 1, -1, -1, -1, 1] ./ 10 Δy = [1, 1, 1, 1, 1, -1, -1] ./ 10 Δ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, x=0, y=0) - Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=0) - Makie.pie!(ax, vs; color=cs, x=0, y=3 .+ Δy) - Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=3 .+ Δy) - - Makie.pie!(ax, vs; color=cs, x=7, y=0, r=Δr1) - Makie.pie!(ax, vs; color=cs, x=7, y=3, r=0.2) - Makie.pie!(ax, vs; color=cs, x=10 .+ Δx, y=3 .+ Δy, r=0.2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=10, y=0, r=Δr1, normalize=false, offset=π/2) - - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-3, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-3, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) - - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=0.5, y=-6, r=0.2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=3.5, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=6.5 .+ Δx, y=-6, r=0.2, normalize=false, offset=π/2) - Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=9.5 .+ Δx, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) + 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, r=Δr1) + Makie.pie!(ax, 7, 3, vs; color=cs, r=0.2) + Makie.pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, r=0.2) + Makie.pie!(ax, 10, 0, vs_; color=cs, r=Δr1, normalize=false, offset=π/2) + + Makie.pie!(ax, 0.5, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, 9.5 .+ Δx, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) + + Makie.pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) + Makie.pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) + Makie.pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) + Makie.pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) fig end diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index aaaa8dbce4a..299dc353c7d 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -39,32 +39,33 @@ f fig = Makie.Figure() ax = Makie.Axis(fig[1, 1]; autolimitaspect=1) -vs = 0:6 +vs = 0:6 |> Vector +vs_ = vs ./ sum(vs) .* (3/2*π) cs = Makie.wong_colors() Δx = [1, 1, 1, -1, -1, -1, 1] ./ 10 Δy = [1, 1, 1, 1, 1, -1, -1] ./ 10 Δ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, x=0, y=0) -Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=0) -Makie.pie!(ax, vs; color=cs, x=0, y=3 .+ Δy) -Makie.pie!(ax, vs; color=cs, x=3 .+ Δx, y=3 .+ Δy) - -Makie.pie!(ax, vs; color=cs, x=7, y=0, r=Δr1) -Makie.pie!(ax, vs; color=cs, x=7, y=3, r=0.2) -Makie.pie!(ax, vs; color=cs, x=10 .+ Δx, y=3 .+ Δy, r=0.2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=10, y=0, r=Δr1, normalize=false, offset=π/2) - -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=0.5, y=-3, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=3.5, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=6.5 .+ Δx, y=-3, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); color=cs, x=9.5 .+ Δx, y=-3 .+ Δy, r=Δr2, normalize=false, offset=π/2) - -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=0.5, y=-6, r=0.2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=3.5, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=6.5 .+ Δx, y=-6, r=0.2, normalize=false, offset=π/2) -Makie.pie!(ax, vs ./ sum(vs) .* (3/2*π); inner_radius=0.2, color=cs, x=9.5 .+ Δx, y=-6 .+ Δy, r=0.2, normalize=false, offset=π/2) +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, r=Δr1) +Makie.pie!(ax, 7, 3, vs; color=cs, r=0.2) +Makie.pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, r=0.2) +Makie.pie!(ax, 10, 0, vs_; color=cs, r=Δr1, normalize=false, offset=π/2) + +Makie.pie!(ax, 0.5, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, 9.5 .+ Δx, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) + +Makie.pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) +Makie.pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) +Makie.pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) +Makie.pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) fig ``` diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index c7e716a0fa0..1babd8bbbee 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -1,9 +1,10 @@ """ pie(values; kwargs...) + pie(x, y, values; kwargs...) Creates a pie chart from the given `values`. """ -@recipe Pie (values,) begin +@recipe Pie (points,) begin "If `true`, the sum of all values is normalized to 2π (a full circle)." normalize = true color = :gray @@ -17,23 +18,27 @@ Creates a pie chart from the given `values`. inner_radius = 0 "The angular offset of the first pie segment from the (1, 0) vector in radians." offset = 0 - "Position of pie segments (x-value, scalar or `length(values)` vector)" - x = 0 - "Position of pie segments (y-value, scalar or `length(values)` vector)" - y = 0 "Position of pie segments (r-value as polar coordinate, scalar or `length(values)` vector)" r = 0 MakieCore.mixin_generic_plot_attributes()... end -function plot!(plot::Pie) +conversion_trait(::Type{<:Pie}) = PointBased() +convert_arguments(::Type{<:Pie}, values::Vector) = (Point3d.(0, 0, getindex.(values, 1)),) +convert_arguments(::Type{<:Pie}, xs, ys, values::Vector) = begin + xs = length(xs) == 1 ? fill(only(xs), length(values)) : xs + ys = length(ys) == 1 ? fill(only(ys), length(values)) : ys + return (Point3d.(xs, ys, values),) +end +function plot!(plot::Pie) values = plot[1] - polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize, plot.x, plot.y, plot.r) do vals, vertex_per_deg, radius, inner_radius, offset, normalize, x, y, r - xs = length(x) == 1 ? fill(only(x), length(vals)) : x - ys = length(y) == 1 ? fill(only(y), length(vals)) : y - rs = length(r) == 1 ? fill(only(r), length(vals)) : r + polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize, plot.r) do vals, vertex_per_deg, radius, inner_radius, offset, normalize, rs + xs = getindex.(vals, 1) + ys = getindex.(vals, 2) + vals = getindex.(vals, 3) + rs = length(rs) == 1 ? fill(only(rs), length(vals)) : rs T = eltype(vals) From f66fff17e33c32bd07102f3fbac32a6a9d620bb9 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sun, 14 Jul 2024 01:40:56 +0800 Subject: [PATCH 06/16] rename `r` of `pie` to `offset_radius` --- ReferenceTests/src/tests/examples2d.jl | 29 +++++++++++++------------- docs/src/reference/plots/pie.md | 28 ++++++++++++------------- src/basic_recipes/pie.jl | 6 +++--- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index 53d800e8f7f..abccc6a1be0 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -390,20 +390,21 @@ end 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, r=Δr1) - Makie.pie!(ax, 7, 3, vs; color=cs, r=0.2) - Makie.pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, r=0.2) - Makie.pie!(ax, 10, 0, vs_; color=cs, r=Δr1, normalize=false, offset=π/2) - - Makie.pie!(ax, 0.5, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, 9.5 .+ Δx, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) - - Makie.pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) - Makie.pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) - Makie.pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) - Makie.pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) + 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, 0.5, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) + Makie.pie!(ax, 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) + fig end diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 299dc353c7d..2c68fa6a6ae 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -52,20 +52,20 @@ 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, r=Δr1) -Makie.pie!(ax, 7, 3, vs; color=cs, r=0.2) -Makie.pie!(ax, 10 .+ Δx, 3 .+ Δy, vs; color=cs, r=0.2) -Makie.pie!(ax, 10, 0, vs_; color=cs, r=Δr1, normalize=false, offset=π/2) - -Makie.pie!(ax, 0.5, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, 9.5 .+ Δx, -3 .+ Δy, vs_; color=cs, r=Δr2, normalize=false, offset=π/2) - -Makie.pie!(ax, 0.5, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) -Makie.pie!(ax, 3.5, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) -Makie.pie!(ax, 6.5 .+ Δx, -6, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) -Makie.pie!(ax, 9.5 .+ Δx, -6 .+ Δy, vs_; inner_radius=0.2, color=cs, r=0.2, normalize=false, offset=π/2) +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, 0.5, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) +Makie.pie!(ax, 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) fig ``` diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index 1babd8bbbee..2275de40159 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -18,8 +18,8 @@ Creates a pie chart from the given `values`. inner_radius = 0 "The angular offset of the first pie segment from the (1, 0) vector in radians." offset = 0 - "Position of pie segments (r-value as polar coordinate, scalar or `length(values)` vector)" - r = 0 + "The offset of each pie segment from the center along the radius" + offset_radius = 0 MakieCore.mixin_generic_plot_attributes()... end @@ -34,7 +34,7 @@ end function plot!(plot::Pie) values = plot[1] - polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize, plot.r) do vals, vertex_per_deg, radius, inner_radius, offset, normalize, rs + polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize, plot.offset_radius) do vals, vertex_per_deg, radius, inner_radius, offset, normalize, rs xs = getindex.(vals, 1) ys = getindex.(vals, 2) vals = getindex.(vals, 3) From 400742788525253ae72d4540a5fdab3e3e9e33c2 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sun, 14 Jul 2024 01:59:10 +0800 Subject: [PATCH 07/16] adjust code --- src/basic_recipes/pie.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index 2275de40159..ac7d22691e7 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -34,11 +34,11 @@ end function plot!(plot::Pie) values = plot[1] - polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize, plot.offset_radius) do vals, vertex_per_deg, radius, inner_radius, offset, normalize, rs + polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset_radius, plot.offset, plot.normalize) do vals, vertex_per_deg, radius, inner_radius, offset_radius, offset, normalize xs = getindex.(vals, 1) ys = getindex.(vals, 2) vals = getindex.(vals, 3) - rs = length(rs) == 1 ? fill(only(rs), length(vals)) : rs + offset_radius = length(offset_radius) == 1 ? fill(only(offset_radius), length(vals)) : offset_radius T = eltype(vals) @@ -51,7 +51,7 @@ function plot!(plot::Pie) end # create vector of a vector of points for each piece - vertex_arrays = map(boundaries[1:end-1], boundaries[2:end], xs, ys, rs) do sta, en, x, y, r + vertex_arrays = map(boundaries[1:end-1], boundaries[2:end], xs, ys, offset_radius) do sta, en, x, y, r x += cos((en + sta) / 2 + offset) * r y += sin((en + sta) / 2 + offset) * r distance = en - sta From 754c5026b36b45224c7d6f5efc2b342a2df21c8e Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sun, 14 Jul 2024 02:50:12 +0800 Subject: [PATCH 08/16] fix `convert_arguments` of `pie` --- src/basic_recipes/pie.jl | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index ac7d22691e7..88716c1d1c5 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -1,10 +1,11 @@ """ pie(values; kwargs...) + pie(point, values; kwargs...) pie(x, y, values; kwargs...) Creates a pie chart from the given `values`. """ -@recipe Pie (points,) begin +@recipe Pie (xs, ys, values) begin "If `true`, the sum of all values is normalized to 2π (a full circle)." normalize = true color = :gray @@ -23,21 +24,19 @@ Creates a pie chart from the given `values`. MakieCore.mixin_generic_plot_attributes()... end -conversion_trait(::Type{<:Pie}) = PointBased() -convert_arguments(::Type{<:Pie}, values::Vector) = (Point3d.(0, 0, getindex.(values, 1)),) -convert_arguments(::Type{<:Pie}, xs, ys, values::Vector) = begin - xs = length(xs) == 1 ? fill(only(xs), length(values)) : xs - ys = length(ys) == 1 ? fill(only(ys), length(values)) : ys - return (Point3d.(xs, ys, values),) -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) function plot!(plot::Pie) - values = plot[1] + xs = plot[1] + ys = plot[2] + values = plot[3] - polys = lift(plot, values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset_radius, plot.offset, plot.normalize) do vals, vertex_per_deg, radius, inner_radius, offset_radius, offset, normalize - xs = getindex.(vals, 1) - ys = getindex.(vals, 2) - vals = getindex.(vals, 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) From 18dd831ecc70dbd2e512644ee1edd5bb94986e3e Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sun, 14 Jul 2024 02:56:42 +0800 Subject: [PATCH 09/16] docs: use `Point2` for `pie` --- ReferenceTests/src/tests/examples2d.jl | 8 ++++---- docs/src/reference/plots/pie.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index abccc6a1be0..a2b5ccd2ae4 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -395,10 +395,10 @@ end 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, 0.5, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) - Makie.pie!(ax, 9.5 .+ Δx, -3 .+ Δy, vs_; color=cs, offset_radius=Δr2, 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) diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 2c68fa6a6ae..5099edb8502 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -57,10 +57,10 @@ 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, 0.5, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, 3.5, -3 .+ Δy, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, 6.5 .+ Δx, -3, vs_; color=cs, offset_radius=Δr2, normalize=false, offset=π/2) -Makie.pie!(ax, 9.5 .+ Δx, -3 .+ Δy, vs_; color=cs, offset_radius=Δr2, 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) From 4785dc03542a24905730b6a1a0b52fa44630af8f Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sun, 14 Jul 2024 03:01:28 +0800 Subject: [PATCH 10/16] allow segment-specific radius for `pie` --- src/basic_recipes/pie.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index 88716c1d1c5..432f084bd21 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -37,6 +37,8 @@ function plot!(plot::Pie) 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 T = eltype(vals) @@ -50,22 +52,22 @@ function plot!(plot::Pie) end # create vector of a vector of points for each piece - vertex_arrays = map(boundaries[1:end-1], boundaries[2:end], xs, ys, offset_radius) do sta, en, x, y, r - x += cos((en + sta) / 2 + offset) * r - y += sin((en + sta) / 2 + offset) * r + vertex_arrays = map(boundaries[1:end-1], boundaries[2:end], xs, ys, radius, inner_radius, offset_radius) do sta, en, x, y, r, inner_r, offset_r + x += cos((en + sta) / 2 + offset) * offset_r + y += sin((en + sta) / 2 + offset) * offset_r distance = en - sta # how many vertices are needed for the curve? nvertices = max(2, ceil(Int, rad2deg(distance) * vertex_per_deg)) # curve points points = map(LinRange(sta, en, nvertices)) do rad - Point2f(cos(rad + offset) * radius + x, sin(rad + offset) * radius + y) + Point2f(cos(rad + offset) * r + x, sin(rad + offset) * r + y) end # add inner points (either curve or one point) - if inner_radius != 0 + if inner_r != 0 inner_points = map(LinRange(en, sta, nvertices)) do rad - Point2f(cos(rad + offset) * inner_radius + x, sin(rad + offset) * inner_radius + y) + Point2f(cos(rad + offset) * inner_r + x, sin(rad + offset) * inner_r + y) end append!(points, inner_points) else From 84548cc2d5a7bd00bd88f454a26185eae29ac626 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sun, 14 Jul 2024 04:15:34 +0800 Subject: [PATCH 11/16] update doc, test, and changelog --- CHANGELOG.md | 1 + ReferenceTests/src/tests/examples2d.jl | 21 +++++++++++++++++++++ docs/src/reference/plots/pie.md | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5e13e006aa..09bea646227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Correct a bug in the `project` function when projecting using a `Scene`. [#3909](https://github.com/MakieOrg/Makie.jl/pull/3909). - Add position for `pie` plot [#4027](https://github.com/MakieOrg/Makie.jl/pull/4027). +- Allow segment-specific radius for `pie` plot [#4028](https://github.com/MakieOrg/Makie.jl/pull/4028). ## [0.21.5] - 2024-07-07 diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index a2b5ccd2ae4..c16b406e224 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -373,6 +373,27 @@ end pie(0.1:0.1:1.0, normalize=false, axis=(;aspect=DataAspect())) end +@reference_test "Pie with Segment-specific Radius" begin + fig = Makie.Figure() + ax = Makie.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]) + + vs = [2, 3, 4, 5, 6, 7, 8] + vs_inner = [1, 1, 1, 1, 2, 2, 2] + rs = 8 + 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)]) + + display(fig) +end + @reference_test "Pie Position" begin fig = Makie.Figure() ax = Makie.Axis(fig[1, 1]; autolimitaspect=1) diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 5099edb8502..205271b2f13 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -35,6 +35,29 @@ f, ax, plt = pie([π/2, 2π/3, π/4], f ``` +```@figure +import Makie, CairoMakie + +fig = Makie.Figure() +ax = Makie.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]) + +vs = [2, 3, 4, 5, 6, 7, 8] +vs_inner = [1, 1, 1, 1, 2, 2, 2] +rs = 8 +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)]) + +display(fig) +``` + ```@figure fig = Makie.Figure() ax = Makie.Axis(fig[1, 1]; autolimitaspect=1) From 1f84aba87ae0bc49e4eb1a00d5510f24e8959335 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Mon, 15 Jul 2024 16:51:39 +0800 Subject: [PATCH 12/16] sync --- ReferenceTests/src/tests/examples2d.jl | 54 ++++++++++++------------- docs/src/reference/plots/pie.md | 56 +++++++++++++------------- src/basic_recipes/pie.jl | 20 ++++----- 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index c16b406e224..73fd089249b 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -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] @@ -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*π) @@ -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 diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 205271b2f13..13b8dd8b52f 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -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] @@ -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*π) @@ -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 ``` diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index 432f084bd21..e67bec17072 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -24,10 +24,14 @@ 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] @@ -35,8 +39,6 @@ function plot!(plot::Pie) 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 @@ -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 From a45075a0fec96f103df68d849d7a7a5210f4d1c6 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Mon, 15 Jul 2024 17:01:21 +0800 Subject: [PATCH 13/16] adjust pie example --- ReferenceTests/src/tests/examples2d.jl | 4 ++-- docs/src/reference/plots/pie.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index 73fd089249b..0ccb3eb14c5 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -385,9 +385,9 @@ end rs = 8 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) + lp = Makie.LinePattern(; direction=Makie.Vec2f(1, -1), width=2, tilesize=(12, 12), linecolor=:darkgrey, background_color=:transparent) # draw the inner pie twice since `color` can not be vector of `LinePattern` currently - 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=Makie.wong_colors(0.4)[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)]) diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 13b8dd8b52f..4e1ae8ede7d 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -47,9 +47,9 @@ vs_inner = [1, 1, 1, 1, 2, 2, 2] rs = 8 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) +lp = Makie.LinePattern(; direction=Makie.Vec2f(1, -1), width=2, tilesize=(12, 12), linecolor=:darkgrey, background_color=:transparent) # draw the inner pie twice since `color` can not be vector of `LinePattern` currently -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=Makie.wong_colors(0.4)[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)]) From 921f67d25789a99192e34136a9b25c6b6e040ffb Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Tue, 16 Jul 2024 23:29:15 +0800 Subject: [PATCH 14/16] sync --- src/basic_recipes/pie.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/basic_recipes/pie.jl b/src/basic_recipes/pie.jl index e67bec17072..0e202a85f2d 100644 --- a/src/basic_recipes/pie.jl +++ b/src/basic_recipes/pie.jl @@ -27,7 +27,8 @@ end 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 + +function convert_arguments(::Type{<:Pie}, xs::Union{Real,RealVector}, ys::Union{Real,RealVector}, values::RealVector) 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)) From 644d1a5c942f6f775f4da0e06568a82f9a463a90 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Sat, 17 Aug 2024 15:40:28 +0800 Subject: [PATCH 15/16] fix test --- ReferenceTests/src/tests/examples2d.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index 76f2eb86ff4..25b815ce773 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -391,7 +391,7 @@ end 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) + fig end @reference_test "Pie Position" begin From f4f01ec012e8d31c59d47fafd7453b83517e21e4 Mon Sep 17 00:00:00 2001 From: Tarn Yeong Ching Date: Thu, 29 Aug 2024 21:20:11 +0800 Subject: [PATCH 16/16] fix test --- docs/src/reference/plots/pie.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/reference/plots/pie.md b/docs/src/reference/plots/pie.md index 4e1ae8ede7d..817ee893afd 100644 --- a/docs/src/reference/plots/pie.md +++ b/docs/src/reference/plots/pie.md @@ -53,7 +53,7 @@ pie!(ax, 20, 0, vs; radius=rs_inner, inner_radius=0, kw..., color=Makie.wong_col 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) +fig ``` ```@figure