Skip to content

Commit

Permalink
Histogram: fix a bug when data changes to allequal values (#3325)
Browse files Browse the repository at this point in the history
When plotting Observables if the contained collection changed such that
all values were equal the minimum and maximum values would match causing
pick_hist_edges to return a vector. This in turn would result in a
conversion error if the previous value was a range. This is fixed by
simply returning a range instead.

Fixes #2452
  • Loading branch information
Sagnac authored Oct 31, 2023
1 parent 3c115c2 commit c8458b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stats/hist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function pick_hist_edges(vals, bins)
if bins isa Int
mi, ma = float.(extrema(vals))
if mi == ma
return [mi - 0.5, ma + 0.5]
return (mi - 0.5):(ma + 0.5)
end
# hist is right-open, so to include the upper data point, make the last bin a tiny bit bigger
ma = nextfloat(ma)
Expand Down
16 changes: 16 additions & 0 deletions test/hist.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@testset "Histogram plotting" begin
unequal_vec = [1; rand(2:9, rand(1:9))]
allequal_vec = fill(rand(1:9), rand(1:9))
# normal range
@test_nowarn hist(0:rand(1:9))
# initialize with unequal observable vector
v = Observable(unequal_vec)
@test_nowarn hist(v)
# change to allequal vector
@test_nowarn v[] = allequal_vec
# initialize with allequal observable vector
v = Observable(allequal_vec)
@test_nowarn hist(v)
# change to unequal vector
@test_nowarn v[] = unequal_vec
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ using Makie: volume
include("PolarAxis.jl")
include("barplot.jl")
include("bezier.jl")
include("hist.jl")
end

10 comments on commit c8458b7

@SimonDanisch
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@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 updated: JuliaRegistries/General/94526

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.19.12 -m "<description of version>" c8458b766f32da97c84e0791fd8f7e3a74a755c8
git push origin v0.19.12

@SimonDanisch
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir=GLMakie

@SimonDanisch
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir=WGLMakie

@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/94539

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 GLMakie-v0.8.12 -m "<description of version>" c8458b766f32da97c84e0791fd8f7e3a74a755c8
git push origin GLMakie-v0.8.12

@SimonDanisch
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir=CairoMakie

@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/94540

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 WGLMakie-v0.8.16 -m "<description of version>" c8458b766f32da97c84e0791fd8f7e3a74a755c8
git push origin WGLMakie-v0.8.16

@SimonDanisch
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir=RPRMakie

@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/94541

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 CairoMakie-v0.10.12 -m "<description of version>" c8458b766f32da97c84e0791fd8f7e3a74a755c8
git push origin CairoMakie-v0.10.12

@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/94542

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 RPRMakie-v0.5.12 -m "<description of version>" c8458b766f32da97c84e0791fd8f7e3a74a755c8
git push origin RPRMakie-v0.5.12

Please sign in to comment.