From 60bd12eab666b3c7e498690438c615b82d12b7d7 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 12 Sep 2024 15:51:42 -0700 Subject: [PATCH] Fix AoG (#24) * Update scales.md * add all aesthetics * Update AlgebraOfGraphicsExt.jl * Add a legend elements definition, lifted from scatter --- docs/src/examples/scales.md | 2 +- ext/AlgebraOfGraphicsExt.jl | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/docs/src/examples/scales.md b/docs/src/examples/scales.md index 5b514b7..dd6a475 100644 --- a/docs/src/examples/scales.md +++ b/docs/src/examples/scales.md @@ -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") diff --git a/ext/AlgebraOfGraphicsExt.jl b/ext/AlgebraOfGraphicsExt.jl index f3ddd4f..70e3281 100644 --- a/ext/AlgebraOfGraphicsExt.jl +++ b/ext/AlgebraOfGraphicsExt.jl @@ -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 \ No newline at end of file + +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