-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix cycling and test + clean up plotspec diffing
- Loading branch information
1 parent
95a0137
commit b0c0c13
Showing
4 changed files
with
159 additions
and
52 deletions.
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
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,73 @@ | ||
import Makie.SpecApi as S | ||
|
||
@testset "diffing" begin | ||
@testset "update_plot!" begin | ||
obs = Observable[] | ||
oldspec = S.Scatter(1:4; cycle=[]) | ||
newspec = S.Scatter(1:4; cycle=[]) | ||
p = Makie.to_plot_object(newspec) | ||
s = Scene() | ||
plot!(s, p) | ||
Makie.update_plot!(obs, p, oldspec, newspec) | ||
@test isempty(obs) | ||
|
||
newspec = S.Scatter(1:4; color=:red) | ||
Makie.update_plot!(obs, p, oldspec, newspec) | ||
oldspec = newspec | ||
@test length(obs) == 1 | ||
@test obs[1] === p.color | ||
|
||
newspec = S.Scatter(1:4; color=:green, cycle=[]) | ||
empty!(obs) | ||
Makie.update_plot!(obs, p, oldspec, newspec) | ||
oldspec = newspec | ||
@test length(obs) == 1 | ||
@test obs[1] === p.color | ||
@test obs[1].val == to_color(:green) | ||
|
||
newspec = S.Scatter(1:5; color=:green, cycle=[]) | ||
empty!(obs) | ||
Makie.update_plot!(obs, p, oldspec, newspec) | ||
oldspec = newspec | ||
@test length(obs) == 1 | ||
@test obs[1] === p.args[1] | ||
|
||
oldspec = S.Scatter(1:5; color=:green, marker=:rect, cycle=[]) | ||
newspec = S.Scatter(1:4; color=:red, marker=:circle, cycle=[]) | ||
empty!(obs) | ||
p = Makie.to_plot_object(oldspec) | ||
s = Scene() | ||
plot!(s, p) | ||
Makie.update_plot!(obs, p, oldspec, newspec) | ||
@test length(obs) == 3 | ||
@test obs[1] === p.args[1] | ||
@test obs[2] === p.color | ||
@test obs[3] === p.marker | ||
end | ||
|
||
@testset "diff_plotlist!" begin | ||
scene = Scene(); | ||
plotspecs = [S.Scatter(1:4; color=:green), S.Scatter(1:4; color=:red)] | ||
reusable_plots = IdDict{PlotSpec,Plot}() | ||
obs_to_notify = Observable[] | ||
new_plots = Makie.diff_plotlist!(scene, plotspecs, obs_to_notify, reusable_plots) | ||
@test length(new_plots) == 2 | ||
@test Set(scene.plots) == Set(values(new_plots)) | ||
@test isempty(obs_to_notify) | ||
|
||
new_plots2 = Makie.diff_plotlist!(scene, plotspecs, obs_to_notify, new_plots) | ||
|
||
@test isempty(new_plots) # they got all used up | ||
@test Set(scene.plots) == Set(values(new_plots2)) | ||
@test isempty(obs_to_notify) | ||
|
||
plotspecs = [S.Scatter(1:4; color=:red), S.Scatter(1:4; color=:green)] | ||
new_plots3 = Makie.diff_plotlist!(scene, plotspecs, obs_to_notify, new_plots2) | ||
|
||
@test isempty(new_plots) # they got all used up | ||
@test Set(scene.plots) == Set(values(new_plots3)) | ||
# TODO, and some point we should try to find the matching plot and just | ||
# switch them, so we don't need an update! | ||
@test Set(obs_to_notify) == Set([scene.plots[1].color, scene.plots[2].color]) | ||
end | ||
end |