bokeh.models.CheckboxButtonGroup

Here are the examples of the python api bokeh.models.CheckboxButtonGroup taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

0 View Source File : config.py
License : GNU General Public License v3.0
Project Creator : happydasch

    def _create_plotgroup_config(self):
        self.plotgroup = []
        self.plotgroup_chk = defaultdict(list)
        self.plotgroup_objs = defaultdict(list)
        self.plotgroup_text = None

        def active_obj(obj, selected):
            if not len(selected) or obj.plotinfo.plotid in selected:
                return True
            return False

        title = Paragraph(
            text='Plot Group',
            css_classes=['config-title'])
        options = []

        # get client plot group selection
        if self._client.plotgroup != '':
            selected_plot_objs = self._client.plotgroup.split(',')
        else:
            selected_plot_objs = []

        # get all plot objects
        self.plotgroup_objs = get_plotobjs(
            self._figurepage.strategy,
            order_by_plotmaster=False)

        # create plotgroup checkbox buttons
        for d in self.plotgroup_objs:
            # generate master chk
            master_chk = None
            if not isinstance(d, bt.Strategy):
                active = []
                if active_obj(d, selected_plot_objs):
                    active.append(0)
                    self._add_to_plotgroup(d)
                master_chk = CheckboxButtonGroup(
                    labels=[obj2label(d)], active=active)

            # generate childs chk
            childs_chk = []
            objsd = self.plotgroup_objs[d]
            # sort child objs by type
            objsd.sort(key=lambda x: (FigureType.get_type(x).value))
            # split objs into chunks and store chk
            objsd = [objsd[i:i + 3] for i in range(0, len(objsd), 3)]
            for x in objsd:
                childs = []
                active = []
                for i, o in enumerate(x):
                    childs.append(obj2label(o))
                    if active_obj(o, selected_plot_objs):
                        active.append(i)
                        self._add_to_plotgroup(o)
                # create a chk for every chunk
                if len(childs):
                    chk = CheckboxButtonGroup(
                        labels=childs, active=active)
                    chk.on_change(
                        'active',
                        partial(
                            self._on_update_plotgroups,
                            chk=chk,
                            master=d,
                            childs=x))
                    # if master is not active, disable childs
                    if master_chk and not len(master_chk.active):
                        chk.disabled = True
                    childs_chk.append(chk)
                self.plotgroup_chk[d].append(x)

            # append title for master (this will also include strategy)
            if len(self.plotgroup_objs[d]):
                options.append(Paragraph(text=f'{obj2label(d)}:'))
            # append master_chk and childs_chk to layout
            if master_chk:
                master_chk.on_change(
                    'active',
                    partial(
                        self._on_update_plotgroups,
                        # provide all related chk to master
                        chk=[master_chk] + childs_chk,
                        master=d))
                options.append(master_chk)
            for c in childs_chk:
                options.append(c)

        # text input to display selection
        self.plotgroup_text = TextInput(
            value=','.join(self.plotgroup),
            disabled=True)
        options.append(Paragraph(text='Plot Group Selection:'))
        options.append(self.plotgroup_text)

        return column([title] + options)

    def _add_to_plotgroup(self, obj):

0 View Source File : base.py
License : MIT License
Project Creator : phurwicz

    def _setup_subset_toggle(self):
        """
        ???+ note "Create a group of buttons for toggling which data subsets to show."
        """
        from bokeh.models import CheckboxButtonGroup, Div
        from bokeh.layouts import column

        data_keys = list(self.__class__.SUBSET_GLYPH_KWARGS.keys())
        self.data_key_button_group = CheckboxButtonGroup(
            labels=data_keys, active=list(range(len(data_keys)))
        )
        self.data_key_button_group_help = Div(text="Toggle data subset display")
        self.subset_toggle_widget_column = column(
            self.data_key_button_group_help, self.data_key_button_group
        )

        def update_data_key_display(active):
            visible_keys = {self.data_key_button_group.labels[idx] for idx in active}
            for _renderer in self.figure.renderers:
                # if the renderer has a name "on the list", update its visibility
                if _renderer.name in self.__class__.SUBSET_GLYPH_KWARGS.keys():
                    _renderer.visible = _renderer.name in visible_keys

        # store the callback (useful, for example, during automated tests) and link it
        self._callback_subset_display = lambda: update_data_key_display(
            self.data_key_button_group.active
        )
        self.data_key_button_group.on_click(update_data_key_display)

    def _setup_axes_dropdown(self):