You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm helping on the development of a plotting library and I came up with the following recipe to plot "wedges"/regions/polygons (not sure how to name it) inspired in the likes of vspan and hspan:
function polarpoly endfunction polarpoly! end
Makie.@recipe(PolarPoly, r_min, r_max, theta_min, theta_max) do scene
Makie.Attributes(
alpha =@something(Makie.theme(scene, :alpha), 0.5),
color =@something(Makie.theme(scene, :color), :blue),
resolution =1.0,
)
endfunction Makie.plot!(plt::PolarPoly)
# Check if inputs are correct@assertlength(plt.r_min[]) ==length(plt.r_max[]) ==length(plt.theta_min[]) ==length(plt.theta_max[]) "Mismatch between number of values for polygon"# Allow user to give multiple colors as input# NOTE: This is implemented like this due to CairoMakie not respecting the `alpha`# parameter. Refer to https://github.com/MakieOrg/Makie.jl/issues/4614 for more# informationiftypeof(plt.color[]) == Symbol
plt.color[] =fill((plt.color[], plt.alpha[]), length(plt.r_min[]))
elseiftypeof(plt.color[]) == Tuple{Any,AbstractFloat}
plt.color[] =fill((first(plt.color[]), last(plt.color[]) * plt.alpha[]), length(plt.r_min[]))
else
c_array =Vector(undef, length(plt.color[]))
for (i, c) inenumerate(plt.color[])
iftypeof(c) == Tuple{Any,AbstractFloat}
c_array[i] = (first(c), last(c) * plt.alpha[])
else
c_array[i] = (c, plt.alpha[])
endend
plt.color[] = c_array
end@assertlength(plt.color[]) ==length(plt.r_min[]) "Mismatch between number of values and colors"for (i, (r_min, r_max, theta_min, theta_max)) inenumerate(zip(plt.r_min[], plt.r_max[], plt.theta_min[], plt.theta_max[]))
# Compute curved segments to connect
segments_theta =range(
theta_min,
theta_max,
length =trunc(Int, abs(rad2deg(theta_min - theta_max)) * plt.resolution[])
)
r_min =fill(r_min, length(segments_theta))
r_max =fill(r_max, length(segments_theta))
# Convert polar coordinates to cartesian
x_inner =@. r_min *cos(segments_theta)
y_inner =@. r_min *sin(segments_theta)
x_outer =@. r_max *cos(segments_theta)
y_outer =@. r_max *sin(segments_theta)
# Combine points to form a closed polygon
x =vcat(x_inner, reverse(x_outer), x_inner[1])
y =vcat(y_inner, reverse(y_outer), y_inner[1])
poly!(plt, Point2f.(zip(x, y)), alpha = plt.alpha[]; color=plt.color[][i])
endend
The issue is, I'm unsure how to create the PR to add this, or if this is even neccesary or already implemented (from my search through the documentation and code base, I found nothing like this).
The text was updated successfully, but these errors were encountered:
I'm helping on the development of a plotting library and I came up with the following recipe to plot "wedges"/regions/polygons (not sure how to name it) inspired in the likes of
vspan
andhspan
:Example:
The issue is, I'm unsure how to create the PR to add this, or if this is even neccesary or already implemented (from my search through the documentation and code base, I found nothing like this).
The text was updated successfully, but these errors were encountered: