[KomaUI Plotting] obj_ui[] does not draw on first time updated. Need to press :rho or other option.
What happened?
obj_ui[] does not draw on first time updated:
Need to press :rho or other button option:
Environment
OS x86_64-linux-gnu
Julia 1.10.4
KomaMRIPlots 0.8.3
KomaMRIFiles 0.8.2
KomaMRI 0.8.2
KomaMRICore 0.8.3
KomaMRIBase 0.8.4
obj_ui[]=brain_phantom2D();
Has same behavior. No draw the first time.
obj_ui[]=pelvis_phantom2D()
Also does the same thing, so consistent. Same code or same code called?
I will need to look into this, in KomaUI.jl we define the callbacks as follows:
on((obj) -> view_ui!(obj, w, seq_ui[], widgets_button_obj; key=:ρ, darkmode), obj_ui)
for (widget_button, key) in zip(widgets_button_obj, fieldnames_obj)
on((cnt) -> view_ui!(cnt, w, obj_ui[], seq_ui[], widgets_button_obj; key, darkmode), widget_button)
end
So, for example, the first one means that each time obj_ui changes the view_ui! function is triggered. I believe the problem are the buttons, I am fixing this locally.
After looking into it, that wasn't the problem. There are two things that I didn't realize:
-
plot_phantom_mapwas changed to usePlotinstead of the backend-agnosticplot_koma, and that generates this problem. - If
view_2D=true, the plot usesscatterinstead ofscattergl, which is very slow.
@pvillacorta could you fix this?
@pvillacorta Also, it seems that plotting a phantom with too many spins shows fewer spins, with no warning telling the user that it is happening.
@pvillacorta @cncastillo
It does seem to do the warning the first time only, which is probably related to the calling issues mentioned in: https://github.com/JuliaHealth/KomaMRI.jl/issues/407#issuecomment-2171855179
julia> obj_ui[]=brain_phantom3D(;ss=2)
┌ Warning: For performance reasons, the number of displayed spins was capped to `max_spins`=100000.
└ @ KomaMRIPlots ~/src/KomaMRI/KomaMRIPlots/src/ui/DisplayFunctions.jl:1080
See maxlog=1 in line 1080 of https://github.com/JuliaHealth/KomaMRI.jl/pull/387/commits/592b85f345fa7e3701f436ef985b25a5d2043eaf. That is why the message only displays once
plot_phantom_mapwas changed to usePlotinstead of the backend-agnosticplot_koma, and that generates this problem.
The solution is not as easy as using plot_koma again, since PlotlyJS.plot (which is called by plot_koma when using the Plotly backend) does not support frames for animations. It looks like a bug from PlotlyJS. See:
- https://discourse.julialang.org/t/plotlyjs-jl-animation/70058/9
- https://community.plotly.com/t/adding-an-animation-button-to-a-julia-plot-with-slider/73404/2
- If
view_2D=true, the plot usesscatterinstead ofscattergl, which is very slow.
Solved in #413, as well as the maxlog issue
https://github.com/JuliaHealth/KomaMRI.jl/pull/413#issuecomment-2189778867