Skip to content

Commit 938c6fa

Browse files
committed
add help bubbles on cards
1 parent 847197b commit 938c6fa

File tree

5 files changed

+150
-24
lines changed

5 files changed

+150
-24
lines changed

NetworkDynamicsInspector/assets/app.css

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ body {
1313
box-sizing: border-box;
1414
}
1515

16+
span {
17+
font-size: 12px;
18+
}
19+
1620
.maingrid {
1721
display: grid;
1822
grid-template-columns: min-content auto;
@@ -24,7 +28,7 @@ body {
2428
/* https://stackoverflow.com/questions/70802682/parents-overflowhidden-doesnt-show-childs-box-shadow */
2529
/* to the sides we only go +- 5 px (padding of body)*/
2630
.graphplot-col{
27-
overflow: hidden; /* otherwise axis won't shrink */
31+
/* overflow: hidden; /\* otherwise axis won't shrink *\/ */
2832
margin:-10px -10px -10px -5px; /* t r b l */
2933
padding:10px 10px 10px 5px;
3034
}
@@ -42,6 +46,7 @@ body {
4246

4347
.bonito-card {
4448
margin: 5px !important;
49+
position:relative;
4550
}
4651

4752
.graphplot-card {
@@ -163,3 +168,75 @@ button{
163168
padding: 5px !important;
164169
padding-bottom: 3px !important;
165170
}
171+
172+
173+
.help-icon {
174+
position: absolute;
175+
/* text-shadow: 0 0 1px #999999; */
176+
color: #999999;
177+
top: 0px;
178+
left: 0px;
179+
width: 20px;
180+
height: 20px;
181+
min-width: 0;
182+
min-height: 0;
183+
border-width: 0;
184+
box-shadow: none;
185+
/* background-color: #333; */
186+
padding: 0;
187+
margin: 0;
188+
text-align: center;
189+
font-size: 10px;
190+
cursor: pointer;
191+
display: flex; /* Use flexbox for centering */
192+
align-items: center; /* Vertically center */
193+
justify-content: center; /* Horizontally center */
194+
}
195+
196+
.timeseries-card .help-icon {
197+
display:none;
198+
}
199+
.timeseries-card.active-tseries .help-icon {
200+
display:flex;
201+
}
202+
203+
.tooltip.help-text {
204+
position: absolute;
205+
top: 5px; /* Adjust based on the size of the icon */
206+
left: 5px;
207+
width: 200px; /* Adjust as needed */
208+
white-space: normal; /* Allow text to wrap */
209+
word-wrap: break-word; /* Break long words if necessary */
210+
}
211+
212+
.tooltip {
213+
display: none; /* Initially hidden */
214+
position: absolute;
215+
background-color: rgba(51, 51, 51, 0.99); /* Slightly transparent */
216+
color: white;
217+
padding: 5px 5px;
218+
border-radius: 5px;
219+
font-size: 12px;
220+
white-space: normal; /* Allow text to wrap */
221+
z-index: 1000; /* Ensure it's above other elements */
222+
}
223+
224+
.tooltip ul {
225+
margin: 0; /* Remove extra padding for list items */
226+
padding-left: 10px; /* Adjust as needed for bullet alignment */
227+
}
228+
229+
.tooltip li {
230+
padding-left: 0; /* Remove extra padding for list items */
231+
}
232+
233+
.tooltip.gp-tooltip {
234+
font-family: monospace;
235+
pointer-events: none;
236+
transform: translate(12px, 12px); /* Offset from cursor */
237+
white-space: normal; /* Allow text to wrap */
238+
}
239+
240+
.help-icon:hover + .help-text {
241+
display: block; /* Show on hover */
242+
}

NetworkDynamicsInspector/src/NetworkDynamicsInspector.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export set_sol!, set_state!, set_graphplot!, set_timeseries!, define_timeseries!
6363
ecolorscheme::Observable{ColorScheme} = ColorSchemes.coolwarm
6464
_selcomp::Observable{Vector{SymbolicCompIndex}} = SymbolicCompIndex[]
6565
_hoverel::Observable{Union{SymbolicCompIndex,Nothing}} = nothing
66-
_lastclickel::Observable{Union{SymbolicCompIndex,Nothing}} = nothing
66+
_lastclickel::Observable{Union{SymbolicCompIndex,Nothing}} = VIndex(1)
6767
end
6868
function GraphPlot(sol)
6969
nw = extract_nw(sol)
@@ -475,16 +475,26 @@ function timeslider_card(app)
475475
nothing
476476
end
477477
t_slider = ContinuousSlider(twindow, app.t; arrowkeys=true)
478+
479+
help = HoverHelp(html"""
480+
<ul>
481+
<li>Adjust the time for the graph coloring.</li>
482+
<li>Use <strong>Arrow Keys</strong> to adjust the time in small increments.</li>
483+
<li>Use <strong>Shift + Arrow Keys</strong> to adjust the time in larger increments.</li>
484+
<li>Use second slider to adjust the time window (i.e. to focus on a specific timeframe in the plots below)</li>
485+
<ul>
486+
""")
487+
478488
Card(
479-
Grid(
489+
[Grid(
480490
DOM.span("Time"), t_slider, RoundedLabel(t_slider.value_r),
481491
RoundedLabel(tw_slider.value_l; style=Styles("text-align"=>"right")),
482492
tw_slider,
483493
RoundedLabel(tw_slider.value_r; style=Styles("text-align"=>"left"));
484494
columns="70px auto 70px",
485495
justify_content="begin",
486496
align_items="center",
487-
);
497+
), help];
488498
class="bonito-card timeslider-card"
489499
);
490500
end
@@ -521,8 +531,14 @@ function element_info_card(app, session)
521531
"""
522532
Bonito.evaljs(session, js)
523533

534+
help = HoverHelp(html"""
535+
Show details on last clicked element.
536+
<strong>Shift + Click</strong> element in graphplot to update details pane
537+
without adding/removing timeseries.
538+
""")
539+
524540
Card(
525-
DOM.div(;id="element-info-box");
541+
[DOM.div(;id="element-info-box"), help];
526542
class="bonito-card element-info-card resize-with-gp"
527543
)
528544
end

NetworkDynamicsInspector/src/graphplot.jl

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function graphplot_card(app, session)
136136
// Create tooltip element
137137
const tooltip = document.createElement("div");
138138
tooltip.classList.add("tooltip"); // Apply styles from CSS
139+
tooltip.classList.add("gp-tooltip"); // Apply styles from CSS
139140
document.body.appendChild(tooltip);
140141
141142
// let tooltipTimeout; // Store timeout reference
@@ -212,7 +213,14 @@ function graphplot_card(app, session)
212213
register_interaction!(ax, :edgeclick, ech)
213214
register_interaction!(ax, :edgehover, ehh)
214215

215-
Card(fig; class="bonito-card graphplot-card")
216+
help = HoverHelp(html"""
217+
<ul>
218+
<li><strong>Click</strong> on a node or edge to select it for timeseries plotting (highlighted plot).</li>
219+
<li><strong>Shift + Click</strong>. only update the element info pane.</li>
220+
<li><strong>Ctrl + Click</strong> resets axis after zoom</li>
221+
</ul>
222+
""")
223+
Card([fig, help]; class="bonito-card graphplot-card")
216224
end
217225
function _gracefully_extract_states!(vec, sol, t, idxs, rel)
218226
isvalid(s) = SII.is_variable(sol, s) || SII.is_parameter(sol, s) || SII.is_observed(sol, s)
@@ -354,18 +362,26 @@ function gpstate_control_card(app, type)
354362

355363
cslider = ContinuousSlider(maxrange, thumb_l, thumb_r)
356364

357-
Card(
358-
DOM.div(
359-
selector,
360-
DOM.div(fig; style=Styles("height" => "40px")),
361-
# fig,
362-
# RoundedLabel(@lift $maxrange[1]; style=Styles("text-align"=>"right")),
363-
cslider,
364-
# RoundedLabel(@lift $maxrange[2]; style=Styles("text-align"=>"left"));
365-
class="gpstate-control-card-content",
366-
);
367-
class
368-
)
365+
childs = Any[DOM.div(
366+
selector,
367+
DOM.div(fig; style=Styles("height" => "40px")),
368+
# fig,
369+
# RoundedLabel(@lift $maxrange[1]; style=Styles("text-align"=>"right")),
370+
cslider,
371+
# RoundedLabel(@lift $maxrange[2]; style=Styles("text-align"=>"left"));
372+
class="gpstate-control-card-content",
373+
)]
374+
if type == :vertex
375+
help = HoverHelp(html"""
376+
Select the state to color the graphplot.
377+
<ul>
378+
<li>Use slider to adjust the color range. <strong>Shift</strong> while draggin the knobs to scale symmetricly</li>
379+
<li>Toggle <strong>Rel to u0</strong> to color by the difference to the initial state.</li>
380+
</ul>
381+
""")
382+
push!(childs, help)
383+
end
384+
Card(childs; class)
369385
end
370386

371387
function _maxrange(sol, idxs, rel)

NetworkDynamicsInspector/src/timeseries.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ function timeseries_card(app, key, session)
135135
T=Symbol,
136136
id=gendomid("statesel"))
137137

138-
reset_color_button = Bonito.Button("Reset Color", style=Styles("margin-left"=>"10px"))
139-
on(reset_color_button.value) do _
138+
reset_style_button = Bonito.Button("Reset Styles", style=Styles("margin-left"=>"10px"))
139+
on(reset_style_button.value) do _
140140
empty!(color_cache)
141141
empty!(linestyle_cache)
142142
notify(tsplot.selcomp)
@@ -149,7 +149,7 @@ function timeseries_card(app, key, session)
149149

150150
comp_state_sel_dom = Grid(
151151
DOM.span("Components"), comp_sel,
152-
DOM.div(reset_color_button, reset_axis_button, rel_toggle; style=Styles("grid-row"=>"1/3", "grid-column"=>"3")),
152+
DOM.div(reset_style_button, reset_axis_button, rel_toggle; style=Styles("grid-row"=>"1/3", "grid-column"=>"3")),
153153
DOM.span("States"), state_sel;
154154
columns = "min-content auto min-content",
155155
align_items = "center",
@@ -324,7 +324,7 @@ function timeseries_card(app, key, session)
324324
datahash = Ref{UInt64}()
325325
onany(ts, valid_idxs, tsplot.rel, app.sol; update=true) do _ts, _valid_idxs, _rel, _sol
326326
# only replot if the data has actually changed
327-
newhash = hash((_ts, _valid_idxs, _rel, _sol))
327+
newhash = hash((_ts, _valid_idxs, _rel, _sol, linestyle_cache, color_cache))
328328
newhash == datahash[] && return
329329
datahash[] = newhash
330330

@@ -399,13 +399,25 @@ function timeseries_card(app, key, session)
399399
cardclass *= " active-tseries"
400400
end
401401

402+
help = HoverHelp(html"""
403+
Select the components and states to plot.
404+
<ul>
405+
<li><strong>Click</strong> on the plot to set the time.</li>
406+
<li><strong>Click and Drag</strong> to zoom in.</li>
407+
<li><strong>Ctrl + Click</strong> to reset zoom.</li>
408+
<li>Use timeslider to change the x-axis limits.</li>
409+
<li>Toggle "Rel to u0" to plot the difference to the initial value.</li>
410+
<li>Click "Reset Styles" to pick colors and linestyles in order of apperance.</li>
411+
</ul>
412+
""")
413+
402414
card = Card(
403-
DOM.div(
415+
[DOM.div(
404416
comp_state_sel_dom,
405417
DOM.div(fig; class="timeseries-axis-container"),
406418
closebutton(app, key);
407419
class="timeseries-card-container"
408-
);
420+
), help];
409421
class=cardclass,
410422
id=key
411423
)

NetworkDynamicsInspector/src/widgets.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,3 +896,8 @@ function Bonito.jsrender(session::Session, toggle::ToggleSwitch)
896896
)
897897
Bonito.jsrender(session, container)
898898
end
899+
900+
function HoverHelp(help)
901+
[DOM.div("?", class="help-icon"),
902+
DOM.div(help, class="help-text tooltip")]
903+
end

0 commit comments

Comments
 (0)