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

Recipes do not work well with {h,v}span!() or {h,v}lines!() #3051

Closed
3 tasks done
staticfloat opened this issue Jul 6, 2023 · 7 comments
Closed
3 tasks done

Recipes do not work well with {h,v}span!() or {h,v}lines!() #3051

staticfloat opened this issue Jul 6, 2023 · 7 comments
Labels

Comments

@staticfloat
Copy link
Contributor

  • are you running newest version (version from docs) ?
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)
  • What platform + GPU are you on? macOS

Issue Description

Using the 2d projection types within a recipe seems to cause axis limit confusion. Here's some example code:

using WGLMakie, Makie
Makie.theme(::Nothing) = Makie.CURRENT_DEFAULT_THEME
@recipe(TestRecipe) do scene
    Attributes(
        cycle = [:color],
    )
end

function Makie.plot!(plt::TestRecipe)
    # Plot an example signal
    t = collect((0:99)/100)
    y = .5*sin.(t .* 8π)
    lines!(plt, t, y)

    # Add a shaded region
    vspan!(plt, 0.1, 0.2)

    return plt
end


function vspan_test()
    fig = Figure()
    ax = Axis(fig[1, 1])

    testrecipe!(ax)
    return fig
end
vspan_test()

This results in a plot with a vspan!() going from 0 to 10, not 0 to 1 as the docs describe (and as you get if you do this plot outside of a recipe):

image

As a bonus, CTRL-clicking to reset the zoom bounds gradually zooms out step by step, rather than resetting to a default good location.

@staticfloat staticfloat added the bug label Jul 6, 2023
@ffreyer
Copy link
Collaborator

ffreyer commented Jul 7, 2023

This is probably a problem with boundingbox/data_limits taking the size of the span into account, which then bumps the size of axis limits, which then cycles back to increasign the size of the span. Mixed coordinate spaces and #2881 should fix this eventually.
A workaround for this problem is to add custom data_limits like this:

data_limits(pl::Bracket) = mapreduce(union, pl[1][]) do points
Rect3f([points...])
end

In this case you could just return the data_limits of the scatter plot for the recipe

@staticfloat
Copy link
Contributor Author

I tried to figure out how to do this, but I got stuck because data_limits() doesn't seem to play well when the return value is an Observable, I get the following error:

ERROR: MethodError: no method matching iterate(::Observables.Observable{GeometryBasics.HyperRectangle{3, Float32}})

Closest candidates are:
  iterate(::LibGit2.GitBranchIter)
   @ LibGit2 ~/src/julia-cedar/usr/share/julia/stdlib/v1.11/LibGit2/src/reference.jl:343
  iterate(::LibGit2.GitBranchIter, ::Any)
   @ LibGit2 ~/src/julia-cedar/usr/share/julia/stdlib/v1.11/LibGit2/src/reference.jl:343
  iterate(::VerilogAParser.VerilogACSTParser.ChunkTree)
   @ VerilogAParser ~/.julia/packages/VerilogAParser/BlwXp/src/parse/preproc.jl:269
  ...

Stacktrace:
  [1] _all(f::typeof(isfinite), itr::Observables.Observable{GeometryBasics.HyperRectangle{3, Float32}}, ::Colon)
    @ Base ./reduce.jl:1287
  [2] all(f::Function, itr::Observables.Observable{GeometryBasics.HyperRectangle{3, Float32}})
    @ Base ./reduce.jl:1283
  [3] update_boundingbox!(bb_ref::Base.RefValue{GeometryBasics.HyperRectangle{…}}, point::Observables.Observable{GeometryBasics.HyperRectangle{…}})
    @ Makie ~/.julia/packages/Makie/s8oDn/src/layouting/data_limits.jl:151

@ffreyer
Copy link
Collaborator

ffreyer commented Jul 23, 2023

Yea, data_limits should just return a Rect3f. The reactive stuff is handled where the function is called, if that is needed.

@staticfloat
Copy link
Contributor Author

Hmm, but the data within the recipe object is an observable. How am I supposed to get the bounds of it? Call to_value()?

@ffreyer
Copy link
Collaborator

ffreyer commented Jul 23, 2023

That or just data[]since it's always an observable.

@SimonDanisch
Copy link
Member

data_limits get called on demand, so one just extracts the values from the observables when implementing data_limits

@ffreyer
Copy link
Collaborator

ffreyer commented May 24, 2024

Fixed by #3681 in Makie 0.21 by allowing NaN in bounding boxes to mark a dimension as invalid. h/vspan and h/vlines do that now, so that the default limits only care about the lines for that dimension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants