Commit e49d75df authored by Duggan, John's avatar Duggan, John
Browse files

Add state flush to Interactive2DPlot and MatplotlibFigure

parent 554f4de1
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class Interactive2DPlot(vega.Figure):

        Parameters
        ----------
        figure : `altair.Chart <https://altair-viz.github.io/user_guide/generated/toplevel/altair.Chart.html#altair.Chart>`_
        figure : `altair.Chart <https://altair-viz.github.io/user_guide/generated/toplevel/altair.Chart.html#altair.Chart>`__, optional
            Altair chart object
        kwargs
            Arguments to be passed to `AbstractElement <https://trame.readthedocs.io/en/latest/core.widget.html#trame_client.widgets.core.AbstractElement>`_
@@ -38,7 +38,7 @@ class Interactive2DPlot(vega.Figure):
        Returns
        -------
        None
        """
        """  # noqa: E501
        self._initialized = False

        super().__init__(figure=figure, **kwargs)
@@ -83,3 +83,5 @@ class Interactive2DPlot(vega.Figure):

        if hasattr(self, "_start_update_handlers"):
            self._start_update_handlers()

        self.server.state.flush()
+9 −5
Original line number Diff line number Diff line
@@ -200,18 +200,20 @@ class MatplotlibFigure(matplotlib.Figure):

        Parameters
        ----------
        figure : `altair.Chart <https://altair-viz.github.io/user_guide/generated/toplevel/altair.Chart.html#altair.Chart>`_
            Altair chart object
        webagg : bool
        figure : `matplotlib.figure.Figure <https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure>`__, optional
            Initial Matplotlib figure.
        webagg : bool, optional
            If true, then the WebAgg backend for Matplotlib is used. If not, then the default Trame matplotlib plugin
            is used.
            is used. Note that this parameter does not supporting Trame bindings since the user experiences are
            fundamentally different between the two options and toggling them is not considered a good idea by the
            author of this component.
        kwargs
            Arguments to be passed to `AbstractElement <https://trame.readthedocs.io/en/latest/core.widget.html#trame_client.widgets.core.AbstractElement>`_

        Returns
        -------
        None
        """
        """  # noqa: E501
        self._webagg = webagg
        if webagg:
            self._port = MatplotlibFigure._get_free_port()
@@ -253,6 +255,8 @@ class MatplotlibFigure(matplotlib.Figure):
        else:
            super().update(figure)

        self._server.state.flush()

    def _setup_figure_websocket(self) -> None:
        thread = Thread(target=self._mpl_run_ws_server, daemon=True)
        thread.start()