예제 #1
0
class BqplotRectangleMode(InteractCheckableTool):

    icon = 'glue_square'
    tool_id = 'bqplot:rectangle'
    action_text = 'Rectangular ROI'
    tool_tip = 'Define a rectangular region of interest'

    def __init__(self, viewer, **kwargs):

        super().__init__(viewer, **kwargs)

        self.interact = BrushSelector(x_scale=self.viewer.scale_x,
                                      y_scale=self.viewer.scale_y,
                                      color="green")

        self.interact.observe(self.update_selection, "brushing")

    def update_selection(self, *args):
        with self.viewer.output_widget:
            if self.interact.selected_x is not None and self.interact.selected_y is not None:
                x = self.interact.selected_x
                y = self.interact.selected_y
                roi = RectangularROI(xmin=min(x),
                                     xmax=max(x),
                                     ymin=min(y),
                                     ymax=max(y))
                self.viewer.apply_roi(roi)
예제 #2
0
class BqplotRectangleMode(InteractCheckableTool):

    icon = 'glue_square'
    tool_id = 'bqplot:rectangle'
    action_text = 'Rectangular ROI'
    tool_tip = 'Define a rectangular region of interest'

    def __init__(self, viewer, roi=None, finalize_callback=None, **kwargs):

        super().__init__(viewer, **kwargs)

        self.interact = BrushSelector(x_scale=self.viewer.scale_x,
                                      y_scale=self.viewer.scale_y,
                                      color=INTERACT_COLOR)

        if roi is not None:
            self.update_from_roi(roi)

        self.interact.observe(self.update_selection, "brushing")
        self.interact.observe(self.on_selection_change, "selected_x")
        self.interact.observe(self.on_selection_change, "selected_y")
        self.finalize_callback = finalize_callback

    def update_selection(self, *args):
        if self.interact.brushing:
            return
        with self.viewer._output_widget:
            if self.interact.selected_x is not None and self.interact.selected_y is not None:
                x = self.interact.selected_x
                y = self.interact.selected_y
                roi = RectangularROI(xmin=min(x), xmax=max(x), ymin=min(y), ymax=max(y))
                self.viewer.apply_roi(roi)
                if self.finalize_callback is not None:
                    self.finalize_callback()

    def update_from_roi(self, roi):
        with self.viewer._output_widget:
            if isinstance(roi, RectangularROI):
                self.interact.selected_x = [roi.xmin, roi.xmax]
                self.interact.selected_y = [roi.ymin, roi.ymax]
            elif isinstance(roi, PolygonalROI):
                self.interact.selected_x = [np.min(roi.vx), np.max(roi.vx)]
                self.interact.selected_y = [np.min(roi.vy), np.max(roi.vy)]
            else:
                raise TypeError(f'Cannot initialize a BqplotRectangleMode from a {type(roi)}')
            # FIXME: the brush selector does not actually update unless the
            # widget is resized/refreshed, see
            # https://github.com/bloomberg/bqplot/issues/1067

    def on_selection_change(self, *args):
        if self.interact.selected_x is None or self.interact.selected_y is None:
            if self.finalize_callback is not None:
                self.finalize_callback()

    def activate(self):
        with self.viewer._output_widget:
            self.interact.selected_x = None
            self.interact.selected_y = None
        super().activate()
예제 #3
0
    def __init__(self, viewer, **kwargs):

        super().__init__(viewer, **kwargs)

        self.interact = BrushSelector(x_scale=self.viewer.scale_x,
                                      y_scale=self.viewer.scale_y,
                                      color="green")

        self.interact.observe(self.update_selection, "brushing")
예제 #4
0
    def __init__(self, viewer, roi=None, finalize_callback=None, **kwargs):

        super().__init__(viewer, **kwargs)

        self.interact = BrushSelector(x_scale=self.viewer.scale_x,
                                      y_scale=self.viewer.scale_y,
                                      color=INTERACT_COLOR)

        if roi is not None:
            self.update_from_roi(roi)

        self.interact.observe(self.update_selection, "brushing")
        self.interact.observe(self.on_selection_change, "selected_x")
        self.interact.observe(self.on_selection_change, "selected_y")
        self.finalize_callback = finalize_callback
예제 #5
0
    def interaction_map(self):  # , xScale, yScale, fig, mark, deb):

        self.interactions = {}

        xScale = self.xScale  # if xScale is None else xScale
        yScale = self.yScale  # if yScale is None else yScale
        fig = self.fig  # if fig is None else fig
        mark = fig.marks  # if mark is None else mark

        multi_sel = MultiSelector(scale=xScale, marks=mark)
        br_intsel = BrushIntervalSelector(scale=xScale, marks=mark)
        index_sel = IndexSelector(scale=xScale, marks=mark)
        int_sel = FastIntervalSelector(scale=xScale, marks=mark)
        br_sel = BrushSelector(x_scale=xScale, y_scale=yScale, marks=mark, color='red')
        pz = PanZoom(scales={'x': [xScale], 'y': [yScale]})

        self.interactions['Multiple_Brush'] = multi_sel
        self.interactions['BrushX'] = br_intsel
        self.interactions['Fast_Brush'] = int_sel
        self.interactions['Brush'] = br_sel
        self.interactions['Index_Selector'] = index_sel
        self.interactions['Pan_Zoom'] = pz
예제 #6
0
 def _new_interact(self):
     return BrushSelector(x_scale=self.viewer.scale_x,
                          y_scale=self.viewer.scale_y,
                          color=INTERACT_COLOR)
예제 #7
0
파일: cyplot.py 프로젝트: orpheus92/CyQuery
    def interaction_map(self):  # , xScale, yScale, fig, mark, deb):

        self.interactions = {}

        xScale = self.xScale  # if xScale is None else xScale
        yScale = self.yScale  # if yScale is None else yScale
        fig = self.fig  # if fig is None else fig
        mark = fig.marks  # if mark is None else mark

        multi_sel = MultiSelector(scale=xScale, marks=mark)
        br_intsel = BrushIntervalSelector(scale=xScale, marks=mark)
        index_sel = IndexSelector(scale=xScale, marks=mark)
        int_sel = FastIntervalSelector(scale=xScale, marks=mark)
        br_sel = BrushSelector(x_scale=xScale,
                               y_scale=yScale,
                               marks=mark,
                               color='red')
        pz = PanZoom(scales={'x': [xScale], 'y': [yScale]})

        def cb1(change):
            if len(change.new) > 1:
                xr = change.new
                yr = [None, None]
                box = [[xr[0], yr[0]], [xr[1], yr[1]]]
                y = getattr(self, "cbs", None)

                if y is not None:
                    for k in self.cbs:
                        if 'brush' in k:
                            if self.debug:
                                self.deb.value = str(box)
                            cb = self.cbs[k]
                            if not self.dims:
                                cb(box)
                            else:
                                cb(box,
                                   [self.alldims.index(d) for d in self.dims])

            else:
                y = getattr(self, "cbs", None)
                # Single selector should have different cbs

                if y is not None:
                    if 'bar' in self.cbs:
                        cb = self.cbs['bar']
                        if not self.dims:
                            cb(change.new)
                        else:
                            cb(change.new,
                               [self.alldims.index(d) for d in self.dims])

        def cb2(change):
            box = self.interactions['brush']['selector'].selected
            y = getattr(self, "cbs", None)

            if y is not None:
                if 'brush' in self.cbs:
                    if self.debug:
                        self.deb.value = str(box)
                    cb = self.cbs['brush']
                    if not self.dims:
                        cb(box)
                    else:
                        cb(box, [self.alldims.index(d) for d in self.dims])

        def cb3(change):
            newscales = change.new
            y = getattr(self, "cbs", None)

            if y is not None:
                if 'panzoom' in self.cbs:
                    cb = self.cbs['panzoom']
                    cb(newscales['x'], newscales['y'])

        multi_sel.observe(cb1, names=['selected'])
        br_intsel.observe(cb1, names=['selected'])  # 'selected'])
        index_sel.observe(cb1, names=['selected'])
        int_sel.observe(cb1, names=['selected'])
        br_sel.observe(cb2, names=['brushing'])
        pz.observe(cb3, names=['scales'])

        self.interactions['brushes'] = {}
        self.interactions['brushes']['selector'] = multi_sel
        self.interactions['brushes']['icon'] = 'th-large'
        self.interactions['brushes']['tooltip'] = 'Multiple Brushes'
        self.interactions['brushes']['order'] = 0  # '   '
        self.interactions['brushes']['watch'] = 'selected'

        self.interactions['brush_x'] = {}
        self.interactions['brush_x']['selector'] = br_intsel
        self.interactions['brush_x']['icon'] = 'arrows-h'
        self.interactions['brush_x']['tooltip'] = 'Horizontal Brush'
        self.interactions['brush_x']['order'] = 1  # '     '
        self.interactions['brush_x']['watch'] = 'selected'

        self.interactions['brush_fast'] = {}
        self.interactions['brush_fast']['selector'] = int_sel
        self.interactions['brush_fast']['icon'] = 'exchange'
        self.interactions['brush_fast']['tooltip'] = 'Fast Brush'
        self.interactions['brush_fast']['order'] = 3  # '      '
        self.interactions['brush_fast']['watch'] = 'selected'

        self.interactions['brush'] = {}
        self.interactions['brush']['selector'] = br_sel
        self.interactions['brush']['icon'] = 'retweet'
        self.interactions['brush']['tooltip'] = 'Brush'
        self.interactions['brush']['order'] = 4  # '       '
        self.interactions['brush']['watch'] = 'brushing'

        self.interactions['bar'] = {}
        self.interactions['bar']['selector'] = index_sel
        self.interactions['bar']['icon'] = 'mouse-pointer'
        self.interactions['bar']['tooltip'] = 'Single Slider'
        self.interactions['bar']['order'] = 5  # ' '
        self.interactions['bar']['watch'] = 'selected'

        self.interactions['panzoom'] = {}
        self.interactions['panzoom']['selector'] = pz
        self.interactions['panzoom']['icon'] = 'arrows'
        self.interactions['panzoom']['tooltip'] = 'Pan Zoom'
        self.interactions['panzoom']['order'] = 6  # ''
        self.interactions['panzoom']['watch'] = 'scales'
예제 #8
0
    def interaction_map(self):  # , xScale, yScale, fig, mark, deb):

        self.interactions = {}

        xScale = self.xScale  # if xScale is None else xScale
        yScale = self.yScale  # if yScale is None else yScale
        fig = self.fig  # if fig is None else fig
        mark = fig.marks  # if mark is None else mark

        multi_sel = MultiSelector(scale=xScale, marks=mark)
        br_intsel = BrushIntervalSelector(scale=xScale, marks=mark)
        index_sel = IndexSelector(scale=xScale, marks=mark)
        int_sel = FastIntervalSelector(scale=xScale, marks=mark)
        br_sel = BrushSelector(x_scale=xScale,
                               y_scale=yScale,
                               marks=mark,
                               color='red')
        pz = PanZoom(scales={'x': [xScale], 'y': [yScale]})

        # def cb1(change):
        #
        # def cb2(change):
        #
        # def cb3(change):

        self.interactions['brushes'] = {}
        self.interactions['brushes']['selector'] = multi_sel
        self.interactions['brushes']['icon'] = 'th-large'
        self.interactions['brushes']['tooltip'] = 'Multiple Brushes'
        self.interactions['brushes']['order'] = 0  # '   '
        self.interactions['brushes']['watch'] = 'selected'

        self.interactions['brush_x'] = {}
        self.interactions['brush_x']['selector'] = br_intsel
        self.interactions['brush_x']['icon'] = 'arrows-h'
        self.interactions['brush_x']['tooltip'] = 'Horizontal Brush'
        self.interactions['brush_x']['order'] = 1  # '     '
        self.interactions['brush_x']['watch'] = 'selected'

        self.interactions['brush_fast'] = {}
        self.interactions['brush_fast']['selector'] = int_sel
        self.interactions['brush_fast']['icon'] = 'exchange'
        self.interactions['brush_fast']['tooltip'] = 'Fast Brush'
        self.interactions['brush_fast']['order'] = 3  # '      '
        self.interactions['brush_fast']['watch'] = 'selected'

        self.interactions['brush'] = {}
        self.interactions['brush']['selector'] = br_sel
        self.interactions['brush']['icon'] = 'retweet'
        self.interactions['brush']['tooltip'] = 'Brush'
        self.interactions['brush']['order'] = 4  # '       '
        self.interactions['brush']['watch'] = 'brushing'

        self.interactions['bar'] = {}
        self.interactions['bar']['selector'] = index_sel
        self.interactions['bar']['icon'] = 'mouse-pointer'
        self.interactions['bar']['tooltip'] = 'Single Slider'
        self.interactions['bar']['order'] = 5  # ' '
        self.interactions['bar']['watch'] = 'selected'

        self.interactions['panzoom'] = {}
        self.interactions['panzoom']['selector'] = pz
        self.interactions['panzoom']['icon'] = 'arrows'
        self.interactions['panzoom']['tooltip'] = 'Pan Zoom'
        self.interactions['panzoom']['order'] = 6  # ''
        self.interactions['panzoom']['watch'] = 'scales'