1
+ function timeseries_col (app, session)
2
+ col = DOM. div (
3
+ timeslider_card (app),
4
+ timeseries_cards (app, session),
5
+ add_timeseries_button (app),
6
+ class= " timeseries-col"
7
+ )
8
+
9
+ # add js to update the active ts plot
10
+ onload_js = js """
11
+ (tscol ) => {
12
+ tscol .addEventListener (" click" , function (event ) {
13
+ // Find the closest .timeseries-card ancestor of the clicked element
14
+ const clickedCard = event .target .closest (' .timeseries-card' );
15
+
16
+ // If a .timeseries-card was found, handle the click
17
+ if (clickedCard) {
18
+ // console.log("click on timeseries card", clickedCard.id);
19
+
20
+ // Notify the app with the id of the clicked card
21
+ $ (app .active_tsplot ).notify (clickedCard .id );
22
+
23
+ // Remove "active-tseries" class from all .timeseries-card elements
24
+ document .querySelectorAll (" .timeseries-card" ).forEach (element => {
25
+ element .classList .remove (" active-tseries" );
26
+ });
27
+
28
+ // Add "active-tseries" class to the clicked card
29
+ clickedCard .classList .add (" active-tseries" );
30
+ }
31
+ }, { capture: true });
32
+
33
+ function triggerWindowResize () {
34
+ window .dispatchEvent (new Event (' resize' ));
35
+ }
36
+ const triggerWindowResize_throttled = Bonito .throttle_function (triggerWindowResize, 100 );
37
+ const resizeObserver = new ResizeObserver (triggerWindowResize_throttled);
38
+ resizeObserver .observe (tscol);
39
+ }
40
+ """
41
+ Bonito. onload (session, col, onload_js)
42
+
43
+ return col
44
+ end
45
+
1
46
function timeseries_cards (app, session)
2
47
cards = OrderedDict {String,Bonito.Hyperscript.Node{Bonito.Hyperscript.HTMLSVG}} ()
3
48
container = Observable {Bonito.Hyperscript.Node{Bonito.Hyperscript.HTMLSVG}} ()
@@ -27,7 +72,18 @@ function timeseries_cards(app, session)
27
72
app. graphplot. _selcomp[] = activesel
28
73
end
29
74
30
- return container[]
75
+ return container
76
+ end
77
+
78
+ function add_timeseries_button (app)
79
+ button = Bonito. Button (" Add Timeseries" , class= " add-ts-button" )
80
+ on (button. value) do _
81
+ newkey = free_ts_key ()
82
+ @info " TS: Add Timeseries button clicked. Add $newkey "
83
+ app. tsplots[][newkey] = TimeseriesPlot ()
84
+ notify (app. tsplots)
85
+ end
86
+ return button
31
87
end
32
88
33
89
function timeseries_card (app, key, session)
@@ -213,7 +269,7 @@ function timeseries_card(app, key, session)
213
269
Bonito. evaljs (session, js)
214
270
215
271
fig, ax = with_theme (apptheme ()) do
216
- fig = Figure ()
272
+ fig = Figure (size = ( 100 , 400 ) )
217
273
ax = Axis (fig[1 , 1 ])
218
274
fig, ax
219
275
end
@@ -333,10 +389,10 @@ function timeseries_card(app, key, session)
333
389
DOM. div (fig; class= " timeseries-axis-container" );
334
390
class= " timeseries-card-container"
335
391
);
336
- class= cardclass
392
+ class= cardclass,
393
+ id= key
337
394
)
338
395
339
-
340
396
# trigger plot on document ready
341
397
jqdocument = Bonito. JSString (raw " $(document)" )
342
398
trigger_plot = js """
@@ -348,31 +404,6 @@ function timeseries_card(app, key, session)
348
404
"""
349
405
Bonito. evaljs (session, trigger_plot)
350
406
351
- # on click set active-tseries class
352
- onload_js = js """
353
- (card ) => {
354
- card .addEventListener (" click" , function (event ) {
355
- $ (app .active_tsplot ).notify ($ (key));
356
-
357
- document .querySelectorAll (" .timeseries-card" ).forEach (element => {
358
- element .classList .remove (" active-tseries" );
359
- });
360
-
361
- // Add "active-tseries" to the given target element
362
- card .classList .add (" active-tseries" );
363
- }, { capture: true });
364
-
365
-
366
- function triggerWindowResize () {
367
- window .dispatchEvent (new Event (' resize' ));
368
- }
369
- const triggerWindowResize_throttled = Bonito .throttle_function (triggerWindowResize, 100 );
370
- const resizeObserver = new ResizeObserver (triggerWindowResize_throttled);
371
- resizeObserver .observe (card);
372
- }
373
- """
374
- Bonito. onload (session, card, onload_js)
375
-
376
407
return card
377
408
end
378
409
0 commit comments