Skip to content

Fix Makie recipe to support 3D plots with automatic LScene detection #1079

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions ext/SciMLBaseMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ function ensure_plottrait(PT::Type, arg, desired_plottrait_type::Type)
end
end

# Define preferred axis type based on the idxs parameter
function Makie.preferred_axis_type(plot::Plot{<:Tuple{<:SciMLBase.AbstractTimeseriesSolution}})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dispatch doesn't actually do anything. I don't think you can actually hook into this in this way in Makie v0.24. It might need a small patch, I'm PRing that to Makie now

if haskey(plot, :idxs) || haskey(plot, :vars)
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
idxs = haskey(plot, :idxs) ? plot[:idxs][] :
(haskey(plot, :vars) ? plot[:vars][] : nothing)

if idxs isa Tuple && length(idxs) == 3
return Makie.LScene
elseif idxs isa AbstractArray && length(idxs) == 3
return Makie.LScene
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return Makie.LScene
return Makie.LScene

end
end
return Makie.Axis
end

# ## `AbstractTimeseriesSolution` recipe

# First, we define the standard plot type for timeseries solutions.
Expand Down Expand Up @@ -138,6 +151,19 @@ end

Makie.plottype(integrator::SciMLBase.DEIntegrator) = Makie.Lines

# Define preferred axis type for integrator plots
function Makie.preferred_axis_type(plot::Plot{<:Tuple{<:SciMLBase.DEIntegrator}})
if haskey(plot, :idxs) || haskey(plot, :vars)
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
idxs = haskey(plot, :idxs) ? plot[:idxs][] :
(haskey(plot, :vars) ? plot[:vars][] : nothing)

if idxs isa Tuple && length(idxs) == 3
return Makie.LScene
elseif idxs isa AbstractArray && length(idxs) == 3
return Makie.LScene
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return Makie.LScene
return Makie.LScene

end
end
return Makie.Axis
end

function Makie.used_attributes(::Type{<:Plot}, integrator::SciMLBase.DEIntegrator)
(:plot_analytic, :denseplot, :plotdensity, :vars, :idxs)
end
Expand Down Expand Up @@ -273,6 +299,19 @@ end
# Again, we first define the "ideal" plot type for ensemble solutions.
Makie.plottype(sol::SciMLBase.AbstractEnsembleSolution) = Makie.Lines

# Define preferred axis type for ensemble plots
function Makie.preferred_axis_type(plot::Plot{<:Tuple{<:SciMLBase.AbstractEnsembleSolution}})
if haskey(plot, :idxs) || haskey(plot, :vars)
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
idxs = haskey(plot, :idxs) ? plot[:idxs][] :
(haskey(plot, :vars) ? plot[:vars][] : nothing)

if idxs isa Tuple && length(idxs) == 3
return Makie.LScene
elseif idxs isa AbstractArray && length(idxs) == 3
return Makie.LScene
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return Makie.LScene
return Makie.LScene

end
end
return Makie.Axis
end

# We also define the attributes that are used by the ensemble solution recipe:
function Makie.used_attributes(::Type{<:Plot}, sol::SciMLBase.AbstractEnsembleSolution)
(:trajectories,
Expand Down
Loading