diff options
author | Danglewood <85772166+deeleeramone@users.noreply.github.com> | 2024-01-05 18:03:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-06 02:03:04 +0000 |
commit | a7514bc588e70bd1fbcff95d7d43742c4168ebc3 (patch) | |
tree | 876284112b3e0b9ff93e89b2304da383bebdd202 | |
parent | 70633e37a03c19ade7c066047cf0e8e3998ce119 (diff) |
hotfix/backend - Initialize OpenBBFigure (#5912)
* create backend
* openbb_figure
* black
* pylint
* pylint again
---------
Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
-rw-r--r-- | openbb_platform/extensions/charting/openbb_charting/core/backend.py | 2 | ||||
-rw-r--r-- | openbb_platform/extensions/charting/openbb_charting/core/openbb_figure.py | 38 |
2 files changed, 9 insertions, 31 deletions
diff --git a/openbb_platform/extensions/charting/openbb_charting/core/backend.py b/openbb_platform/extensions/charting/openbb_charting/core/backend.py index bbfc7b9ac9d..24ab5ed4c50 100644 --- a/openbb_platform/extensions/charting/openbb_charting/core/backend.py +++ b/openbb_platform/extensions/charting/openbb_charting/core/backend.py @@ -353,7 +353,7 @@ class Backend(PyWry): def get_kwargs(self, title: Optional[str] = "") -> dict: """Get the kwargs for the backend.""" return { - "title": f"OpenBB - {title}", + "title": "OpenBB Platform" + (f" - {title}" if title else ""), "icon": self.get_window_icon(), "download_path": str(self.charting_settings.user_exports_directory), } diff --git a/openbb_platform/extensions/charting/openbb_charting/core/openbb_figure.py b/openbb_platform/extensions/charting/openbb_charting/core/openbb_figure.py index 1511d6faf2c..5fb9107b0b9 100644 --- a/openbb_platform/extensions/charting/openbb_charting/core/openbb_figure.py +++ b/openbb_platform/extensions/charting/openbb_charting/core/openbb_figure.py @@ -22,7 +22,7 @@ import numpy as np import pandas as pd import plotly.graph_objects as go import plotly.io as pio -from openbb_charting.core.backend import PLOTLYJS_PATH, get_backend +from openbb_charting.core.backend import PLOTLYJS_PATH, create_backend, get_backend from openbb_charting.core.chart_style import ChartStyle from openbb_charting.core.config.openbb_styles import ( PLT_TBL_ROW_COLORS, @@ -99,6 +99,9 @@ class OpenBBFigure(go.Figure): self._export_image: Optional[Union[Path, str]] = "" self._subplot_xdates: Dict[int, Dict[int, List[Any]]] = {} + if kwargs.pop("create_backend", False): + create_backend(self._charting_settings) + get_backend().start(debug=self._charting_settings.debug_mode) self._theme = ChartStyle( self._charting_settings.chart_style, self._charting_settings.user_styles_directory, @@ -161,7 +164,7 @@ class OpenBBFigure(go.Figure): self._cmd_xshift = value @classmethod - def create_subplots( # noqa: PLR0913 + def create_subplots( # pylint: disable=too-many-arguments cls, rows: int = 1, cols: int = 1, @@ -267,7 +270,7 @@ class OpenBBFigure(go.Figure): except Exception as e: raise ValueError(f"Error adding trend line: {e}") from e - def add_histplot( # noqa: PLR0913, PLR0915 + def add_histplot( # pylint: disable=too-many-arguments self, dataset: Union[np.ndarray, pd.Series, TimeSeriesT], name: Optional[Union[str, List[str]]] = None, @@ -309,7 +312,7 @@ class OpenBBFigure(go.Figure): Column of the subplot, by default 1 """ - from scipy import stats + from scipy import stats # pylint: disable=import-outside-toplevel callback = stats.norm if curve == "normal" else stats.gaussian_kde @@ -1452,30 +1455,6 @@ class OpenBBFigure(go.Figure): self._margin_adjusted = True - def _set_watermark(self) -> None: - """Set the watermark for OpenBB Terminal.""" - if ( - not self._backend.isatty - or not self._charting_settings.plot_enable_pywry - or isinstance(self._export_image, Path) - and self._export_image.suffix in [".svg", ".pdf"] - ): - self.add_annotation( - yref="paper", - xref="paper", - x=1, - y=0, - showarrow=False, - text="OpenBB Terminal", - font_size=17, - font_color="gray", - opacity=0.5, - xanchor="right", - yanchor="bottom", - yshift=-80, - xshift=40, - ) - # pylint: disable=import-outside-toplevel def _add_cmd_source(self, command_location: Optional[str] = "") -> None: """Set the watermark for OpenBB Terminal.""" @@ -1525,7 +1504,6 @@ class OpenBBFigure(go.Figure): return self._add_cmd_source() - self._set_watermark() self._feature_flags_applied = True @@ -1594,7 +1572,7 @@ class OpenBBFigure(go.Figure): ], ) - def add_corr_plot( # noqa: PLR0913 + def add_corr_plot( # pylint: disable=too-many-arguments self, series: pd.DataFrame, max_lag: int = 20, |