Skip to content

Commit 4953082

Browse files
committed
sync app on updates
1 parent 74172e0 commit 4953082

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

NetworkDynamicsInspector/src/NetworkDynamicsInspector.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function inspect(sol; restart=false, reset=false, display=CURRENT_DISPLAY[])
157157
APPSTATE[] = appstate
158158
CURRENT_WEBAPP[] = webapp
159159

160+
wait_for()
160161
nothing
161162
end
162163

NetworkDynamicsInspector/src/appstate.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ set_maybe!(obs::Observable, ::NotSpecified) = nothing
8888
Set the solution of the current appstate to `sol`.
8989
"""
9090
function set_sol!(sol)
91+
wait_for()
9192
if isnothing(APPSTATE[])
9293
APPSTATE[] = AppState(sol)
9394
else
9495
APPSTATE[].sol[] = sol
9596
end
97+
wait_for()
9698
nothing
9799
end
98100

@@ -107,10 +109,12 @@ function set_state!(; sol = NotSpecified(),
107109
t = NotSpecified(),
108110
tmin = NotSpecified(),
109111
tmax = NotSpecified())
112+
wait_for()
110113
sol != NotSpecified() && set_sol!(sol)
111114
set_maybe!(appstate().t, t)
112115
set_maybe!(appstate().tmin, tmin)
113116
set_maybe!(appstate().tmax, tmax)
117+
wait_for()
114118
nothing
115119
end
116120

@@ -127,13 +131,15 @@ function set_graphplot!(; nstate = NotSpecified(),
127131
estate_rel = NotSpecified(),
128132
ncolorrange = NotSpecified(),
129133
ecolorrange = NotSpecified())
134+
wait_for()
130135
gp = appstate().graphplot
131136
set_maybe!(gp.nstate, nstate)
132137
set_maybe!(gp.estate, estate)
133138
set_maybe!(gp.nstate_rel, nstate_rel)
134139
set_maybe!(gp.estate_rel, estate_rel)
135140
set_maybe!(gp.ncolorrange, ncolorrange)
136141
set_maybe!(gp.ecolorrange, ecolorrange)
142+
wait_for()
137143
nothing
138144
end
139145

@@ -147,13 +153,15 @@ To automaticially create commands see [`dump_app_state()`](@ref).
147153
function set_timeseries!(key; selcomp = NotSpecified(),
148154
states = NotSpecified(),
149155
rel = NotSpecified())
156+
wait_for()
150157
if !haskey(appstate().tsplots[], key)
151158
appstate().tsplots[][key] = TimeseriesPlot()
152159
end
153160
tsplot = appstate().tsplots[][key]
154161
set_maybe!(tsplot.selcomp, selcomp)
155162
set_maybe!(tsplot.states, states)
156163
set_maybe!(tsplot.rel, rel)
164+
wait_for()
157165
nothing
158166
end
159167

@@ -166,8 +174,8 @@ Defines timeseries, where `tsarray` is an array of timeseries keyword arguments
166174
To automaticially create commands see [`dump_app_state()`](@ref).
167175
"""
168176
function define_timeseries!(tsarray)
177+
wait_for()
169178
if length(tsarray) != length(appstate().tsplots[])
170-
@warn "Due to current limitations, you need to reload the page if the number of timeseries plots changes"
171179
empty!(appstate().tsplots[])
172180
tskeys = [gendomid("ts") for _ in tsarray]
173181
else
@@ -176,6 +184,8 @@ function define_timeseries!(tsarray)
176184
for (key, tsargs) in zip(tskeys, tsarray)
177185
set_timeseries!(key; tsargs...)
178186
end
187+
notify(appstate().tsplots)
188+
wait_for()
179189
nothing
180190
end
181191

@@ -186,18 +196,18 @@ Generate a list of [`set_sol!`](@ref), [`set_state!`](@ref), [`set_graphplot!`](
186196
commands to recreate the current appstate.
187197
The intended usecase is to quickly recreate "starting points" for interactive exploration.
188198
"""
189-
function dump_app_state()
190-
appstate()
191-
println("To recreate the current state, run the following commands:\n")
192-
println(styled"set_sol!({red:sol}) # optional if after inspect(sol)")
193-
println("set_state!(; t=$(appstate().t[]), tmin=$(appstate().tmin[]), tmax=$(appstate().tmax[]))")
199+
function dump_app_state(io=stdout)
200+
wait_for()
201+
println(io, "# To recreate the current state, run the following commands:\n")
202+
println(io, styled"set_sol!({red:sol}) # optional if after inspect(sol)")
203+
println(io, "set_state!(; t=$(appstate().t[]), tmin=$(appstate().tmin[]), tmax=$(appstate().tmax[]))")
194204
gp = appstate().graphplot
195-
println("set_graphplot!(; nstate=$(gp.nstate[]), estate=$(gp.estate[]), nstate_rel=$(gp.nstate_rel[]), estate_rel=$(gp.estate_rel[]), ncolorrange=$(gp.ncolorrange[]), ecolorrange=$(gp.ecolorrange[]))")
196-
println("define_timeseries!([")
205+
println(io, "set_graphplot!(; nstate=$(gp.nstate[]), estate=$(gp.estate[]), nstate_rel=$(gp.nstate_rel[]), estate_rel=$(gp.estate_rel[]), ncolorrange=$(gp.ncolorrange[]), ecolorrange=$(gp.ecolorrange[]))")
206+
println(io, "define_timeseries!([")
197207
for ts in values(appstate().tsplots[])
198208
selstr = replace(repr(ts.selcomp[]), r"^.*\["=>"[")
199-
println(" (; selcomp=$(selstr), states=$(ts.states[]), rel=$(ts.rel[])),")
209+
println(io, " (; selcomp=$(selstr), states=$(ts.states[]), rel=$(ts.rel[])),")
200210
end
201-
println("])")
211+
println(io, "])")
202212
nothing
203213
end

docs/src/inspector.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,32 @@ end
6060
6161
sol = get_sol()
6262
inspect(sol; restart=false, reset=true)
63-
NDI.wait_for()
6463
define_timeseries!([
6564
(; selcomp=[EIndex(i) for i in 1:7], states=[:P])
6665
])
67-
NDI.save_electron_screenshot("screenshot.png") #hide #md
68-
nothing #hide #md
66+
NDI.save_electron_screenshot("screenshot.png") #hide
67+
nothing #hide
6968
```
70-
![screenshot](../screenshot.png)
69+
![screenshot](screenshot.png)
70+
71+
## Programmatric Acces and GUI State manipulation
72+
```@example ndi
73+
set_state!(; t=2.0) #hide
74+
define_timeseries!([ #hide
75+
(; selcomp=[VIndex(i) for i in 1:5], states=[:θ, :ω]) #hide
76+
(; selcomp=[EIndex(i) for i in 1:7], states=[:P]) #hide
77+
]) #hide
78+
dump_app_state()
79+
```
80+
81+
```@example ndi
82+
buf = IOBuffer() #hide
83+
dump_app_state(buf) #hide
84+
code = String(take!(buf)) #hide
85+
inspect(sol; reset=true) #hide
86+
eval(Meta.parse("begin;"*code*"end;")) #hide
87+
NDI.save_electron_screenshot("screenshot2.png") #hide
88+
nothing #hide
89+
```
90+
![screenshot](screenshot2.png)
91+

0 commit comments

Comments
 (0)