-
-
Notifications
You must be signed in to change notification settings - Fork 327
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
Generic plot tests #4804
Draft
ffreyer
wants to merge
5
commits into
master
Choose a base branch
from
ff/testplot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Generic plot tests #4804
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
94e5d2c
add testplot!() function
ffreyer d4ec8e6
fix projview_to_2d_limits in scene
ffreyer 2690c86
test that every plot works in Scene()
ffreyer b970991
add SparseArrays dependency
ffreyer b46d5a9
switch to dispatch, fix name collisions
ffreyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@testset "plot!() to scene" begin | ||
scene = Scene() | ||
for PlotType in ALL_PLOT_TYPES | ||
@testset "$PlotType" begin | ||
testplot!(scene, PlotType) | ||
@test true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using SparseArrays | ||
using Random | ||
|
||
const ALL_PLOT_PRIMITIVES = [ | ||
Scatter, Lines, LineSegments, Makie.Text, Mesh, MeshScatter, Image, Heatmap, | ||
Surface, Volume, Voxels | ||
] | ||
const ALL_PLOT_TYPES = vcat(ALL_PLOT_PRIMITIVES, [ | ||
# skipped Annotations, Axis3D | ||
ABLines, Arc, Arrows, Band, Makie.BarPlot, Bracket, Contourf, Contour, Contour3d, | ||
DataShader, Errorbars, Rangebars, HLines, VLines, HSpan, VSpan, Pie, Poly, | ||
RainClouds, ScatterLines, Series, Spy, Stairs, Stem, StreamPlot, TimeSeries, | ||
Tooltip, Tricontourf, Triplot, VolumeSlices, Voronoiplot, Waterfall, Wireframe, | ||
BoxPlot, CrossBar, Density, QQPlot, QQNorm, ECDFPlot, Hexbin, Hist, Violin | ||
]) | ||
|
||
""" | ||
testplot!(scenelike, PlotType[; kwargs...]) | ||
|
||
Creates a sample plot of type `PlotType` with random data in the given `scenelike`. | ||
Any keyword arguments are passed to the plot function. | ||
|
||
This is meant to simplify creating throw-away plots for testing attributes. | ||
`ALL_PLOT_TYPES` may also be useful. | ||
""" | ||
function testplot!(scene, ::Type{PlotType}, kwargs...) where {PlotType <: Plot} | ||
CT = Makie.conversion_trait(PlotType) | ||
f = Makie.MakieCore.plotfunc!(PlotType) | ||
|
||
if CT === PointBased() || PlotType <: Union{Makie.Text, ABLines, BarPlot, | ||
HSpan, VSpan, Triplot, Voronoiplot, BoxPlot, QQPlot, QQNorm} | ||
return f(scene, rand(10), rand(10); kwargs...) | ||
|
||
elseif CT isa Union{Makie.GridBased, Makie.ImageLike} | ||
return f(scene, rand(10, 10); kwargs...) | ||
|
||
elseif CT isa Makie.VolumeLike || PlotType <: Voxels | ||
return f(scene, rand(10, 10, 10); kwargs...) | ||
|
||
elseif PlotType <: Violin # TODO: doesn't work with SampleBased() input | ||
return f(scene, rand(1:3, 100), rand(100); kwargs...) | ||
|
||
elseif CT isa Makie.SampleBased || PlotType <: Union{Density, ECDFPlot, Hist} | ||
return f(scene, rand(100); kwargs...) | ||
|
||
elseif PlotType <: Union{HLines, VLines, Pie} | ||
return f(scene, rand(10); kwargs...) | ||
|
||
elseif PlotType <: Union{Band, Errorbars, Rangebars, Tricontourf} | ||
return f(scene, 1:10, rand(10), 1 .+ rand(10); kwargs...) | ||
|
||
elseif PlotType <: Union{Mesh, Poly, Wireframe} | ||
return f(scene, Rect2f(rand(Point2f), rand(Vec2f)); kwargs...) | ||
|
||
elseif PlotType <: Arc | ||
return f(scene, rand(Point2f), rand(), minmax(rand(), rand())...; kwargs...) | ||
|
||
elseif PlotType <: Arrows | ||
return f(scene, rand(Point2f, 10), rand(Vec2f, 10); kwargs...) | ||
|
||
elseif PlotType <: Bracket | ||
return f(scene, rand(Point2f), rand(Point2f); kwargs...) | ||
|
||
elseif PlotType <: DataShader | ||
return f(scene, rand(Point2f, 100); kwargs...) | ||
|
||
elseif PlotType <: RainClouds | ||
return f(scene, rand(["A", "B", "C"], 100), rand(100); kwargs...) | ||
|
||
elseif PlotType <: Series # TODO: merge with GridBased, ImageLike once more than 7 categories work | ||
return f(scene, [rand(Point2f, 10) for _ in 1:3]; kwargs...) | ||
|
||
elseif PlotType <: Spy | ||
return f(scene, sparse(rand(10, 10) .< 0.5); kwargs...) | ||
|
||
elseif PlotType <: StreamPlot | ||
return f(scene, (x, y) -> rand(Point2f), -1..1, -1..1; kwargs...) | ||
|
||
elseif PlotType <: TimeSeries | ||
obs = Observable(rand()) | ||
p = f(scene, obs; kwargs...) | ||
for _ in 1:10 | ||
sleep(0.01) | ||
obs[] = rand() | ||
end | ||
return p | ||
|
||
elseif PlotType <: Tooltip | ||
return f(scene, rand(Point2f), randstring(20); kwargs...) | ||
|
||
elseif PlotType <: VolumeSlices | ||
return f(scene, 1:10, 1:10, 1:10, rand(10,10,10); kwargs...) | ||
|
||
elseif PlotType <: CrossBar | ||
return f(scene, 1:10, 0 .- rand(10), rand(10), 1 .+ rand(10); kwargs...) | ||
|
||
else | ||
error("$PlotType not recognized") | ||
end | ||
return | ||
end | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this multiple dispatch based, maybe so it returns aplotspec that can be decomposed to args and kwargs and then plotted?
That way it's easy to extend as we get more recipes, or for external recipes we may want to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I guess multiple dispatch would be better if another library wants to reuse and extend the Code for testing. If it's just used here I don't think multiple dispatch matters much.
I'm not sure if PlotSpec is a good idea. It's calling
to_value
on kwargs/attributes and I'd assume it circumvents parts of the normal plot pipeline. It should probably be tested separatelyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, maybe just returning a tuple
(; args, kwargs)
might work?