Skip to content

Commit b427403

Browse files
committed
[MISC] Add checkbox
1 parent f574909 commit b427403

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

scripts/plot.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from bokeh.layouts import row
1010
from bokeh.models import (
1111
AdaptiveTicker,
12+
CheckboxGroup,
13+
ColumnDataSource,
1214
CustomJS,
1315
CustomJSTickFormatter,
1416
FactorRange,
@@ -132,9 +134,11 @@ def create_plot(interactive=False):
132134
toolbar_location="left",
133135
tools="",
134136
)
135-
renderers1 = p1.hbar_stack(
136-
stackers=time_structure[1:], y=time_structure[0], height=0.4, source=(time_data), color=Set2_6
137-
)
137+
138+
source = ColumnDataSource(time_data)
139+
original = ColumnDataSource(time_data)
140+
141+
renderers1 = p1.hbar_stack(stackers=time_structure[1:], y=time_structure[0], height=0.4, source=source, color=Set2_6)
138142
legend_items = []
139143
for r in renderers1:
140144
key, tag = r.name, r.name
@@ -197,6 +201,32 @@ def create_plot(interactive=False):
197201
)
198202
p1.js_on_event(events.DoubleTap, toggle_legend_js)
199203

204+
chkbxgrp = CheckboxGroup(labels=time_structure[1:], active=list(range(len(time_structure[1:]))))
205+
callback = CustomJS(
206+
args={"source": source, "original": original},
207+
code="""
208+
var active_values = cb_obj.active.map(x => cb_obj.labels[x]);
209+
var number_of_entries = cb_obj.labels.length;
210+
211+
for (var i = 0; i < number_of_entries; i++)
212+
{
213+
var value = cb_obj.labels[i];
214+
if (active_values.indexOf(value) >= 0)
215+
{
216+
source.data[value] = original.data[value];
217+
}
218+
else
219+
{
220+
delete source.data[value];
221+
}
222+
}
223+
224+
source.change.emit();
225+
console.log("callback completed");
226+
""",
227+
)
228+
chkbxgrp.js_on_change("active", callback)
229+
200230
p2 = figure(
201231
y_range=convert_list_to_string(size_data[size_structure[0]]),
202232
x_range=(0, max_result_size),
@@ -249,7 +279,7 @@ def create_plot(interactive=False):
249279
p2.yaxis.minor_tick_line_color = None
250280
p2.yaxis.major_label_standoff = 15
251281
p2.sizing_mode = "scale_both"
252-
both_plots = row(p1, p2)
282+
both_plots = row(chkbxgrp, p1, p2)
253283
both_plots.sizing_mode = "scale_both"
254284
tabs.append(TabPanel(child=both_plots, title=files_names_titles[i]))
255285
if interactive:

0 commit comments

Comments
 (0)