Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stephist with related Stairs plot type, and Volume plot type #572

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

- Added `Volume`, `Stairs` aesthetic mapping and `stephistogram` analysis [#572](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/572).

## v0.8.12 - 2024-10-07

- Added `legend` keyword in `visual` to allow overriding legend element attributes [#570](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/570).
Expand Down
3 changes: 2 additions & 1 deletion src/AlgebraOfGraphics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export hideinnerdecorations!, deleteemptyaxes!
export Layer, Layers, ProcessedLayer, ProcessedLayers
export Entry, AxisEntries
export renamer, sorter, nonnumeric, verbatim, presorted
export density, histogram, linear, smooth, expectation, frequency, contours, filled_contours
export density, histogram, stephistogram, linear, smooth, expectation, frequency, contours, filled_contours
export visual, data, geodata, dims, mapping
export datetimeticks
export draw, draw!
Expand Down Expand Up @@ -70,6 +70,7 @@ include("transformations/frequency.jl")
include("transformations/expectation.jl")
include("transformations/contours.jl")
include("transformations/filled_contours.jl")
include("transformations/stephistogram.jl")
include("guides/guides.jl")
include("guides/legend.jl")
include("guides/colorbar.jl")
Expand Down
17 changes: 17 additions & 0 deletions src/aesthetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@
])
end

function aesthetic_mapping(::Type{Stairs}, ::Normal, ::Normal)
dictionary([

Check warning on line 170 in src/aesthetics.jl

View check run for this annotation

Codecov / codecov/patch

src/aesthetics.jl#L169-L170

Added lines #L169 - L170 were not covered by tests
pointlike_positionals(2)...,
:color => AesColor,
:linestyle => AesLineStyle,
])
end

function aesthetic_mapping(::Type{HLines}, ::Normal)
dictionary([
1 => AesY,
Expand Down Expand Up @@ -218,6 +226,15 @@
])
end

function aesthetic_mapping(::Type{Volume}, ::Normal, ::Normal, ::Normal, ::Normal)
dictionary([

Check warning on line 230 in src/aesthetics.jl

View check run for this annotation

Codecov / codecov/patch

src/aesthetics.jl#L229-L230

Added lines #L229 - L230 were not covered by tests
1 => AesX,
2 => AesY,
3 => AesZ,
4 => AesVolumeColor, # set to AesColor would not work
])
end

function aesthetic_mapping(::Type{LinesFill}, ::Normal, ::Normal)
dictionary([
1 => AesX,
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/layers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function full_rescale(data, aes::Type{AesMarkerSize}, scale::ContinuousScale)
values_to_markersizes(data, props.sizerange, scale.extrema)
end

full_rescale(data, aes::Type{<:Union{AesContourColor,AesABIntercept,AesABSlope}}, scale::ContinuousScale) = data # passthrough, this aes is a mock one anyway
full_rescale(data, aes::Type{<:Union{AesContourColor,AesABIntercept,AesABSlope,AesVolumeColor}}, scale::ContinuousScale) = data # passthrough, this aes is a mock one anyway

function values_to_markersizes(data, sizerange, extrema)
# we scale the area linearly with the values
Expand Down
2 changes: 1 addition & 1 deletion src/guides/legend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function legend_elements(T::Type{Heatmap}, attributes, scale_args::MixedArgument
)]
end

function legend_elements(T::Type{<:Union{HLines,VLines,Lines,LineSegments,Errorbars,Rangebars,Wireframe,ABLines,ECDFPlot}}, attributes, scale_args::MixedArguments)
function legend_elements(T::Type{<:Union{HLines,VLines,Lines,LineSegments,Errorbars,Rangebars,Wireframe,ABLines,ECDFPlot,Stairs}}, attributes, scale_args::MixedArguments)

is_vertical = T === VLines || (T <: Union{Errorbars,Rangebars} && _get(T, scale_args, attributes, :direction) === :y)
# TODO: seems errorbars and rangebars are missing linestyle in Makie, once this is fixed, remove this
Expand Down
1 change: 1 addition & 0 deletions src/scales.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct AesText <: Aesthetic end
# maybe aesthetics that completely avoid scales
struct AesViolinSide <: Aesthetic end
struct AesContourColor <: Aesthetic end # this is just so the third contour argument doesn't conflict with other things for now, it's complex to handle in its interplay with `color` and `levels`
struct AesVolumeColor <: Aesthetic end # this is the fourth argument of volume
struct AesPlaceholder <: Aesthetic end # choropleth for example takes as first arg only geometries which avoid scales, but for now we still have to give an aes to 1, so this can serve for that purpose
struct AesABIntercept <: Aesthetic end
struct AesABSlope <: Aesthetic end
Expand Down
28 changes: 28 additions & 0 deletions src/transformations/stephistogram.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Base.@kwdef struct StepHistogramAnalysis{D, B}
datalimits::D=automatic
bins::B=automatic
closed::Symbol=:left
normalization::Symbol=:none
end

function (h::StepHistogramAnalysis)(input::ProcessedLayer)
datalimits = h.datalimits === automatic ? defaultdatalimits(input.positional) : h.datalimits
options = valid_options(; datalimits, h.bins, h.closed, h.normalization)

Check warning on line 10 in src/transformations/stephistogram.jl

View check run for this annotation

Codecov / codecov/patch

src/transformations/stephistogram.jl#L8-L10

Added lines #L8 - L10 were not covered by tests

output = map(input) do p, n
hist = _histogram(Tuple(p); pairs(n)..., pairs(options)...)
edges, weights = hist.edges, hist.weights
return (map(midpoints, edges)..., weights), (;)

Check warning on line 15 in src/transformations/stephistogram.jl

View check run for this annotation

Codecov / codecov/patch

src/transformations/stephistogram.jl#L12-L15

Added lines #L12 - L15 were not covered by tests
end

N = length(input.positional)
@assert N == 1 "StepHistogram only supports 1D data"
label = h.normalization == :none ? "count" : string(h.normalization)
labels = set(output.labels, N+1 => label)
attributes = output.attributes
default_plottype = Stairs
plottype = Makie.plottype(input.plottype, default_plottype)
return ProcessedLayer(output; plottype, labels, attributes)

Check warning on line 25 in src/transformations/stephistogram.jl

View check run for this annotation

Codecov / codecov/patch

src/transformations/stephistogram.jl#L18-L25

Added lines #L18 - L25 were not covered by tests
end

stephistogram(; options...) = transformation(StepHistogramAnalysis(; options...))

Check warning on line 28 in src/transformations/stephistogram.jl

View check run for this annotation

Codecov / codecov/patch

src/transformations/stephistogram.jl#L28

Added line #L28 was not covered by tests
Loading