diff --git a/src/transformations/histogram.jl b/src/transformations/histogram.jl index aacb88454..5294d60e0 100644 --- a/src/transformations/histogram.jl +++ b/src/transformations/histogram.jl @@ -39,15 +39,17 @@ Base.@kwdef struct HistogramAnalysis{D, B} bins::B=automatic closed::Symbol=:left normalization::Symbol=:none + visual::Union{typeof(automatic), Layer}=automatic end function (h::HistogramAnalysis)(input::ProcessedLayer) datalimits = h.datalimits === automatic ? defaultdatalimits(input.positional) : h.datalimits options = valid_options(; datalimits, h.bins, h.closed, h.normalization) + visual = h.visual N = length(input.positional) default_plottype = categoricalplottypes[N] - plottype = Makie.plottype(input.plottype, default_plottype) + plottype = Makie.plottype(input.plottype, visual === automatic ? default_plottype : (visual.transformation::Visual).plottype) output = map(input) do p, n hist = _histogram(Tuple(p); pairs(n)..., pairs(options)...) @@ -68,16 +70,18 @@ function (h::HistogramAnalysis)(input::ProcessedLayer) label = h.normalization == :none ? "count" : string(h.normalization) labels = set(output.labels, N+1 => label) - attributes = if plottype == BarPlot - set(output.attributes, :gap => 0, :dodge_gap => 0) - else - output.attributes + attributes = output.attributes + if plottype == BarPlot + attributes = set(attributes, :gap => 0, :dodge_gap => 0) + end + if visual !== automatic + attributes = merge(attributes, (visual.transformation::Visual).attributes) end return ProcessedLayer(output; plottype, labels, attributes) end """ - histogram(; bins=automatic, datalimits=automatic, closed=:left, normalization=:none) + histogram(; bins=automatic, datalimits=automatic, closed=:left, normalization=:none, visual=automatic) Compute a histogram. diff --git a/test/reference_tests.jl b/test/reference_tests.jl index fb2492357..dd3282b28 100644 --- a/test/reference_tests.jl +++ b/test/reference_tests.jl @@ -246,13 +246,13 @@ end reftest("histogram stairs cat color") do df = (x=[sin.(1:500); sin.(1:500) .* 2], z=repeat(["a", "b"], inner = 500)) - specs = data(df) * mapping(:x, layout=:z, color = :z) * visual(Stairs) * histogram() + specs = data(df) * mapping(:x, layout=:z, color = :z) * histogram(; visual = visual(Stairs; alpha = 0.8, linewidth = 4)) draw(specs) end reftest("histogram scatter cat color") do df = (x=[sin.(1:500); sin.(1:500) .* 2], z=repeat(["a", "b"], inner = 500)) - specs = data(df) * mapping(:x, layout=:z, color = :z) * visual(Scatter) * histogram() + specs = data(df) * mapping(:x, layout=:z, color = :z) * histogram(visual = visual(Scatter; alpha = 0.8, marker = :cross, markersize = 20)) draw(specs) end diff --git a/test/reference_tests/histogram scatter cat color ref.png b/test/reference_tests/histogram scatter cat color ref.png index 9d0da343c..733ac4f9f 100644 Binary files a/test/reference_tests/histogram scatter cat color ref.png and b/test/reference_tests/histogram scatter cat color ref.png differ diff --git a/test/reference_tests/histogram stairs cat color ref.png b/test/reference_tests/histogram stairs cat color ref.png index 5a80979b7..1dbce5696 100644 Binary files a/test/reference_tests/histogram stairs cat color ref.png and b/test/reference_tests/histogram stairs cat color ref.png differ