forked from MakieOrg/Makie.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specapi.jl
73 lines (63 loc) · 2.61 KB
/
specapi.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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=:red), 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=:yellow), 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