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

Update plotting recipe to support Plots 1.10.0 #218

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
27 changes: 16 additions & 11 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@ interval_markers(L::Type{<:Bound}, R::Type{<:Bound}) = interval_marker.([L, R])
interval_marker(x::Type{Closed}) = :vline
interval_marker(x::Type{Open}) = :none

_alpha(marker::Symbol) = marker === :none ? 0 : 1

# TODO: Add support for plotting unbounded intervals
@recipe function f(xs::AbstractVector{<:AbstractInterval{T,L,R}}, ys) where {T, L <: Bounded, R <: Bounded}
new_xs = T[]
new_xs = Vector{T}[]
new_ys = []
markers = Symbol[]
markers = Vector{Symbol}[]
for (x, y) in zip(xs, ys)
marker = interval_markers(x)

# To cause line to not be connected, need to add a breaker point with
# NaN in one of the coordinates. We put that in `new_ys` as that is probably a
# float. where-as new_xs is potentially a DateTime etc that would not accept NaN
append!(new_xs, [first(x), last(x), last(x)])
append!(new_ys, [y, y, NaN])
append!(markers, interval_markers(x))
push!(markers, :none)
push!(new_xs, [first(x), last(x)])
push!(new_ys, [y, y])
push!(markers, interval_markers(x))
end

# Work around GR bug that shows :none as a marker
# TODO: remove once https://github.com/jheinen/GR.jl/issues/295 is fixed
markeralpha := [x == :none ? 0 : 1 for x in markers]
# Work around GR bug that shows `:none` as a marker
# TODO: remove once https://github.com/jheinen/GR.jl/issues/295 is fixed
markeralpha := permutedims([_alpha.(m) for m in markers])

markershape := markers
seriestype := :path # always a path, even in a scatter plot
new_xs, new_ys
seriestype := :path # always a path, even in a scatter plot
markershape := permutedims(markers) # force markershape to be set the endpoints

return new_xs, new_ys
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
[compat]
Documenter = "0.23, 0.24, 0.25, 0.26, 0.27"
Infinity = "0.2.3"
Plots = "1.10.0"
UTCDateTimes = "1.1"
Loading