Exemplo n.º 1
0
    def test_selection_no_warning(self):
        plot_data = ArrayPlotData()
        arr = np.arange(4)
        plot_data.set_data("x", arr)
        plot_data.set_data("y", arr)
        plot = Plot(plot_data)
        renderer = plot.plot(('x', 'y'))[0]
        tool = RangeSelection(renderer)
        with warnings.catch_warnings(record=True) as w:
            tool.selection = np.array([2.0, 3.0])
        self.assertEqual(w, [])

        # Accept tuples and lists and None
        tool.selection = (1.5, 3.5)
        tool.selection = [1.0, 2.0]
        tool.selection = None
Exemplo n.º 2
0
    def _add_range_selection(self, series, listeners=None):
        series.active_tool = tool = RangeSelection(series,
                                                   left_button_selects=True)
        if listeners:
            tool.listeners = listeners

        series.overlays.append(RangeSelectionOverlay(component=series))
        return tool
Exemplo n.º 3
0
    def add_range_selector(self, plotid=0, series=0):
        from chaco.tools.range_selection import RangeSelection
        from chaco.tools.range_selection_overlay import RangeSelectionOverlay

        plot = self.plots[plotid].plots['plot{}'.format(series)][0]

        plot.active_tool = RangeSelection(plot, left_button_selects=True)

        plot.overlays.append(RangeSelectionOverlay(component=plot))
Exemplo n.º 4
0
    def test_selection_no_warning(self):
        plot_data = ArrayPlotData()
        arr = np.arange(4)
        plot_data.set_data("x", arr)
        plot_data.set_data("y", arr)
        plot = Plot(plot_data)
        renderer = plot.plot(('x', 'y'))[0]
        tool = RangeSelection(renderer)
        with warnings.catch_warnings(record=True) as w:
            # Ignore warnings coming from Traits
            warnings.filterwarnings("ignore",
                                    'elementwise == comparison failed')
            tool.selection = np.array([2.0, 3.0])

        self.assertEqual(w, [])

        # Accept tuples and lists and None
        tool.selection = (1.5, 3.5)
        tool.selection = [1.0, 2.0]
        tool.selection = None
Exemplo n.º 5
0
    def test_selection_no_warning(self):
        plot_data = ArrayPlotData()
        arr = np.arange(4)
        plot_data.set_data("x", arr)
        plot_data.set_data("y", arr)
        plot = Plot(plot_data)
        renderer = plot.plot(('x', 'y'))[0]
        tool = RangeSelection(renderer)
        with warnings.catch_warnings(record=True) as w:
            # Ignore warnings coming from any package other than Chaco
            warnings.filterwarnings(
                "ignore",
                module="(?!chaco)",
            )
            tool.selection = np.array([2.0, 3.0])

        self.assertEqual(w, [])

        # Accept tuples and lists and None
        tool.selection = (1.5, 3.5)
        tool.selection = [1.0, 2.0]
        tool.selection = None
Exemplo n.º 6
0
    def test_selecting_mouse_leave_clipping(self):
        # Regression test for #216.
        plot_data = ArrayPlotData()
        arr = np.arange(4.0)
        plot_data.set_data("x", arr)
        plot_data.set_data("y", arr)

        for origin in ('bottom left', 'top left', 'bottom right', 'top right'):
            for orientation in ('h', 'v'):
                for axis in ('index', 'value'):
                    plot = Plot(plot_data,
                                orientation=orientation,
                                origin='top right')

                    renderer = plot.plot(('x', 'y'))[0]
                    renderer.bounds = [10, 20]
                    tool = RangeSelection(
                        renderer,
                        left_button_selects=True,
                        axis=axis,
                    )
                    renderer.tools.append(tool)

                    low_x, low_y = plot.position
                    high_x = low_x + renderer.bounds[0] - 1
                    high_y = low_y + renderer.bounds[1] - 1

                    cx = 5
                    cy = 5

                    bounds = (
                        (low_x - 1, low_y),
                        (high_x + 1, low_y),
                        (low_x, low_y - 1),
                        (low_x, high_y + 1),
                    )
                    for x, y in bounds:
                        self.mouse_down(tool, x=cx, y=cy)
                        self.mouse_leave(tool, x=x, y=y)
                        selection = tool.selection
                        self.assertTrue(selection[0] <= selection[1])
                        self.mouse_up(tool, x=x, y=y)
Exemplo n.º 7
0
    def initialize_plot(self):
        data = self.data_model

        container = self.plot_container
        self._series = []
        self._plots = {}
        index, rr = None, None
        for i, (a, title) in enumerate((
            ('water_head', 'Head'),
            ('adjusted_water_head', 'Adj. Head'),

                # ('temp', 'Temp.'),
                # ('water_level_elevation', 'Elev.')
        )):
            plot = Plot(
                data=ArrayPlotData(**{
                    'x': data.x,
                    a: getattr(data, a)
                }),
                padding=[70, 10, 10, 10],
                # resizable='h',
                # bounds=(1, 125)
            )

            if index is None:
                index = plot.index_mapper
                rr = plot.index_range
            else:
                plot.index_mapper = index
                plot.index_range = rr

            series = plot.plot(('x', a))[0]
            plot.plot(('x', a), marker_size=1.5, type='scatter')

            dt = DataTool(plot=series,
                          component=plot,
                          normalize_time=False,
                          use_date_str=True)
            dto = DataToolOverlay(component=series, tool=dt)
            series.tools.append(dt)
            series.overlays.append(dto)

            plot.y_axis.title = title
            if i != 0:
                plot.x_axis.visible = False
            else:

                zoom = ZoomTool(plot,
                                tool_mode="range",
                                axis='index',
                                color=(0, 1, 0, 0.5),
                                enable_wheel=False,
                                always_on=False)
                plot.overlays.append(zoom)

                tool = RangeSelection(series,
                                      left_button_selects=True,
                                      listeners=[self])
                self._tool = tool

                series.tools.append(tool)
                # series.active_tool = tool
                # plot.x_axis.title = 'Time'
                bottom_axis = PlotAxis(
                    plot,
                    orientation="bottom",  # mapper=xmapper,
                    tick_generator=ScalesTickGenerator(
                        scale=CalendarScaleSystem()))
                plot.x_axis = bottom_axis

                plot.padding_bottom = 50

            series.overlays.append(RangeSelectionOverlay(component=series))
            container.add(plot)
            self._series.append(series)
            self._plots[a] = plot

        container.invalidate_and_redraw()