Skip to content

Commit

Permalink
implement review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub committed Jan 30, 2025
1 parent 60cb12c commit 84e51d6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/transformations/histogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions test/reference_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified test/reference_tests/histogram scatter cat color ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/reference_tests/histogram stairs cat color ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 84e51d6

Please sign in to comment.