Skip to content

Commit

Permalink
Merge pull request #127 from bcsj/lineplot-nan-support
Browse files Browse the repository at this point in the history
added support for vectors containing NaN in lineplot
  • Loading branch information
Evizero committed Nov 18, 2020
2 parents cb114bc + 4c6a691 commit 3ba7e63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/canvas.jl
Expand Up @@ -85,6 +85,9 @@ end
function lines!(c::Canvas, X::AbstractVector, Y::AbstractVector, color::Union{Int, Symbol})
length(X) == length(Y) || throw(DimensionMismatch("X and Y must be the same length"))
for i in 1:(length(X)-1)
if isnan(X[i]) || isnan(X[i+1]) || isnan(Y[i]) || isnan(Y[i+1])
continue
end
lines!(c, X[i], Y[i], X[i+1], Y[i+1], color)
end
c
Expand Down
4 changes: 3 additions & 1 deletion src/interface/lineplot.jl
Expand Up @@ -101,7 +101,9 @@ function lineplot(
color::Symbol = :auto,
name = "",
kw...)
new_plot = Plot(x, y, canvas; kw...)
idx = map(!isnan, x)
idx .&= map(!isnan, y)
new_plot = Plot(x[idx], y[idx], canvas; kw...)
lineplot!(new_plot, x, y; color = color, name = name)
end

Expand Down

0 comments on commit 3ba7e63

Please sign in to comment.