Skip to content

Commit de7de06

Browse files
committed
add close button
1 parent 3daa9fa commit de7de06

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

NetworkDynamicsInspector/assets/app.css

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ body {
7474
.timeseries-card {
7575
resize: vertical;
7676
overflow: hidden;
77-
/* grid-column: 2; */
77+
position: relative; /* for close button */
7878
}
7979
.timeseries-card.active-tseries {
8080
box-shadow: 0 4px 8px rgba(0.0, 0.0, 51.0, 0.65);
@@ -92,6 +92,25 @@ body {
9292
flex-grow: 1;
9393
overflow:hidden;
9494
}
95+
button.close-button {
96+
position: absolute;
97+
top: 0;
98+
right: 0;
99+
width: 20px;
100+
height: 20px;
101+
min-width: 0;
102+
min-height: 0;
103+
border-width: 0;
104+
box-shadow: none;
105+
background-color: transparent;
106+
padding: 0;
107+
margin: 0;
108+
}
109+
button.close-button:hover{
110+
box-shadow: none;
111+
background-color: transparent;
112+
text-shadow: 0 0 1px #000;
113+
}
95114

96115
.tooltip {
97116
position: absolute;

NetworkDynamicsInspector/src/timeseries.jl

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ function timeseries_col(app, session)
4040
"""
4141
Bonito.onload(session, col, onload_js)
4242

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+
4365
return col
4466
end
4567

@@ -79,7 +101,7 @@ function add_timeseries_button(app)
79101
button = Bonito.Button("Add Timeseries", class="add-ts-button")
80102
on(button.value) do _
81103
newkey = free_ts_key()
82-
@info "TS: Add Timeseries button clicked. Add $newkey"
104+
@debug "TS: Add Timeseries button clicked. Add $newkey"
83105
app.tsplots[][newkey] = TimeseriesPlot()
84106
notify(app.tsplots)
85107
end
@@ -386,7 +408,8 @@ function timeseries_card(app, key, session)
386408
card = Card(
387409
DOM.div(
388410
comp_state_sel_dom,
389-
DOM.div(fig; class="timeseries-axis-container");
411+
DOM.div(fig; class="timeseries-axis-container"),
412+
closebutton(app, key);
390413
class="timeseries-card-container"
391414
);
392415
class=cardclass,
@@ -406,6 +429,15 @@ function timeseries_card(app, key, session)
406429

407430
return card
408431
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
409441

410442
function _refine_time_limits!(ts, sollims, axlims)
411443
FOCUS = 900

0 commit comments

Comments
 (0)