-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample2.jl
115 lines (90 loc) · 3.58 KB
/
example2.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using WGLMakie
WGLMakie.activate!()
using JSServe
using Markdown
# 1. LOAD LIBRARY
using CSSMakieLayout
config = Dict(
:resolution => (1400, 700), #used for the main figures
:colorscheme => ["rgb(242, 242, 247)", "black", "#000529", "white"],
:smallresolution => (280, 160), #used for the menufigures
)
# define some style for the menufigures' container
menufigs_style = """
display:flex;
flex-direction: row;
justify-content: space-around;
background-color: $(config[:colorscheme][1]);
padding-top: 20px;
width: $(config[:resolution][1])px;
"""
landing = App() do session::Session
# Create the menufigures and the mainfigures
mainfigures = [Figure(backgroundcolor=:white, resolution=config[:resolution]) for _ in 1:3]
menufigures = [Figure(backgroundcolor=:white, resolution=config[:smallresolution]) for _ in 1:3]
# Figure titles
titles= ["Figure a: sin(x)",
"Figure b: tan(x)",
"Figure c: cos(x)"]
# Active index/ hovered index: 1 2 or 3
# 1: the first a.k.a 'a' figure is active / hovered respectively
# 2: the second a.k.a 'b' figure is active / hovered respectively
# 3: the third a.k.a 'c' figure is active / hovered respectively
activeidx = Observable(1)
hoveredidx = Observable(0)
# Add custom click event listeners
for i in 1:3
on(events(menufigures[i]).mousebutton) do event
activeidx[]=i
notify(activeidx)
end
on(events(menufigures[i]).mouseposition) do event
hoveredidx[]=i
notify(hoveredidx)
end
end
# Axii of each of the 6 figures
main_axii = [Axis(mainfigures[i][1, 1]) for i in 1:3]
menu_axii = [Axis(menufigures[i][1, 1]) for i in 1:3]
# Plot each of the 3 figures using your own plots!
scatter!(main_axii[1], 0:0.1:10, x -> sin(x))
scatter!(main_axii[2], 0:0.1:10, x -> tan(x))
scatter!(main_axii[3], 0:0.1:10, x -> log(x))
scatter!(menu_axii[1], 0:0.1:10, x -> sin(x))
scatter!(menu_axii[2], 0:0.1:10, x -> tan(x))
scatter!(menu_axii[3], 0:0.1:10, x -> log(x))
# Create ZStacks displaying titles below the menu graphs
titles_zstack = [zstack(wrap(DOM.h4(titles[i], class="upper")),
wrap("");
activeidx=@lift(($hoveredidx == i || $activeidx == i)),
anim=[:opacity], style="""color: $(config[:colorscheme][2]);""") for i in 1:3]
# Wrap each of the menu figures and its corresponing title zstack in a div
menufigs_andtitles = wrap([
vstack(
hoverable(menufigures[i], anim=[:border];
stayactiveif=@lift($activeidx == i)),
titles_zstack[i];
class="justify-center align-center "
) for i in 1:3];
class="menufigs",
style=menufigs_style
)
# Create the active figure zstack and add the :whoop (zoom in) animation to it
activefig = zstack(
active(mainfigures[1]),
wrap(mainfigures[2]),
wrap(mainfigures[3]);
activeidx=activeidx,
anim=[:whoop])
# Obtain reactive layout of the figures
return wrap(menufigs_andtitles, activefig, CSSMakieLayout.formatstyle)
end
isdefined(Main, :server) && close(server);
port = 8888
interface = "127.0.0.1"
proxy_url = ""
server = JSServe.Server(interface, port; proxy_url);
JSServe.HTTPServer.start(server)
JSServe.route!(server, "/" => landing);
# the app will run on localhost at port 8888
wait(server)