warning and hint on mismatched attr lengths
This commit is contained in:
parent
e9cd69ea2f
commit
6af91c7f71
72
src/utils.jl
72
src/utils.jl
@ -82,8 +82,8 @@ function series_segments(series::Series, seriestype::Symbol = :path)
|
|||||||
args = RecipesPipeline.is3d(series) ? (x, y, z) : (x, y)
|
args = RecipesPipeline.is3d(series) ? (x, y, z) : (x, y)
|
||||||
nan_segments = collect(iter_segments(args...))
|
nan_segments = collect(iter_segments(args...))
|
||||||
|
|
||||||
if has_attribute_segments(series)
|
result = if has_attribute_segments(series)
|
||||||
return Iterators.flatten(map(nan_segments) do r
|
Iterators.flatten(map(nan_segments) do r
|
||||||
if seriestype in (:scatter, :scatter3d)
|
if seriestype in (:scatter, :scatter3d)
|
||||||
(SeriesSegment(i:i, i) for i in r)
|
(SeriesSegment(i:i, i) for i in r)
|
||||||
else
|
else
|
||||||
@ -91,8 +91,28 @@ function series_segments(series::Series, seriestype::Symbol = :path)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
return (SeriesSegment(r, 1) for r in nan_segments)
|
(SeriesSegment(r, 1) for r in nan_segments)
|
||||||
|
end
|
||||||
|
|
||||||
|
seg_attr_range = UnitRange(minimum(first(seg.range) for seg in result),
|
||||||
|
maximum(last(seg.range) for seg in result))
|
||||||
|
for attr in _segmenting_vector_attributes
|
||||||
|
v = get(series, attr, nothing)
|
||||||
|
if v isa AVec && eachindex(v) != seg_attr_range
|
||||||
|
@warn "Indices $(eachindex(v)) of attribute `$attr` does not match data indices $seg_attr_range."
|
||||||
|
if any(v -> !isnothing(v) && any(isnan, v), (x,y,z))
|
||||||
|
@info """Data contains NaNs or missing values, and indices of `$attr` vector do not match data indices.
|
||||||
|
If you intend elements of `$attr` to apply to individual NaN-separated segements in the data,
|
||||||
|
pass each segment in a separate vector instead, and use a row vector for `$attr`. Legend entries
|
||||||
|
may be suppressed by passing an empty label.
|
||||||
|
For example,
|
||||||
|
plot([1:2,1:3], [[4,5],[3,4,5]], label=["y" ""], $attr=[1 2])
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
# helpers to figure out if there are NaN values in a list of array types
|
# helpers to figure out if there are NaN values in a list of array types
|
||||||
@ -577,34 +597,34 @@ function get_markerstrokewidth(series, i::Int = 1)
|
|||||||
_cycle(series[:markerstrokewidth], i)
|
_cycle(series[:markerstrokewidth], i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
const _segmenting_vector_attributes = (
|
||||||
|
:seriescolor,
|
||||||
|
:seriesalpha,
|
||||||
|
:linecolor,
|
||||||
|
:linealpha,
|
||||||
|
:linewidth,
|
||||||
|
:linestyle,
|
||||||
|
:fillcolor,
|
||||||
|
:fillalpha,
|
||||||
|
:markercolor,
|
||||||
|
:markeralpha,
|
||||||
|
:markersize,
|
||||||
|
:markerstrokecolor,
|
||||||
|
:markerstrokealpha,
|
||||||
|
:markerstrokewidth,
|
||||||
|
:markershape,
|
||||||
|
)
|
||||||
|
|
||||||
|
const _segmenting_array_attributes = (:line_z, :fill_z, :marker_z)
|
||||||
|
|
||||||
function has_attribute_segments(series::Series)
|
function has_attribute_segments(series::Series)
|
||||||
# we want to check if a series needs to be split into segments just because
|
# we want to check if a series needs to be split into segments just because
|
||||||
# of its attributes
|
# of its attributes
|
||||||
series[:seriestype] == :shape && return false
|
series[:seriestype] == :shape && return false
|
||||||
# check relevant attributes if they have multiple inputs
|
# check relevant attributes if they have multiple inputs
|
||||||
return any(
|
return any(series[attr] isa AbstractVector && length(series[attr]) > 1
|
||||||
(typeof(series[attr]) <: AbstractVector && length(series[attr]) > 1)
|
for attr in _segmenting_vector_attributes
|
||||||
for
|
) || any(series[attr] isa AbstractArray for attr in _segmenting_array_attributes)
|
||||||
attr in [
|
|
||||||
:seriescolor,
|
|
||||||
:seriesalpha,
|
|
||||||
:linecolor,
|
|
||||||
:linealpha,
|
|
||||||
:linewidth,
|
|
||||||
:linestyle,
|
|
||||||
:fillcolor,
|
|
||||||
:fillalpha,
|
|
||||||
:markercolor,
|
|
||||||
:markeralpha,
|
|
||||||
:markersize,
|
|
||||||
:markerstrokecolor,
|
|
||||||
:markerstrokealpha,
|
|
||||||
:markerstrokewidth,
|
|
||||||
:markershape,
|
|
||||||
]
|
|
||||||
) || any(
|
|
||||||
typeof(series[attr]) <: AbstractArray for attr in (:line_z, :fill_z, :marker_z)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_aspect_ratio(sp)
|
function get_aspect_ratio(sp)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user