コード例 #1
0
 def freeze(self, toast: Toast) -> None:
     """Set the plotter to frozen, preventing new traces from being added."""
     try:
         return self.active_view.freeze(toast)
     except NotImplementedError:
         toast.show(f"{self._active} does not implement freeze",
                    ToastType.warning)
コード例 #2
0
    def rename_variable(self, toast: Toast, var_name: str,
                        display_name: str) -> None:
        """Update the legend label of the given variable.

        If a dataframe name is specified, the legend labels of all the columns are changed
        accordingly.

        Parameters
        ----------
        toast: Toast
            The `Toast` class instance.

        var_name: str
            The name of the variable to change the label of, as it is defined in Python.
            Can be a series or dataframe name.

        display_name: str
            The desired legend label.
        """
        try:
            return self.active_view.rename_variable(toast, var_name,
                                                    display_name)
        except NotImplementedError:
            toast.show(f"{self._active} does not implement variable renaming",
                       ToastType.warning)
コード例 #3
0
 def defrost(self, toast: Toast) -> None:
     if self._frozen:
         toast.show(
             "Dtale is 'defrosted'. DFs defined while it was frozen will not be automatically picked up. Use --show "
             " to get them added.",
             ToastType.info,
         )
     self._frozen = False
コード例 #4
0
    def defrost(self, toast: Toast) -> None:
        """Set the plotter to un-frozen, allowing new traces to be plotted.

        Note that traces defined while it was frozen will need to be added manually.
        """
        try:
            return self.active_view.defrost(toast)
        except NotImplementedError:
            toast.show(f"{self._active} does not implement defrost",
                       ToastType.warning)
コード例 #5
0
    def update_max_series_length(self, toast: Toast, sample: int) -> None:
        """Update the maximum series length of all traces.

        If this has an effect on any of the traces, set `self._changed` to `True`.

        Parameters
        ----------
        max_length: int
            The new maximum series length. If 0, the traces will not be downsampled.
        """
        try:
            return self.active_view.update_max_series_length(toast, sample)
        except NotImplementedError:
            toast.show(f"{self._active} does not implement max series length",
                       ToastType.warning)
コード例 #6
0
    def set_plot_width(self, toast: Toast, width: int) -> None:
        """Validate and set the width of the figure.

        Parameters
        ----------
        toast: Toast
            The `Toast` class instance.

        width: int
            The desired width of the plot in inches. If outside the range `[_MIN_WIDTH,
            _MAX_WIDTH]`, will be set to the nearest limit and the user will be notified.
        """
        try:
            return self.active_view.set_plot_width(toast, width)
        except NotImplementedError:
            toast.show(
                f"{self._active} does not implement setting the plot height",
                ToastType.warning)
コード例 #7
0
    def set_ylabel(self, toast: Toast, ylabel: str) -> None:
        """Set the y axis label.

         If the new label is different, set `self._changed` to True.

         Parameters
         ----------
         toast: Toast
             The `Toast` class instance.

         ylabel: str
             New label for the y axis. If it is an empty string, no label will be used.
         """
        try:
            return self.active_view.set_ylabel(toast, ylabel)
        except NotImplementedError:
            toast.show(f"{self._active} does not implement changing ylabel",
                       ToastType.warning)
コード例 #8
0
    def ignore_variable(self, toast: Toast, var_name: str) -> None:
        """Hide the given variable from the plot. Undoes `show_variable`.

        If a dataframe name is specified, all of its columns will be hidden.

        Parameters
        ----------
        toast: Toast
            The `Toast` class instance.

        var_name: str
            Name of the variable to hide, as it is defined in Python. Can be a series
            names or dataframe name.
        """
        try:
            return self.active_view.ignore_variable(toast, var_name)
        except NotImplementedError:
            toast.show(f"{self._active} does not implement ignoring variables",
                       ToastType.warning)
コード例 #9
0
def test_show_variable():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.show_variable(Toast(Output()), "df")

    assert manager._changed
    assert a.showed == "df"
    assert b.showed == ""
コード例 #10
0
def test_rename_variable():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.rename_variable(Toast(Output()), "df", "ddf")

    assert manager._changed
    assert a.rename == ("df", "ddf")
    assert b.rename == ()
コード例 #11
0
def test_defrost():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.defrost(Toast(Output()))

    assert manager._changed
    assert a.defrosted
    assert not b.defrosted
コード例 #12
0
def test_max_series_length():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.update_max_series_length(Toast(Output()), 20)

    assert manager._changed
    assert a.max_series_length == 20
    assert b.max_series_length is None
コード例 #13
0
def test_set_ylabel():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.set_ylabel(Toast(Output()), "hello")

    assert manager._changed
    assert a.ylabel == "hello"
    assert b.ylabel is None
コード例 #14
0
def test_change_colour():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.change_colour(Toast(Output()), "df", "red")

    assert manager._changed
    assert a.colour == ("df", "red")
    assert b.colour == ()
コード例 #15
0
def test_set_plot_width():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.set_plot_width(Toast(Output()), 3)

    assert manager._changed
    assert a.plot_width == 3
    assert b.plot_width is None
コード例 #16
0
    def change_colour(self, toast: Toast, var_name: str, colour: str) -> None:
        """Update the colour of the given variable.

        Only series / column names can be specified, not dataframe names.

        Parameters
        ----------
        toast: Toast
            The `Toast` class instance.

        var_name: str
            The name of the variable to change the colour of, as it is defined in Python.

        colour: str
            The desired trace colour. Must be a valid matplotlib colour.
        """
        try:
            return self.active_view.change_colour(toast, var_name, colour)
        except NotImplementedError:
            toast.show(f"{self._active} does not implement changing colours",
                       ToastType.warning)
コード例 #17
0
    def show_variable(self, toast: Toast, var_name: str) -> None:
        """Show the given variable on the plot. Undoes `ignore_variable`.

        If a dataframe name is specified, all of its columns will be shown.

        Parameters
        ----------
        plotted_dfs: Dict[str, Set[str]]
            Dictionary with key = dataframe name, value = set of plotted column names.

        toast: Toast
            The `Toast` class instance.

        var_name: str
            Name of the variable to show, as it is defined in Python. Can be a series
            names or dataframe name.
        """
        try:
            return self.active_view.show_variable(toast, var_name)
        except NotImplementedError:
            toast.show(f"{self._active} does not implement showing variables",
                       ToastType.warning)
コード例 #18
0
def load_ipython_extension(shell):
    """Load the IPython extension. Called by `%load_ext ...`.

    This function initialises the widget output area, the autoplot display area defined
    in `AutoplotDisplay` and the `Plotter` instance. It also attaches adds
    the IPython event listeners defined in `CellEventHandler` and registers the magic
    commands defined in `AutoplotMagic`.

    Parameters
    ----------
    shell: IPython.InteractiveShell
        The active IPython shell.
    """
    js_output = widgets.Output()

    toast = Toast(js_output)
    plotter_model = PlotterModel(Plotter(toast))
    dtaler = DTaler()
    view_manager = ViewManager(AutoplotDisplay(), shell, {
        "graph": plotter_model,
        "dtale": dtaler
    }, "graph")

    def _autoplot_post_run_cell(*args):
        if args:
            success = args[0].success
        else:
            # IPython 5.x didn't use to pass the result as a parameter of post_run_cell
            success = IPython.get_ipython().last_execution_succeeded
        if success:
            view_manager.redraw()

    # Unregister previous events registered with this class (eg.: when the plugin reloads)
    for name, funcs in shell.events.callbacks.items():
        for func in funcs:
            if _autoplot_post_run_cell.__name__ == func.__name__:
                shell.events.unregister(name, func)
    shell.events.register("post_run_cell", _autoplot_post_run_cell)

    apm = _make_magic(shell, toast, view_manager)
    shell.register_magics(apm)
コード例 #19
0
 def freeze(self, toast: Toast) -> None:
     if not self._frozen:
         toast.show(
             "Dtale is 'frozen'. New DFs will not be tracked, but tracked ones will still update.", ToastType.info
         )
     self._frozen = True