@@ -40,6 +40,28 @@ function timeseries_col(app, session)
40
40
"""
41
41
Bonito. onload (session, col, onload_js)
42
42
43
+ # HACK: sometimes, the select2 lib is not available after a tsplots change, in that case, trigger again
44
+ # from js we trigger recreate_dom which notifies the tsplots
45
+ recreate_dom = Observable {Bool} (true )
46
+ on (_-> notify (app. tsplots), recreate_dom)
47
+ jqdocument = Bonito. JSString (raw " $(document)" )
48
+ esc = Bonito. JSString (raw " $" )
49
+ rebuild_dom_hack = js """
50
+ (tscol ) => {
51
+ function dom_changed () {
52
+ // wait for ready then check if defined and recreate
53
+ if (typeof $ (esc).fn .select2 !== ' function' ) {
54
+ console .warn (' Select2 is not defined. Calling replot...' );
55
+ $ (recreate_dom).notify (true );
56
+ }
57
+ }
58
+
59
+ const observer = new MutationObserver (dom_changed);
60
+ observer .observe (tscol, {childList: true , subtree: true });
61
+ }
62
+ """
63
+ Bonito. onload (session, col, rebuild_dom_hack)
64
+
43
65
return col
44
66
end
45
67
@@ -79,7 +101,7 @@ function add_timeseries_button(app)
79
101
button = Bonito. Button (" Add Timeseries" , class= " add-ts-button" )
80
102
on (button. value) do _
81
103
newkey = free_ts_key ()
82
- @info " TS: Add Timeseries button clicked. Add $newkey "
104
+ @debug " TS: Add Timeseries button clicked. Add $newkey "
83
105
app. tsplots[][newkey] = TimeseriesPlot ()
84
106
notify (app. tsplots)
85
107
end
@@ -386,7 +408,8 @@ function timeseries_card(app, key, session)
386
408
card = Card (
387
409
DOM. div (
388
410
comp_state_sel_dom,
389
- DOM. div (fig; class= " timeseries-axis-container" );
411
+ DOM. div (fig; class= " timeseries-axis-container" ),
412
+ closebutton (app, key);
390
413
class= " timeseries-card-container"
391
414
);
392
415
class= cardclass,
@@ -406,6 +429,15 @@ function timeseries_card(app, key, session)
406
429
407
430
return card
408
431
end
432
+ function closebutton (app, key)
433
+ button = Bonito. Button (" ×" , class= " close-button" )
434
+ on (button. value) do _
435
+ @debug " TS: Close button clicked. Remove $key "
436
+ delete! (app. tsplots[], key)
437
+ notify (app. tsplots)
438
+ end
439
+ button
440
+ end
409
441
410
442
function _refine_time_limits! (ts, sollims, axlims)
411
443
FOCUS = 900
0 commit comments