From 31941d95cb1df8ebbed6234be40fdcbe79c14462 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Sun, 8 Nov 2020 19:20:18 +0100 Subject: [PATCH] minor analysis rework (#110) * add extra entry point in analysis * remove unnecessary mapping * switch order * fix docs * bump CairoMakie for docs * bump patch number --- Project.toml | 2 +- docs/Project.toml | 2 +- docs/make.jl | 2 +- docs/src/generated/internals.jl | 2 +- docs/src/generated/statistics.jl | 4 ++-- docs/src/generated/tutorial.jl | 2 +- src/specs.jl | 12 ++++++++---- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Project.toml b/Project.toml index 4f64852d6..a4756f8ff 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AlgebraOfGraphics" uuid = "cbdf2221-f076-402e-a563-3d30da359d67" authors = ["Pietro Vertechi "] -version = "0.2.0" +version = "0.2.1" [deps] AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e" diff --git a/docs/Project.toml b/docs/Project.toml index 4998a06a8..f27535b68 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,4 @@ [deps] -AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e" CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" @@ -8,6 +7,7 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b" [compat] +CairoMakie = "0.3.6" Documenter = "0.25" Glob = "1" Literate = "2" diff --git a/docs/make.jl b/docs/make.jl index 346991648..d63e33e77 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,6 +1,6 @@ using Documenter, AlgebraOfGraphics, Literate, Glob # avoid font caching warning in docs -using AbstractPlotting, CairoMakie +using CairoMakie CairoMakie.activate!() scatter(rand(10), rand(10)) diff --git a/docs/src/generated/internals.jl b/docs/src/generated/internals.jl index f7c5c122e..a9263fbe6 100644 --- a/docs/src/generated/internals.jl +++ b/docs/src/generated/internals.jl @@ -30,7 +30,7 @@ pairs(d) # All outputs of `mapping`, `data`, and `dims` inherit can be combined using `+` # (adding a new layer), or `*` (merge information in existing layer). -using AbstractPlotting, CairoMakie +using CairoMakie mpg1 = copy(mpg) mpg1.Displ = mpg.Displ .* 0.1 ts = data(mpg) * visual(markersize = 5) + data(mpg1) * visual(markersize=10) diff --git a/docs/src/generated/statistics.jl b/docs/src/generated/statistics.jl index a4f1d6d0d..661f4a238 100644 --- a/docs/src/generated/statistics.jl +++ b/docs/src/generated/statistics.jl @@ -8,7 +8,7 @@ # ## Examples #src using RDatasets: dataset -#src using AlgebraOfGraphics, AbstractPlotting, CairoMakie +#src using AlgebraOfGraphics, CairoMakie #src mpg = dataset("ggplot2", "mpg"); #src data(mpg) * mapping(:Displ, :Hwy, layout_x = ) * visual(QQPlot) |> draw #src AbstractPlotting.save("qqplot.svg", AbstractPlotting.current_scene()); nothing #hide @@ -17,7 +17,7 @@ #src Needs https://github.com/JuliaStats/Distributions.jl/issues/1196 to work. using RDatasets: dataset -using AlgebraOfGraphics, AbstractPlotting, CairoMakie +using AlgebraOfGraphics, CairoMakie mpg = dataset("ggplot2", "mpg"); mpg.IsAudi = mpg.Manufacturer .== "audi" geom = visual(BoxPlot, layout_x = 1) + visual(Violin, layout_x = 2) diff --git a/docs/src/generated/tutorial.jl b/docs/src/generated/tutorial.jl index eec457643..fe20d61c5 100644 --- a/docs/src/generated/tutorial.jl +++ b/docs/src/generated/tutorial.jl @@ -37,7 +37,7 @@ # ## Working with tables using RDatasets: dataset -using AlgebraOfGraphics, AbstractPlotting, CairoMakie +using AlgebraOfGraphics, CairoMakie mpg = dataset("ggplot2", "mpg"); cols = mapping(:Displ, :Hwy); grp = mapping(color = :Cyl => categorical); diff --git a/src/specs.jl b/src/specs.jl index 2ed97bdd7..fcaec6dc0 100644 --- a/src/specs.jl +++ b/src/specs.jl @@ -50,15 +50,19 @@ end global_options(f, d::AlgebraicList) = NamedTuple() +function compute(f, layer, precomputed_attributes) + args, kwargs = split(layer.mapping.value) + return f(args...; precomputed_attributes..., kwargs...) +end + # default fallback to apply a callable to a vector of key => value pairs # if customized, it must return a vector of key => value pairs function apply(f, d::AlgebraicList) - global_kwargs = global_options(f, d) + precomputed_attributes = global_options(f, d) v = map(parent(d)) do layer - analyses, pkeys, mapping, options = layer.analyses, layer.pkeys, layer.mapping, layer.options + analyses, pkeys, options = layer.analyses, layer.pkeys, layer.options T = plottype(layer) - args, kwargs = split(mapping.value) - res = f(args...; global_kwargs..., kwargs...) * Spec{T}(analyses=analyses, options=options, pkeys=pkeys) + res = compute(f, layer, precomputed_attributes) * Spec{T}(analyses=analyses, options=options, pkeys=pkeys) return parent(layers(res)) end return AlgebraicList(reduce(vcat, v))