Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support vec markersize #30

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/algorithms/jitter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ function calculate!(buffer::AbstractVector{<: Point2}, alg::JitterAlgorithm, pos
ys = last.(positions)
for x_val in unique(xs)
group = xs .== x_val
@views buffer[group] .= Point2f.(xs[group] .+ create_jitter_array(ys[group], alg) .* markersize, ys[group])
ms = if markersize isa Number
markersize
else
view(markersize, group)
end
@views buffer[group] .= Point2f.(xs[group] .+ create_jitter_array(ys[group], alg) .* ms, ys[group])
end
end

Expand Down Expand Up @@ -121,4 +126,4 @@ function create_jitter_array(data_array, jitter_type = UniformJitter())
jitter = jitter * (0.5jitter_width / clamp_max)

return jitter
end
end
11 changes: 8 additions & 3 deletions src/algorithms/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ function calculate!(buffer::AbstractVector{<: Point2}, alg::SimpleBeeswarm, posi
@debug "Calculating..."
ys = last.(positions)
xs = first.(positions)

for x_val in unique(xs)
group = findall(==(x_val), xs)
view_ys = view(ys, group)
if isempty(view_ys)
continue
else
xs[group] .= simple_xs(view_ys, markersize, side)
ms = if markersize isa Number
markersize
else
view_ms = view(markersize, group)
maximum(view_ms)
end
xs[group] .= simple_xs(view_ys, ms, side)
end
end

Expand Down Expand Up @@ -99,4 +104,4 @@ function simple_xs(ys, markersize, side)
end
end
return xs
end
end
10 changes: 8 additions & 2 deletions src/algorithms/wilkinson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ function calculate!(buffer::AbstractVector{<: Point2}, alg::WilkinsonBeeswarm, p
## the beeswarm for each group.
for x_val in unique(xs)
group = findall(==(x_val), xs)
wilkinson_kernel!(view(buffer, group), view(positions, group), markersize, side)
ms = if markersize isa Number
markersize
else
view_ms = view(markersize, group)
maximum(view_ms)
end
wilkinson_kernel!(view(buffer, group), view(positions, group), ms, side)
end

end
Expand Down Expand Up @@ -144,4 +150,4 @@ We force the points to dodge each other by `markersize`.
buffer[idxs_by_position] .= Point2f.(((1:length(idxs_by_position))) .* (-markersize) .+ markersize/2 .+ first.(view(positions, idxs_by_position)), current_y)
end
end
end
end
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ buffer = deepcopy(pixel_points)
Makie.update_state_before_display!(f)
@test_nowarn p.gutter = 0.5
end
@testset "Vector markersizes" begin
# First, we test the regular gutter with multiple categories.
xs = rand(1:3, 300)
for algorithm in [NoBeeswarm(), SimpleBeeswarm(), WilkinsonBeeswarm(), UniformJitter(), PseudorandomJitter(), QuasirandomJitter()]
f, a, p = beeswarm(xs, randn(300); color = rand(RGBAf, 300), markersize = xs*2, algorithm)
Makie.update_state_before_display!(f)
end
end
end

# TODO:
Expand Down