summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjoaquim <henriquecjoaquim@gmail.com>2024-05-29 12:29:59 +0100
committerhjoaquim <henriquecjoaquim@gmail.com>2024-05-29 12:29:59 +0100
commit1fa53870458e84b01023e0e7888ee0cddd1cf95c (patch)
tree5f2bbbe7c9ecf02fa18a3b8f1638e744610b7504
parent44287a8f3032270999a9787282aa51c18fdac0f4 (diff)
small adjustments and removing unused function
-rw-r--r--openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py78
-rw-r--r--openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py2
2 files changed, 4 insertions, 76 deletions
diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py
index e1031059789..898e0847210 100644
--- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py
+++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py
@@ -201,21 +201,18 @@ class Backend(PyWry):
if self.charting_settings.chart_style == "dark"
else "rgba(255,255,255,0)"
)
-
title = "Interactive Chart"
-
fig.layout.title.text = re.sub(
r"<[^>]*>", "", fig.layout.title.text if fig.layout.title.text else title
)
-
fig.layout.height += 69
- if export_image and isinstance(export_image, str):
- export_image = Path(export_image).resolve()
+ export_image = Path(export_image).resolve() if export_image else None
json_data = json.loads(fig.to_json())
json_data.update(self.get_json_update(command_location))
json_data["layout"]["paper_bgcolor"] = paper_bg
+
outgoing = dict(
html=self.get_plotly_html(),
json_data=json_data,
@@ -224,7 +221,7 @@ class Backend(PyWry):
)
self.send_outgoing(outgoing)
- if export_image and isinstance(export_image, Path):
+ if export_image:
if self.loop.is_closed(): # type: ignore[has-type]
# Create a new event loop
self.loop = asyncio.new_event_loop()
@@ -404,75 +401,6 @@ class Backend(PyWry):
super().close()
- async def get_results(self, description: str) -> dict:
- """Wait for completion of interactive task and return the data.
-
- Parameters
- ----------
- description : str
- Description of the task to console print while waiting.
-
- Returns
- -------
- dict
- The data returned from pywry backend.
- """
- warnings.warn(
- f"[green]{description}[/]\n\n"
- "[yellow]If the window is closed you can continue by pressing Ctrl+C.[/]"
- )
- while True:
- try:
- data: dict = self.recv.get(block=False) or {}
- if data.get("result", False):
- return json.loads(data["result"])
- except Exception: # pylint: disable=W0703
- await asyncio.sleep(0.1)
-
- await asyncio.sleep(1)
-
- def call_hub(self, login: bool = True) -> Optional[dict]:
- """Call the hub to login or logout.
-
- Parameters
- ----------
- login : bool, optional
- Whether to login or logout, by default True
-
- Returns
- -------
- Optional[dict]
- The user data if login was successful, None otherwise.
- """
- self.check_backend()
- endpoint = {True: "login", False: "logout"}[login]
-
- outgoing = dict(
- json_data=dict(url=f"https://my.openbb.co/{endpoint}?pywry=true"),
- **self.get_kwargs(endpoint.title()),
- width=900,
- height=800,
- )
- self.send_outgoing(outgoing)
-
- messages_dict = dict(
- login=dict(
- message="Welcome to OpenBB Terminal! Please login to continue.",
- interrupt="Window closed without authentication. Please proceed below.",
- ),
- logout=dict(
- message="Sending logout request", interrupt="Please login to continue."
- ),
- )
-
- try:
- return self.loop.run_until_complete(
- self.get_results(messages_dict[endpoint]["message"])
- )
- except KeyboardInterrupt:
- warnings.warn(f"\n[red]{messages_dict[endpoint]['interrupt']}[/red]")
- return None
-
async def download_plotly_js():
"""Download or updates plotly.js to the assets folder."""
diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py
index e41a87bb02a..b9d930cdc45 100644
--- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py
+++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py
@@ -917,7 +917,7 @@ class OpenBBFigure(go.Figure):
self._exported = True
# We send the figure to the backend to be displayed
- return self._backend.send_figure(self, export_image)
+ return self._backend.send_figure(fig=self, export_image=export_image)
except Exception as e:
# If the backend fails, we just show the figure normally
# This is a very rare case, but it's better to have a fallback