Skip to content

Commit

Permalink
avoid Vector to ReinterpretedArray conversion error
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jul 25, 2023
1 parent caba9d8 commit 6f3ec27
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/basic_recipes/error_and_rangebars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,15 @@ function Makie.plot!(plot::Errorbars{T}) where T <: Tuple{AbstractVector{<:VecTy
end

linesegpairs = lift(plot, x_y_low_high, is_in_y_direction) do x_y_low_high, in_y
return map(x_y_low_high) do (x, y, l, h)
in_y ?
(Point2f(x, y - l), Point2f(x, y + h)) :
(Point2f(x - l, y), Point2f(x + h, y))
output = sizehint!(Point2f[], 2length(x_y_low_high))
for (x, y, l, h) in x_y_low_high
if in_y
push!(output, Point2f(x, y - l), Point2f(x, y + h))
else
push!(output, Point2f(x - l, y), Point2f(x + h, y))
end
end
return output
end

_plot_bars!(plot, linesegpairs, is_in_y_direction)
Expand All @@ -169,11 +173,15 @@ function Makie.plot!(plot::Rangebars{T}) where T <: Tuple{AbstractVector{<:VecTy
end

linesegpairs = lift(plot, val_low_high, is_in_y_direction) do vlh, in_y
return map(vlh) do (v, l, h)
in_y ?
(Point2f(v, l), Point2f(v, h)) :
(Point2f(l, v), Point2f(h, v))
output = sizehint!(Point2f[], 2length(vlh))
for (v, l, h) in vlh
if in_y
push!(output, Point2f(v, l), Point2f(v, h))
else
push!(output, Point2f(l, v), Point2f(h, v))
end
end
return output
end

_plot_bars!(plot, linesegpairs, is_in_y_direction)
Expand All @@ -190,14 +198,13 @@ function _plot_bars!(plot, linesegpairs, is_in_y_direction)
scene = parent_scene(plot)

whiskers = lift(plot, linesegpairs, scene.camera.projectionview, plot.model,
scene.px_area, transform_func(plot), whiskerwidth) do pairs, _, _, _, _, whiskerwidth
scene.px_area, transform_func(plot), whiskerwidth) do endpoints, _, _, _, _, whiskerwidth

endpoints = [p for pair in pairs for p in pair]
screenendpoints = plot_to_screen(plot, endpoints)

screenendpoints_shifted_pairs = map(screenendpoints) do sep
(sep .+ f_if(is_in_y_direction[], reverse, Point(0, -whiskerwidth/2)),
sep .+ f_if(is_in_y_direction[], reverse, Point(0, whiskerwidth/2)))
sep .+ f_if(is_in_y_direction[], reverse, Point(0, whiskerwidth/2)))
end

return [p for pair in screenendpoints_shifted_pairs for p in pair]
Expand Down

0 comments on commit 6f3ec27

Please sign in to comment.