Skip to content

Commit

Permalink
Fix AoG (#24)
Browse files Browse the repository at this point in the history
* Update scales.md

* add all aesthetics

* Update AlgebraOfGraphicsExt.jl

* Add a legend elements definition, lifted from scatter
  • Loading branch information
asinghvi17 authored Sep 12, 2024
1 parent 9a557da commit 60bd12e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples/scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Beeswarm plots can be plotted in any combination of `xscale` and `yscale`.
Specifically, beeswarm plots are correct in any [separable transform](https://geo.makie.org/stable/nonlinear_transforms/#Nonlinear-but-separable) - basically, any transform in which the x and y coordinates are independent of each other. This excludes most geographic transformations, but includes any transformation you can make using `xscale` and `yscale` in a Makie `Axis`.

```@figure logscale
using SwarmMakie, Makie
using SwarmMakie, CairoMakie
data = randn(75) .+ 3
fig = Figure()
ax1 = Axis(fig[1, 1]; title = "No transform")
Expand Down
32 changes: 23 additions & 9 deletions ext/AlgebraOfGraphicsExt.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
module AlgebraOfGraphicsExt
using SwarmMakie, AlgebraOfGraphics
import AlgebraOfGraphics: Normal, dictionary, AesColor, AesX, AesY

function AlgebraOfGraphics.aesthetic_mapping(::Type{Beeswarm}, ::Normal, ::Normal)
dictionary([
1 => AesX,
2 => AesY,
:color => AesColor,
using SwarmMakie, AlgebraOfGraphics, Makie
import AlgebraOfGraphics as AOG

function AlgebraOfGraphics.aesthetic_mapping(::Type{Beeswarm}, ::AOG.Normal, ::AOG.Normal)
AOG.dictionary([
1 => AOG.AesX,
2 => AOG.AesY,
:color => AOG.AesColor,
:marker => AOG.AesMarker,
:markersize => AOG.AesMarkerSize,
])
end

end

function AOG.legend_elements(T::Type{Beeswarm}, attributes, scale_args::AOG.MixedArguments)
[Makie.MarkerElement(
color = AOG._get(T, scale_args, attributes, :color),
markerpoints = [Point2f(0.5, 0.5)],
marker = AOG._get(T, scale_args, attributes, :marker),
markerstrokewidth = AOG._get(T, scale_args, attributes, :strokewidth),
markersize = AOG._get(T, scale_args, attributes, :markersize),
markerstrokecolor = AOG._get(T, scale_args, attributes, :strokecolor),
)]
end

end

0 comments on commit 60bd12e

Please sign in to comment.