Beispiel #1
0
 def test_selection1d_resolves(self):
     points = Points([1, 2, 3])
     Selection1D(source=points)
     plot = bokeh_server_renderer.get_plot(points)
     selected = Selection(indices=[0, 2])
     callback = plot.callbacks[0]
     spec = callback.attributes['index']
     resolved = callback.resolve_attr_spec(spec, selected, model=selected)
     self.assertEqual(resolved, {'id': selected.ref['id'], 'value': [0, 2]})
def mkglyph(x, y, selection):
    r = p.circle(x,
                 y,
                 color='green',
                 size=40,
                 selection_color='red',
                 selection_alpha=0.2,
                 nonselection_color='black')
    r.data_source.selected = Selection(indices=selection)
    return r
Beispiel #3
0
    def _reset(self, cache: CACHE_TYPE):
        fov = self._fov
        if fov is not None and self._idfov != id(fov):
            self._idfov = id(fov)
            self._imagedata(cache)

        cache[self._beadssource].update(self._beadsdata())
        sel = self._beadssource.selected
        good = [self._model.bead] if self._model.bead is not None else []
        if getattr(sel, 'indices', None) != good:
            if sel is None:
                cache[self._beadssource].update(selected=Selection(
                    indices=good))
            else:
                cache[sel].update(indices=good)

        self._calibdata(cache)
Beispiel #4
0
        def update_upon_pixel_selection(attr, old, new):
            """Callback to take action when pixels are selected."""
            # check if a selection was "re-clicked".
            if ((sorted(existing_selection['indices']) == sorted(new.indices))
                    & (new.indices != [])):
                tpf_source.selected = Selection(indices=new.indices[1:])
                existing_selection['indices'] = new.indices[1:]
            else:
                existing_selection['indices'] = new.indices

            if tpf_source.selected.indices != []:
                selected_indices = np.array(tpf_source.selected.indices)
                selected_mask = np.isin(pixel_index_array, selected_indices)
                lc_new = tpf.to_lightcurve(aperture_mask=selected_mask)
                lc_source.data['flux'] = lc_new.flux
                ylims = get_lightcurve_y_limits(lc_source)
                fig_lc.y_range.start = ylims[0]
                fig_lc.y_range.end = ylims[1]
            else:
                lc_source.data['flux'] = lc.flux * 0.0
                fig_lc.y_range.start = -1
                fig_lc.y_range.end = 1
Beispiel #5
0
 def test_server_callback_resolve_attr_spec_source_selected(self):
     source = ColumnDataSource()
     source.selected = Selection(indices=[1, 2, 3])
     msg = Callback.resolve_attr_spec('cb_obj.selected.indices', source)
     self.assertEqual(msg, {'id': source.ref['id'], 'value': [1, 2, 3]})
Beispiel #6
0
 def test_selected_is_readonly(self) -> None:
     ds = bms.ColumnDataSource()
     with pytest.raises(RuntimeError) as e:
         ds.selected = Selection()
         assert str(e).endswith(
             "ColumnDataSource.selected is a readonly property")
def tapped(attr, old, new):
    """
    Arguments: Must be there, are not used.
    Removes lines between nodes and clears the textfields when no nodes
    are selected.
    Creates lines between the selected nodes if 1 node is selected. Adds
    selected node to the selected textfield and the children/parents to
    the children/parents field.
    Removes lines between the nodes if multiple nodes are selected and
    adds them to the selected textfield.
    """
    global start_time
    elapsed_time = time.time()-start_time
    if elapsed_time > 0.5:
        if args.models == 2:
            if Active:
                edges_2.visible = True
            else:
                edges_r.visible = True
        else:
            edges_r.visible = True
        sr.visible = False
        sn.visible = False
        if len(source.selected.indices) == 0:
            selectedTerm.value=''
            parentlist.value=''
            childrenlist.value=''
            if args.models == 2:
                if Active:
                    edges_2.visible = True
                else:
                    edges_r.visible = True
            else:
                edges_r.visible = True
            sr.visible = False
            sn.visible = False
        elif len(source.selected.indices) == 1:
            global linklst
            linklst = []
            selectedData = {'x': [df.loc[source.selected.indices[0]]['X']], 'top': [df.loc[source.selected.indices[0]]['Top']], 'bottom': [df.loc[source.selected.indices[0]]['Bottom']]}
            showSelected.data = selectedData
            parents = getAncestors(source.selected.indices[0])
            children = getDescendents(source.selected.indices[0])
            start_time = time.time()
            select = parents + children
            source.selected = Selection(indices=select)
            linkdata = {'x0': [], 'y0': [], 'x1': [], 'y1': []};
            for i in range(len(linklst)):
                linkdata['x0'].append(source.data.get('X')[linklst[i][0]])
                linkdata['y0'].append(source.data.get('Y')[linklst[i][0]])
                linkdata['x1'].append(source.data.get('X')[linklst[i][1]])
                linkdata['y1'].append(source.data.get('Y')[linklst[i][1]])
            showlinks.data = linkdata
            if args.models == 2:
                if Active:
                    edges_2.visible = False
                else:
                    edges_r.visible = False
            else:
                edges_r.visible = False
            sr.visible = True
            sn.visible = True
            p, c = [], []
            for i in parents:
                p.append(source.data['Term'][i])
            for i in children:
                c.append(source.data['Term'][i])
            del c[0]
            selectedTerm.value=p.pop(0)
            parentlist.value=', '.join(p)
            childrenlist.value=', '.join(c)
            return
        elif len(source.selected.indices) > 1:
            selectedTerm.value=', '.join(df['Term'].iloc[source.selected.indices].tolist())
            parentlist.value=''
            childrenlist.value=''
            if args.models == 2:
                if active:
                    edges_2.visible = True
                else:
                    edges_r.visible = True
            else:
                edges_r.visible = True
            sr.visible = False
            sn.visible = False
        start_time = time.time()
Beispiel #8
0
from __future__ import absolute_import

from bokeh.io import save
from bokeh.models import ColumnDataSource, DataTable, TableColumn, Selection

data = dict(x=list(range(10)))
selected = Selection(indices=[1, 2])
source = ColumnDataSource(data=data, selected=selected)
columns = [TableColumn(field="x", title="X")]
data_table = DataTable(source=source, columns=columns)

save(data_table)