Skip to content
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Support `Waterfall` plot type #583

## v0.8.13 - 2024-10-21

- Added aesthetics for `Stairs` [#573](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/573).
Expand Down
19 changes: 18 additions & 1 deletion src/aesthetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ function aesthetic_mapping(::Type{BarPlot}, N::Int)
])
end

aesthetic_mapping(::Type{Waterfall}, ::Normal) = aesthetic_mapping(Waterfall, 1)
aesthetic_mapping(::Type{Waterfall}, ::Normal, ::Normal) = aesthetic_mapping(Waterfall, 2)
function aesthetic_mapping(::Type{Waterfall}, N::Int)
@assert 1 <= N <= 2
positionals = if N == 1
[1 => AesY]
elseif N == 2
[1 => AesX, 2 => AesY]
end
dictionary([
positionals...,
:color => AesColor,
:width => AesDeltaX,
:dodge => AesDodgeX,
])
end

function aesthetic_mapping(::Type{Violin}, ::Normal, ::Normal)
dictionary([
1 => :orientation => dictionary([
Expand Down Expand Up @@ -461,4 +478,4 @@ function aesthetic_mapping(::Type{Stairs}, N::Int)
:color => AesColor,
:linestyle => AesLineStyle,
])
end
end
6 changes: 6 additions & 0 deletions src/guides/legend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ function legend_elements(T::Type{<:Union{BarPlot,Violin,BoxPlot,Choropleth,Poly,
)]
end

function legend_elements(T::Type{Waterfall}, attributes, scale_args::MixedArguments)
[PolyElement(
color = _get(T, scale_args, attributes, :color),
)]
end

function legend_elements(T::Type{RainClouds}, attributes, scale_args::MixedArguments)
[PolyElement(
color = _get(T, scale_args, attributes, :color),
Expand Down
2 changes: 1 addition & 1 deletion src/transformations/histogram.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const categoricalplottypes = [BarPlot, Heatmap, Volume]
const categoricalplottypes = [BarPlot, Heatmap, Volume, Waterfall]

function compute_edges(intervals::Tuple, bins, closed)
bs = bins isa Tuple ? bins : map(_ -> bins, intervals)
Expand Down
14 changes: 14 additions & 0 deletions test/reference_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1018,3 +1018,17 @@ reftest("stairs") do
visual(Stairs)
draw(spec)
end

reftest("waterfall") do
df = (
x=repeat(1:2, inner=5),
y=[6, 4, 2, -8, 3, 5, 1, -2, -3, 7],
group=repeat('A':'E', outer=2),
)
f = Figure()
fg = draw!(f[1, 1], data(df) * visual(Waterfall, show_final=true) * mapping(:x, :y, color=:group, dodge=:group))
legend!(f[1, 2], fg)
draw!(f[2, 1:2], data(df) * visual(Waterfall, show_direction=true) * mapping(:y))
f
end

Binary file added test/reference_tests/waterfall ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading