|
9 | 9 | from bokeh.layouts import column, row |
10 | 10 | from bokeh.models import ( |
11 | 11 | AdaptiveTicker, |
| 12 | + CheckboxGroup, |
| 13 | + ColumnDataSource, |
12 | 14 | CustomJS, |
13 | 15 | CustomJSTickFormatter, |
14 | 16 | Div, |
@@ -133,8 +135,12 @@ def create_plot(interactive=False): |
133 | 135 | toolbar_location="left", |
134 | 136 | tools="", |
135 | 137 | ) |
| 138 | + |
| 139 | + source = ColumnDataSource(time_data) |
| 140 | + original = ColumnDataSource(time_data) |
| 141 | + |
136 | 142 | 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 |
138 | 144 | ) |
139 | 145 | legend_items = [] |
140 | 146 | for r in renderers1: |
@@ -198,6 +204,32 @@ def create_plot(interactive=False): |
198 | 204 | ) |
199 | 205 | p1.js_on_event(events.DoubleTap, toggle_legend_js) |
200 | 206 |
|
| 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 | + |
201 | 233 | p2 = figure( |
202 | 234 | y_range=convert_list_to_string(size_data[size_structure[0]]), |
203 | 235 | x_range=(0, max_result_size), |
@@ -250,7 +282,7 @@ def create_plot(interactive=False): |
250 | 282 | p2.yaxis.minor_tick_line_color = None |
251 | 283 | p2.yaxis.major_label_standoff = 15 |
252 | 284 | p2.sizing_mode = "scale_both" |
253 | | - both_plots = row(p1, p2) |
| 285 | + both_plots = row(chkbxgrp, p1, p2) |
254 | 286 | both_plots.sizing_mode = "scale_both" |
255 | 287 | vercel_logo = """ |
256 | 288 | <svg width="209" height="40" viewBox="0 0 209 40" fill="none" xmlns="http://www.w3.org/2000/svg"> |
|
0 commit comments