Skip to content

Commit 17f471f

Browse files
authored
relax empty plot constraints - rework lims corner cases (#366)
* relax empty plot constraints - rework lims corner cases * update ci
1 parent 8a854fc commit 17f471f

File tree

12 files changed

+85
-29
lines changed

12 files changed

+85
-29
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on:
44
pull_request:
55
push:
6-
branches: [master]
6+
branches: [main]
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

.github/workflows/format-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: format
33
on:
44
pull_request:
55
push:
6-
branches: [master]
6+
branches: [main]
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

.github/workflows/invalidations.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: invalidations
33
on:
44
pull_request:
55
push:
6-
branches: [master]
6+
branches: [main]
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -23,19 +23,19 @@ jobs:
2323

2424
- uses: actions/checkout@v3
2525
with:
26-
ref: 'master'
26+
ref: 'main'
2727
- uses: julia-actions/julia-buildpkg@latest
2828
- uses: julia-actions/julia-invalidations@v1
29-
id: invs_master
29+
id: invs_main
3030

3131
- name: Report invalidation counts
3232
run: |
33-
echo "Invalidations on master: ${{ steps.invs_master.outputs.total }} (${{ steps.invs_master.outputs.deps }} via deps)"
33+
echo "Invalidations on main: ${{ steps.invs_main.outputs.total }} (${{ steps.invs_main.outputs.deps }} via deps)"
3434
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)"
3535
shell: bash
3636
- name: PR doesn't increase number of invalidations
3737
run: |
38-
if (( ${{ steps.invs_pr.outputs.total }} > ${{ steps.invs_master.outputs.total }} )); then
38+
if (( ${{ steps.invs_pr.outputs.total }} > ${{ steps.invs_main.outputs.total }} )); then
3939
exit 1
4040
fi
4141
shell: bash

Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ ColorSchemes = "^3.19"
2626
ColorTypes = "0.11"
2727
Contour = "0.5 - 0.6"
2828
Crayons = "^4.1"
29+
Dates = "1"
2930
FileIO = "1"
3031
FreeType = "4"
3132
ImageInTerminal = "0.5"
33+
IntervalSets = "0.7"
34+
LinearAlgebra = "1"
3235
MarchingCubes = "0.1"
3336
NaNMath = "0.3, 1"
3437
PrecompileTools = "1"
38+
Printf = "1"
3539
Requires = "1"
40+
SparseArrays = "1"
3641
StaticArrays = "1"
3742
StatsBase = "0.33, 0.34"
3843
Unitful = "1"

src/common.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ extend_limits(vec, lims) = extend_limits(vec, lims, :identity)
438438

439439
unitless(x) = x # noop when Unitful is not loaded
440440

441-
function extend_limits(vec, lims, scale::Union{Symbol,Function})
441+
function extend_limits(vec::AbstractVector, lims, scale::Union{Symbol,Function})
442+
isempty(vec) && return is_auto(lims) ? autolims(lims) : lims
443+
442444
scale = scale_callback(scale)
443445
mi, ma = as_float(extrema(lims))
444446
if iszero(mi) && iszero(ma)

src/plot.jl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,31 +126,33 @@ end
126126
127127
Check for invalid input (length) and selects only finite input data.
128128
"""
129-
function validate_input(
130-
x::AbstractVector{<:Number},
131-
y::AbstractVector{<:Number},
132-
z::AbstractVector{<:Number},
133-
)
134-
length(x) == length(y) == length(z) ||
129+
function validate_input(x::AbstractVector, y::AbstractVector, z::AbstractVector)
130+
(nx = length(x)) == (ny = length(y)) == (nz = length(z)) ||
135131
throw(DimensionMismatch("`x`, `y` and `z` must have same length"))
136-
idx = BitVector(map((i, j, k) -> isfinite(i) && isfinite(j) && isfinite(k), x, y, z))
137-
x[idx], y[idx], z[idx]
132+
if nx == ny == nz == 0
133+
x, y, z
134+
else
135+
idx =
136+
BitVector(map((i, j, k) -> isfinite(i) && isfinite(j) && isfinite(k), x, y, z))
137+
x[idx], y[idx], z[idx]
138+
end
138139
end
139140

140-
function validate_input(
141-
x::AbstractVector{<:Number},
142-
y::AbstractVector{<:Number},
143-
z::Nothing,
144-
)
145-
length(x) == length(y) || throw(DimensionMismatch("`x` and `y` must have same length"))
146-
idx = BitVector(map((i, j) -> isfinite(i) && isfinite(j), x, y))
147-
x[idx], y[idx], z
141+
function validate_input(x::AbstractVector, y::AbstractVector, z::Nothing)
142+
(nx = length(x)) == (ny = length(y)) ||
143+
throw(DimensionMismatch("`x` and `y` must have same length"))
144+
if nx == ny == 0
145+
x, y, z
146+
else
147+
idx = BitVector(map((i, j) -> isfinite(i) && isfinite(j), x, y))
148+
x[idx], y[idx], z
149+
end
148150
end
149151

150152
function Plot(
151-
x::AbstractVector{<:Number},
152-
y::AbstractVector{<:Number},
153-
z::Union{AbstractVector{<:Number},Nothing} = nothing,
153+
x::AbstractVector,
154+
y::AbstractVector,
155+
z::Union{AbstractVector,Nothing} = nothing,
154156
canvas::Type{<:Canvas} = BrailleCanvas;
155157
title::AbstractString = PLOT_KEYWORDS.title,
156158
xlabel::AbstractString = PLOT_KEYWORDS.xlabel,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
┌────────────────────────────────────────┐
2+
2 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
3+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
4+
 │⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⡗⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒│ 
5+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
6+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
7+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
8+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
9+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
10+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
11+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
12+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
13+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
14+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
15+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
16+
-10 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
17+
└────────────────────────────────────────┘
18+
⠀-3⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀5⠀
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
┌────────────────────────────────────────┐
2+
2 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
3+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
4+
 │⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⡗⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒│ 
5+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
6+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
7+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
8+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
9+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
10+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
11+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
12+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
13+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
14+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
15+
 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
16+
-10 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
17+
└────────────────────────────────────────┘
18+
⠀-3⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀5⠀

test/tst_common.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ end
3636
@test UnicodePlots.extend_limits([1, 2, 3, 4], [0, 0]) (1.0, 4.0)
3737
@test UnicodePlots.extend_limits([1, 2, 3, 4], [1, 1]) (0.0, 2.0)
3838

39+
@test UnicodePlots.extend_limits([], (-1, 2)) (-1, 2)
40+
3941
@test UnicodePlots.is_auto((0, 0))
4042
@test UnicodePlots.is_auto([0, 0])
4143
@test !UnicodePlots.is_auto((-1, 1))

test/tst_plot.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
BrailleCanvas(5, 30; origin_y = 0.0, origin_x = 0.0, height = 1.0, width = 1.0),
99
)
1010
test_ref("plot/empty_small.txt", @show_col(p))
11+
12+
# empty plot ctor
13+
p = Plot([], [])
14+
@test p isa Plot
15+
p = Plot([], [], [])
16+
@test p isa Plot
17+
18+
p = Plot([], []; xlim = (-3, 5), ylim = (-10, 2))
19+
test_ref("plot/empty_xylim.txt", @show_col(p))
1120
end
1221

1322
@testset "invisible" begin

0 commit comments

Comments
 (0)