Skip to content

Commit 5233520

Browse files
committed
[MISC] Add checkbox
1 parent b796931 commit 5233520

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

scripts/plot.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from bokeh.layouts import column, row
1010
from bokeh.models import (
1111
AdaptiveTicker,
12+
CheckboxGroup,
13+
ColumnDataSource,
1214
CustomJS,
1315
CustomJSTickFormatter,
1416
Div,
@@ -133,8 +135,12 @@ def create_plot(interactive=False):
133135
toolbar_location="left",
134136
tools="",
135137
)
138+
139+
source = ColumnDataSource(time_data)
140+
original = ColumnDataSource(time_data)
141+
136142
renderers1 = p1.hbar_stack(
137-
stackers=time_structure[1:], y=time_structure[0], height=0.4, source=(time_data), color=Set2_6
143+
stackers=time_structure[1:], y=time_structure[0], height=0.4, source=source, color=Set2_6
138144
)
139145
legend_items = []
140146
for r in renderers1:
@@ -198,6 +204,32 @@ def create_plot(interactive=False):
198204
)
199205
p1.js_on_event(events.DoubleTap, toggle_legend_js)
200206

207+
chkbxgrp = CheckboxGroup(labels=time_structure[1:], active=list(range(len(time_structure[1:]))))
208+
callback = CustomJS(
209+
args={"source": source, "original": original},
210+
code="""
211+
var active_values = cb_obj.active.map(x => cb_obj.labels[x]);
212+
var number_of_entries = cb_obj.labels.length;
213+
214+
for (var i = 0; i < number_of_entries; i++)
215+
{
216+
var value = cb_obj.labels[i];
217+
if (active_values.indexOf(value) >= 0)
218+
{
219+
source.data[value] = original.data[value];
220+
}
221+
else
222+
{
223+
delete source.data[value];
224+
}
225+
}
226+
227+
source.change.emit();
228+
console.log("callback completed");
229+
""",
230+
)
231+
chkbxgrp.js_on_change("active", callback)
232+
201233
p2 = figure(
202234
y_range=convert_list_to_string(size_data[size_structure[0]]),
203235
x_range=(0, max_result_size),
@@ -250,7 +282,7 @@ def create_plot(interactive=False):
250282
p2.yaxis.minor_tick_line_color = None
251283
p2.yaxis.major_label_standoff = 15
252284
p2.sizing_mode = "scale_both"
253-
both_plots = row(p1, p2)
285+
both_plots = row(chkbxgrp, p1, p2)
254286
both_plots.sizing_mode = "scale_both"
255287
vercel_logo = """
256288
<svg width="209" height="40" viewBox="0 0 209 40" fill="none" xmlns="http://www.w3.org/2000/svg">

0 commit comments

Comments
 (0)