From b821b7850a1efc8bf9dd62b142fd4258b0fe844d Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 11:26:40 +0100 Subject: [PATCH 1/9] fix `hexbin` with zeros --- src/stats/hexbin.jl | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/stats/hexbin.jl b/src/stats/hexbin.jl index c163f29bf0a..79d00913bfe 100644 --- a/src/stats/hexbin.jl +++ b/src/stats/hexbin.jl @@ -34,10 +34,10 @@ Plots a heatmap with hexagonal bins for the observations `xs` and `ys`. strokecolor=:black) end -function spacings_offsets_nbins(bins::Tuple{Int,Int}, cellsize::Nothing, xmi, xma, ymi, yma) +function spacings_offsets_nbins(bins::Tuple{Int,Int}, cellsize::Nothing, xmi::T, xma::T, ymi::T, yma::T) where T any(<(2), bins) && error("Minimum number of bins in one direction is 2, got $bins.") - x_diff = xma - xmi - y_diff = yma - ymi + x_diff = max(eps(float(T)), xma - xmi) + y_diff = max(eps(float(T)), yma - ymi) xspacing, yspacing = (x_diff, y_diff) ./ (bins .- 1) return xspacing, yspacing, xmi, ymi, bins... @@ -70,7 +70,6 @@ function data_limits(hb::Hexbin) ms = 2 .* fn(hb.plots[1].markersize[]) nw = widths(bb) .+ (ms..., 0.0f0) no = bb.origin .- ((ms ./ 2.0f0)..., 0.0f0) - return Rect3f(no, nw) end @@ -91,17 +90,16 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) isempty(xy) && return - sqrt3 = sqrt(3) - # enclose data in limits - _expand((lo, hi)) = prevfloat(lo), nextfloat(hi) + _expand((lo, hi)) = if lo ≈ hi + prevfloat(lo), nextfloat(hi) + else + lo, hi + end xmi, xma = _expand(extrema((p[1] for p in xy))) ymi, yma = _expand(extrema((p[2] for p in xy))) - x_diff = xma - xmi - y_diff = yma - ymi - xspacing, yspacing, xoff, yoff, nbinsx, nbinsy = spacings_offsets_nbins(bins, cellsize, xmi, xma, ymi, yma) @@ -109,7 +107,7 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) ry = ysize / 2 xsize = xspacing * 2 - rx = xsize / sqrt3 + rx = xsize / √3 d = Dict{Tuple{Int,Int}, Float64}() @@ -126,11 +124,7 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) d1 = ((_x - nx)^2 + (yweight * (_y - ny))^2) d2 = ((_x - nxs)^2 + (yweight * (_y - nys))^2) - is_grid1 = d1 < d2 - - # _xy = is_grid1 ? (nx, ny) : (nxs, nys) - - id = if is_grid1 + id = if d1 < d2 ( cld(dvx, 2), iseven(dvy) ? dvy : dvy+1 @@ -142,7 +136,7 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) ) end - d[id] = get(d, id, 0) + (get_weight(weights, i)) + d[id] = get(d, id, 0.0) + get_weight(weights, i) i += 1 end @@ -187,11 +181,7 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) # and every cell has only 1 entry, then we set the minimum to 0 so we do not get # a singular colorrange error down the line. if mi == ma - if ma == 0 - (0, 1) - else - (0, ma) - end + (0, ma == 0 ? 1 : ma) else (mi, ma) end @@ -220,13 +210,8 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) strokecolor=hb.strokecolor) end -function center_value(dv, spacing, offset, is_grid1) - if is_grid1 - offset + spacing * (dv + isodd(dv)) - else - offset + spacing * (dv + iseven(dv)) - end -end +center_value(dv, spacing, offset, is_grid1) = + offset + spacing * (dv + is_grid1 ? isodd(dv) : iseven(dv)) function nearest_center(val, spacing, offset) dv = Int(fld(val - offset, spacing)) From 148260b03aeead1d66b60e2c2bacbfd28cfa3234 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 11:28:48 +0100 Subject: [PATCH 2/9] add test --- src/stats/hexbin.jl | 2 +- test/statistical_tests.jl | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/stats/hexbin.jl b/src/stats/hexbin.jl index 79d00913bfe..bbb976115d9 100644 --- a/src/stats/hexbin.jl +++ b/src/stats/hexbin.jl @@ -181,7 +181,7 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) # and every cell has only 1 entry, then we set the minimum to 0 so we do not get # a singular colorrange error down the line. if mi == ma - (0, ma == 0 ? 1 : ma) + (0, ma == 0 ? one(ma) : ma) else (mi, ma) end diff --git a/test/statistical_tests.jl b/test/statistical_tests.jl index 9e7e15f5ed4..979d43c6a95 100644 --- a/test/statistical_tests.jl +++ b/test/statistical_tests.jl @@ -295,3 +295,13 @@ end @test p2.plots[2][:color][] === :white @test p2.plots[2][:visible][] === :false end + +@tetset "hexbin" begin + # degenerate case with singleton 0 + hexbin([0, 0], [1, 2]) + hexbin([1, 2], [0, 0]) + + # degenerate case with singleton 1 + hexbin([1, 1], [1, 2]) + hexbin([1, 2], [1, 1]) +end From cd84ed7a41510d84b1b8aee2575b8bd7317e7338 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 11:59:01 +0100 Subject: [PATCH 3/9] update tests --- test/runtests.jl | 13 ++++++++++++- test/statistical_tests.jl | 10 ---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 929f8d4d473..fd9a57a2c97 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,7 +10,7 @@ using GeometryBasics: Pyramid using Makie: volume @testset "Unit tests" begin - @testset "#659 Volume errors if data is not a cube" begin + @testset "Volume errors if data is not a cube (#659)" begin fig, ax, vplot = volume(1:8, 1:8, 1:10, rand(8, 8, 10)) lims = Makie.data_limits(vplot) lo, hi = extrema(lims) @@ -34,9 +34,20 @@ using Makie: volume include("events.jl") include("text.jl") include("boundingboxes.jl") + # include("statistical_tests.jl") # FIXME: untested ? include("ray_casting.jl") include("PolarAxis.jl") include("barplot.jl") include("bezier.jl") include("hist.jl") + + @tetset "Hexbin singleton (#3357)" begin + # degenerate case with singleton 0 + hexbin([0, 0], [1, 2]) + hexbin([1, 2], [0, 0]) + + # degenerate case with singleton 1 + hexbin([1, 1], [1, 2]) + hexbin([1, 2], [1, 1]) + end end diff --git a/test/statistical_tests.jl b/test/statistical_tests.jl index 979d43c6a95..9e7e15f5ed4 100644 --- a/test/statistical_tests.jl +++ b/test/statistical_tests.jl @@ -295,13 +295,3 @@ end @test p2.plots[2][:color][] === :white @test p2.plots[2][:visible][] === :false end - -@tetset "hexbin" begin - # degenerate case with singleton 0 - hexbin([0, 0], [1, 2]) - hexbin([1, 2], [0, 0]) - - # degenerate case with singleton 1 - hexbin([1, 1], [1, 2]) - hexbin([1, 2], [1, 1]) -end From 670527dd0a13e4930dc79bb272911a8d88cce300 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 12:00:23 +0100 Subject: [PATCH 4/9] fix reference tests regression --- src/stats/hexbin.jl | 6 +----- test/runtests.jl | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/stats/hexbin.jl b/src/stats/hexbin.jl index bbb976115d9..22ff146522d 100644 --- a/src/stats/hexbin.jl +++ b/src/stats/hexbin.jl @@ -91,11 +91,7 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) isempty(xy) && return # enclose data in limits - _expand((lo, hi)) = if lo ≈ hi - prevfloat(lo), nextfloat(hi) - else - lo, hi - end + _expand((lo, hi)) = prevfloat(lo), nextfloat(hi) xmi, xma = _expand(extrema((p[1] for p in xy))) ymi, yma = _expand(extrema((p[2] for p in xy))) diff --git a/test/runtests.jl b/test/runtests.jl index fd9a57a2c97..8c76f7e5ac9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -41,7 +41,7 @@ using Makie: volume include("bezier.jl") include("hist.jl") - @tetset "Hexbin singleton (#3357)" begin + @testset "Hexbin singleton (#3357)" begin # degenerate case with singleton 0 hexbin([0, 0], [1, 2]) hexbin([1, 2], [0, 0]) From 07a3359f6f726f7a0fcebeb1f16c01e91933da05 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 12:09:47 +0100 Subject: [PATCH 5/9] restructure tests --- src/stats/hexbin.jl | 2 +- test/issues.jl | 21 +++++++++++ test/{PolarAxis.jl => polaraxis.jl} | 0 test/runtests.jl | 54 ++++++++++------------------- 4 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 test/issues.jl rename test/{PolarAxis.jl => polaraxis.jl} (100%) diff --git a/src/stats/hexbin.jl b/src/stats/hexbin.jl index 22ff146522d..0037f822faf 100644 --- a/src/stats/hexbin.jl +++ b/src/stats/hexbin.jl @@ -120,7 +120,7 @@ function plot!(hb::Hexbin{<:Tuple{<:AbstractVector{<:Point2}}}) d1 = ((_x - nx)^2 + (yweight * (_y - ny))^2) d2 = ((_x - nxs)^2 + (yweight * (_y - nys))^2) - id = if d1 < d2 + id = if (is_grid1 = d1 < d2) ( cld(dvx, 2), iseven(dvy) ? dvy : dvy+1 diff --git a/test/issues.jl b/test/issues.jl new file mode 100644 index 00000000000..12955d228c8 --- /dev/null +++ b/test/issues.jl @@ -0,0 +1,21 @@ +@testset "Reported issues" begin + + @testset "Volume errors if data is not a cube (#659)" begin + fig, ax, vplot = volume(1:8, 1:8, 1:10, rand(8, 8, 10)) + lims = Makie.data_limits(vplot) + lo, hi = extrema(lims) + @test all(lo .<= 1) + @test all(hi .>= (8,8,10)) + end + + @testset "Hexbin singleton (#3357)" begin + # degenerate case with singleton 0 + hexbin([0, 0], [1, 2]) + hexbin([1, 2], [0, 0]) + + # degenerate case with singleton 1 + hexbin([1, 1], [1, 2]) + hexbin([1, 2], [1, 1]) + end + +end \ No newline at end of file diff --git a/test/PolarAxis.jl b/test/polaraxis.jl similarity index 100% rename from test/PolarAxis.jl rename to test/polaraxis.jl diff --git a/test/runtests.jl b/test/runtests.jl index 8c76f7e5ac9..80eb2513e37 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,44 +10,28 @@ using GeometryBasics: Pyramid using Makie: volume @testset "Unit tests" begin - @testset "Volume errors if data is not a cube (#659)" begin - fig, ax, vplot = volume(1:8, 1:8, 1:10, rand(8, 8, 10)) - lims = Makie.data_limits(vplot) - lo, hi = extrema(lims) - @test all(lo .<= 1) - @test all(hi .>= (8,8,10)) - end - + include("barplot.jl") + include("bezier.jl") + include("boundingboxes.jl") + include("conversions.jl") include("deprecated.jl") - include("specapi.jl") - include("primitives.jl") + include("events.jl") + include("figures.jl") + include("hist.jl") + include("issues.jl") + include("liftmacro.jl") + include("makielayout.jl") include("pipeline.jl") + include("polaraxis.jl") + include("primitives.jl") + include("projection_math.jl") + include("quaternions.jl") + include("ray_casting.jl") include("record.jl") include("scenes.jl") - include("conversions.jl") - include("quaternions.jl") - include("projection_math.jl") - include("liftmacro.jl") - include("makielayout.jl") - include("figures.jl") - include("transformations.jl") - include("events.jl") + include("specapi.jl") + # include("statistical_tests.jl") # FIXME: untested and broken ? include("text.jl") - include("boundingboxes.jl") - # include("statistical_tests.jl") # FIXME: untested ? - include("ray_casting.jl") - include("PolarAxis.jl") - include("barplot.jl") - include("bezier.jl") - include("hist.jl") - - @testset "Hexbin singleton (#3357)" begin - # degenerate case with singleton 0 - hexbin([0, 0], [1, 2]) - hexbin([1, 2], [0, 0]) - - # degenerate case with singleton 1 - hexbin([1, 1], [1, 2]) - hexbin([1, 2], [1, 1]) - end + include("transformations.jl") + # include("zoom_pan.jl") # FIXME: untested and broken ? end From 2a5144a42d6e23e98878a780dc085007f803bd1a Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 12:37:53 +0100 Subject: [PATCH 6/9] switch to `import` in tests --- src/bezier.jl | 4 +--- test/bezier.jl | 5 ++--- test/boundingboxes.jl | 2 +- test/conversions.jl | 8 ++++---- test/events.jl | 3 +-- test/issues.jl | 4 ++-- test/runtests.jl | 4 +--- test/statistical_tests.jl | 8 ++++---- test/transformations.jl | 3 +-- 9 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/bezier.jl b/src/bezier.jl index a7754525fea..bb3d7f310f4 100644 --- a/src/bezier.jl +++ b/src/bezier.jl @@ -397,9 +397,7 @@ function parse_bezier_commands(svg) push!(commands, LineTo(Point2d(l[1], y))) i += 2 else - for c in commands - println(c) - end + foreach(println, commands) error("Parsing $comm not implemented.") end diff --git a/test/bezier.jl b/test/bezier.jl index 2111b8f235e..e7db801f77f 100644 --- a/test/bezier.jl +++ b/test/bezier.jl @@ -1,10 +1,9 @@ -using Makie, Test # nice reference: https://www.nan.fyi/svg-paths @testset "BezierPath construction" begin @test_nowarn BezierPath("m 0,9 L 0,5138 0,9 z") - @test_broken BezierPath("m 0,1e-5 L 0,5138 0,9 z") isa BezierPath + @test_broken BezierPath("m 0,1e-5 L 0,5138 0,9 z") isa BezierPath # `Parsing e is not implemented` @test_nowarn BezierPath("M 100,100 C 100,200 200,100 200,200 z") - @test_broken BezierPath("M 100,100 Q 50,150,100,100 z") isa BezierPath + @test_broken BezierPath("M 100,100 Q 50,150,100,100 z") isa BezierPath # `Parsing Q is not implemented` @test_broken BezierPath("M 3.0 10.0 A 10.0 7.5 0.0 0.0 0.0 20.0 15.0 z") isa BezierPath end diff --git a/test/boundingboxes.jl b/test/boundingboxes.jl index 5008cf1fe5c..1fcaadf7dfa 100644 --- a/test/boundingboxes.jl +++ b/test/boundingboxes.jl @@ -65,7 +65,7 @@ end @test bb.origin ≈ Point3f(-0.2) @test bb.widths ≈ Vec3f(2.4) - fig, ax, p = volume(rand(5, 5, 5)) + fig, ax, p = Makie.volume(rand(5, 5, 5)) bb = boundingbox(p) @test bb.origin ≈ Point3f(0) @test bb.widths ≈ Vec3f(5) diff --git a/test/conversions.jl b/test/conversions.jl index 4d27bf4de6f..0d5fb187795 100644 --- a/test/conversions.jl +++ b/test/conversions.jl @@ -1,10 +1,12 @@ -using Makie: +import Makie: NoConversion, convert_arguments, conversion_trait, convert_single_argument, to_vertices, - categorical_colors + categorical_colors, + check_line_pattern, + line_diff_pattern @testset "Conversions" begin # NoConversion @@ -131,8 +133,6 @@ end end end -using Makie: check_line_pattern, line_diff_pattern - @testset "Linetype" begin @test isnothing(check_line_pattern("-.")) @test isnothing(check_line_pattern("--")) diff --git a/test/events.jl b/test/events.jl index 41b7a94d440..e21cf08d8aa 100644 --- a/test/events.jl +++ b/test/events.jl @@ -1,5 +1,4 @@ -using Makie: MouseButtonEvent, KeyEvent, Figure, Textbox -using Makie: Not, And, Or +import Makie: MouseButtonEvent, KeyEvent, Figure, Textbox, Not, And, Or using InteractiveUtils # rudimentary equality for tests diff --git a/test/issues.jl b/test/issues.jl index 12955d228c8..6d52e15afca 100644 --- a/test/issues.jl +++ b/test/issues.jl @@ -1,7 +1,7 @@ @testset "Reported issues" begin @testset "Volume errors if data is not a cube (#659)" begin - fig, ax, vplot = volume(1:8, 1:8, 1:10, rand(8, 8, 10)) + fig, ax, vplot = Makie.volume(1:8, 1:8, 1:10, rand(8, 8, 10)) lims = Makie.data_limits(vplot) lo, hi = extrema(lims) @test all(lo .<= 1) @@ -18,4 +18,4 @@ hexbin([1, 2], [1, 1]) end -end \ No newline at end of file +end diff --git a/test/runtests.jl b/test/runtests.jl index 80eb2513e37..4287599d919 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,9 +5,7 @@ using Makie.GeometryBasics using Makie.PlotUtils using Makie.FileIO using Makie.IntervalSets -using GeometryBasics: Pyramid - -using Makie: volume +using LinearAlgebra @testset "Unit tests" begin include("barplot.jl") diff --git a/test/statistical_tests.jl b/test/statistical_tests.jl index 9e7e15f5ed4..052bf9a3b16 100644 --- a/test/statistical_tests.jl +++ b/test/statistical_tests.jl @@ -1,10 +1,10 @@ -using StatsBase: Histogram using Makie, StatsBase -import Distributions using KernelDensity -using Random: seed! -using GeometryBasics: Rect2f +import GeometryBasics: Rect2f +import StatsBase: Histogram +import Distributions +import Random: seed! seed!(0) diff --git a/test/transformations.jl b/test/transformations.jl index ff3366a9737..6d4ed2e1553 100644 --- a/test/transformations.jl +++ b/test/transformations.jl @@ -1,5 +1,4 @@ -using Makie: PointTrans, apply_transform -using LinearAlgebra +import Makie: PointTrans, apply_transform function xyz_boundingbox(trans, points) bb_ref = Base.RefValue(Rect3f()) From 162304b2b6e2c5cb31317041c8de59054c393e49 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 13:06:39 +0100 Subject: [PATCH 7/9] remove nfc --- src/bezier.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bezier.jl b/src/bezier.jl index bb3d7f310f4..a7754525fea 100644 --- a/src/bezier.jl +++ b/src/bezier.jl @@ -397,7 +397,9 @@ function parse_bezier_commands(svg) push!(commands, LineTo(Point2d(l[1], y))) i += 2 else - foreach(println, commands) + for c in commands + println(c) + end error("Parsing $comm not implemented.") end From fc9ff8d4acb6f466acff3c0d9259455e532f9093 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 24 Dec 2023 13:23:21 +0100 Subject: [PATCH 8/9] try ubuntu 22.04 --- .github/workflows/relocatability.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/relocatability.yml b/.github/workflows/relocatability.yml index 5612a9e08e8..27792ae3bcb 100644 --- a/.github/workflows/relocatability.yml +++ b/.github/workflows/relocatability.yml @@ -28,7 +28,7 @@ jobs: version: - '1' # automatically expands to the latest stable 1.x release of Julia os: - - ubuntu-20.04 + - ubuntu-22.04 arch: - x64 steps: From 138cf016c693bc7cc82c5eaaf3d4a48be868a338 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Thu, 28 Dec 2023 13:51:14 +0100 Subject: [PATCH 9/9] try again 20.04 --- .github/workflows/relocatability.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/relocatability.yml b/.github/workflows/relocatability.yml index 27792ae3bcb..5612a9e08e8 100644 --- a/.github/workflows/relocatability.yml +++ b/.github/workflows/relocatability.yml @@ -28,7 +28,7 @@ jobs: version: - '1' # automatically expands to the latest stable 1.x release of Julia os: - - ubuntu-22.04 + - ubuntu-20.04 arch: - x64 steps: