Skip to content

Commit

Permalink
Merge pull request #510 from MakieOrg/jk/better-layer-printing
Browse files Browse the repository at this point in the history
Better `Layer` printing
  • Loading branch information
jkrumbiegel authored Jul 22, 2024
2 parents 20ee654 + 67d666e commit c790f1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AlgebraOfGraphics"
uuid = "cbdf2221-f076-402e-a563-3d30da359d67"
authors = ["Pietro Vertechi", "Julius Krumbiegel"]
version = "0.7.1"
version = "0.7.2"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand Down
16 changes: 16 additions & 0 deletions src/algebra/layer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,19 @@ function compute_attributes(pl::ProcessedLayer,
# remove unnecessary information
return filterkeys(!in((:col, :row, :layout, :alpha, :group)), attrs)
end

function Base.show(_io::IO, l::Layer; indent = 0, index = nothing)
io = IOContext(_io, :limit => true)
ind = " " ^ indent
printstyled(io, ind, "Layer ", index === nothing ? "" : index, "\n", bold = true)
println(io, ind, " transformation: ", l.transformation)
println(io, ind, " data: ", typeof(l.data)) # print only type here as data source could be anything and print a lot of stuff
println(io, ind, " positional:")
for (i, pos) in enumerate(l.positional)
println(io, ind, " ", i, ": ", pos)
end
println(io, ind, " named:")
for (name, named) in pairs(l.named)
println(io, ind, " ", name, ": ", named)
end
end
9 changes: 9 additions & 0 deletions src/algebra/layers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,13 @@ function to_entry(P::Type{Heatmap}, p::ProcessedLayer, categoricalscales::Dictio
]

Entry(P, positional, merge(p.named, p.primary, p.attributes, color_attributes))
end

function Base.show(io::IO, layers::Layers; indent = 0)
ind = " " ^ indent
printstyled(io, ind, "Layers", bold = true)
println(io, ind, " with $(length(layers.layers)) elements:")
for (i, layer) in enumerate(layers)
show(io, layer; indent = indent + 1, index = i)
end
end
15 changes: 14 additions & 1 deletion test/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,17 @@ end
@test processedlayers[6].positional[1] == exp.(df.x[df.c .== "c"])
@test processedlayers[6].positional[2] == df.z[df.c .== "c"]
@test processedlayers[6].named[:markersize] == df.w[df.c .== "c"]
end
end

@testset "printing" begin
spec = data((; x = 1:10, y = 11:20)) * mapping(:x, :y, color = :y) * visual(BarPlot) + mapping(:x) * visual(HLines)
# testing printing exactly is finicky across Julia versions, just make sure it's not completely broken
printout = @test_nowarn repr(spec)
@test occursin("Layers with 2 elements", printout)
@test occursin("Layer 1", printout)
@test occursin("Layer 2", printout)
@test occursin("transformation:", printout)
@test occursin("data:", printout)
@test occursin("positional:", printout)
@test occursin("named:", printout)
end

2 comments on commit c790f1c

@jkrumbiegel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/111499

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.2 -m "<description of version>" c790f1ccc5b7b62ab83b51e6192b6084e8954937
git push origin v0.7.2

Please sign in to comment.