45
45
46
46
function timeseries_cards (app, session)
47
47
cards = OrderedDict {String,Bonito.Hyperscript.Node{Bonito.Hyperscript.HTMLSVG}} ()
48
+ observables = OrderedDict {String, Vector{Observables.ObserverFunction}} ()
48
49
container = Observable {Bonito.Hyperscript.Node{Bonito.Hyperscript.HTMLSVG}} ()
49
50
50
51
on (app. tsplots; update= true ) do _tsplots
@@ -53,10 +54,14 @@ function timeseries_cards(app, session)
53
54
knownkeys = keys (cards)
54
55
55
56
for delkey in setdiff (knownkeys, newkeys)
57
+ Observables. off .(observables[delkey]) # deactivate allobservables from card
58
+ delete! (observables, delkey)
56
59
delete! (cards, delkey)
57
60
end
58
61
for newkey in setdiff (newkeys, knownkeys)
59
- cards[newkey] = timeseries_card (app, newkey, session)
62
+ card, obsf = timeseries_card (app, newkey, session)
63
+ cards[newkey] = card
64
+ observables[newkey] = obsf
60
65
end
61
66
if keys (cards) != keys (_tsplots)
62
67
@warn " The keys do not match: $(keys (cards)) vs $(keys (_tsplots)) "
@@ -87,6 +92,16 @@ function add_timeseries_button(app)
87
92
end
88
93
89
94
function timeseries_card (app, key, session)
95
+ # store all observer functions to be able to remove them later
96
+ obsf = Observables. ObserverFunction[]
97
+ track_obsf = function (f)
98
+ if f isa AbstractVector
99
+ append! (obsf, f)
100
+ else
101
+ push! (obsf, f)
102
+ end
103
+ end
104
+
90
105
tsplot = app. tsplots[][key]
91
106
92
107
comp_options = Observable {Vector{OptionGroup{SymbolicCompIndex}}} ()
@@ -97,15 +112,15 @@ function timeseries_card(app, key, session)
97
112
eg = OptionGroup {SymbolicCompIndex} (" Edges" , EIndex .(1 : ne (g)))
98
113
comp_options[] = [vg, eg]
99
114
nothing
100
- end
115
+ end |> track_obsf
101
116
102
117
state_options = Observable {Vector{OptionGroup{Symbol}}} ()
103
118
onany (app. sol, tsplot. selcomp; update= true ) do _sol, _sel
104
119
@debug " TS: app.sol, tsplot.selcomp => state_options"
105
120
_nw = extract_nw (_sol)
106
121
state_options[] = gen_state_options (_nw, _sel)
107
122
nothing
108
- end
123
+ end |> track_obsf
109
124
110
125
comp_sel = TomSelect (comp_options, tsplot. selcomp;
111
126
placeholder= " Select components" ,
@@ -126,7 +141,7 @@ function timeseries_card(app, key, session)
126
141
empty! (linestyle_cache)
127
142
notify (tsplot. selcomp)
128
143
notify (tsplot. states)
129
- end
144
+ end |> track_obsf
130
145
131
146
reset_axis_button = Bonito. Button (" Reset Axis" , style= Styles (" margin-left" => " 10px" ))
132
147
@@ -146,7 +161,7 @@ function timeseries_card(app, key, session)
146
161
@debug " TS: comp selection => graphplot selection"
147
162
app. graphplot. _selcomp[] = _sel
148
163
nothing
149
- end
164
+ end |> track_obsf
150
165
151
166
# ###
152
167
# ### actual plot
@@ -173,7 +188,7 @@ function timeseries_card(app, key, session)
173
188
color= " #" * Colors. hex (getcycled (COLORS, v)))
174
189
for (k,v) in color_cache]
175
190
nothing
176
- end
191
+ end |> track_obsf
177
192
on (tsplot. states; update= true ) do _states
178
193
@debug " TS: state selection => update linestyle_cache"
179
194
for unused in setdiff (keys (linestyle_cache), _states)
@@ -186,7 +201,7 @@ function timeseries_card(app, key, session)
186
201
lstylepairs[] = [(; title= repr (s), linestyle= getcycled (LINESTYLES_STR, i))
187
202
for (s,i) in linestyle_cache]
188
203
nothing
189
- end
204
+ end |> track_obsf
190
205
191
206
comp_ms_id = Bonito. JSString (comp_sel. id)
192
207
state_ms_id = Bonito. JSString (state_sel. id)
@@ -274,7 +289,7 @@ function timeseries_card(app, key, session)
274
289
@debug " TS: tim/tmax => update ax limits"
275
290
xlims! (ax, (_tmin, _tmax))
276
291
nothing
277
- end
292
+ end |> track_obsf
278
293
279
294
ts = Observable (collect (range (app. sol[]. t[begin ], app. sol[]. t[end ], length= 1000 )))
280
295
refined_xlims = Ref ((NaN , NaN ))
@@ -287,7 +302,7 @@ function timeseries_card(app, key, session)
287
302
notify (ts)
288
303
end
289
304
nothing
290
- end
305
+ end |> track_obsf
291
306
292
307
# collect all the states wie might want to plot
293
308
valid_idxs = Observable (
@@ -302,7 +317,7 @@ function timeseries_card(app, key, session)
302
317
isvalid (idx) && push! (valid_idxs[], idx)
303
318
end
304
319
notify (valid_idxs)
305
- end
320
+ end |> track_obsf
306
321
307
322
# extract the data
308
323
data = Observable {Vector{Vector{Float32}}} (Vector{Float32}[])
@@ -320,7 +335,7 @@ function timeseries_card(app, key, session)
320
335
data. val[i] = _dat[i,:]
321
336
end
322
337
notify (data)
323
- end
338
+ end |> track_obsf
324
339
325
340
replot = Observable {Nothing} (nothing )
326
341
@@ -352,12 +367,12 @@ function timeseries_card(app, key, session)
352
367
end
353
368
end
354
369
nothing
355
- end
370
+ end |> track_obsf
356
371
357
372
on (reset_axis_button. value) do _
358
373
autolimits! (ax)
359
374
xlims! (ax, (app. tmin[], app. tmax[]))
360
- end
375
+ end |> track_obsf
361
376
362
377
# ###
363
378
# ### Click interaction to set time
0 commit comments