summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <henriquecjoaquim@gmail.com>2024-06-03 14:28:57 +0100
committerGitHub <noreply@github.com>2024-06-03 13:28:57 +0000
commit8a63c2df3e8831d52af4f1fca05c65e859e6f31b (patch)
tree57e19a34d066926b4da58994da82a41ac1488d0a
parent0b3e2860357373846e21225b10ea4ec5900ccfa9 (diff)
[Bugfix] Remove svg export (#6476)
* lint * fix version * add url functionality to the charting extension * small adjustments and removing unused function * remove svg * remove unused function * better messages * version can't be asserted bc will change
-rw-r--r--cli/openbb_cli/controllers/base_controller.py14
-rw-r--r--cli/openbb_cli/controllers/base_platform_controller.py2
-rw-r--r--cli/openbb_cli/controllers/choices.py10
-rw-r--r--cli/openbb_cli/controllers/utils.py2
-rw-r--r--cli/openbb_cli/models/settings.py7
-rw-r--r--cli/tests/test_models_settings.py2
-rw-r--r--openbb_platform/obbject_extensions/charting/openbb_charting/__init__.py13
-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.py20
-rw-r--r--website/content/cli/data-sources.md2
-rw-r--r--website/content/cli/quickstart.md2
11 files changed, 39 insertions, 113 deletions
diff --git a/cli/openbb_cli/controllers/base_controller.py b/cli/openbb_cli/controllers/base_controller.py
index 206e8a735bd..3d93a1dc59c 100644
--- a/cli/openbb_cli/controllers/base_controller.py
+++ b/cli/openbb_cli/controllers/base_controller.py
@@ -743,13 +743,15 @@ class BaseController(metaclass=ABCMeta):
if export_allowed == "raw_data_only":
choices_export = ["csv", "json", "xlsx"]
- help_export = "Export raw data into csv, json, xlsx"
+ help_export = "Export raw data into csv, json or xlsx."
elif export_allowed == "figures_only":
- choices_export = ["png", "jpg", "svg"]
- help_export = "Export figure into png, jpg, svg "
+ choices_export = ["png", "jpg"]
+ help_export = "Export figure into png or jpg."
else:
- choices_export = ["csv", "json", "xlsx", "png", "jpg", "svg"]
- help_export = "Export raw data into csv, json, xlsx and figure into png, jpg, svg "
+ choices_export = ["csv", "json", "xlsx", "png", "jpg"]
+ help_export = (
+ "Export raw data into csv, json, xlsx and figure into png or jpg."
+ )
parser.add_argument(
"--export",
@@ -823,7 +825,7 @@ class BaseController(metaclass=ABCMeta):
"raw_data_and_figures",
]:
ns_parser.is_image = any(
- ext in ns_parser.export for ext in ["png", "svg", "jpg"]
+ ext in ns_parser.export for ext in ["png", "jpg"]
)
except SystemExit:
diff --git a/cli/openbb_cli/controllers/base_platform_controller.py b/cli/openbb_cli/controllers/base_platform_controller.py
index ed8f0087516..33cc4700849 100644
--- a/cli/openbb_cli/controllers/base_platform_controller.py
+++ b/cli/openbb_cli/controllers/base_platform_controller.py
@@ -154,7 +154,7 @@ class PlatformController(BaseController):
obbject = translator.execute_func(parsed_args=ns_parser)
df: pd.DataFrame = pd.DataFrame()
- fig: OpenBBFigure = None
+ fig: Optional[OpenBBFigure] = None
title = f"{self.PATH}{translator.func.__name__}"
if obbject:
diff --git a/cli/openbb_cli/controllers/choices.py b/cli/openbb_cli/controllers/choices.py
index 242cb098d46..5ed38bb8ba3 100644
--- a/cli/openbb_cli/controllers/choices.py
+++ b/cli/openbb_cli/controllers/choices.py
@@ -56,14 +56,14 @@ def __mock_parse_known_args_and_warn(
if export_allowed == "raw_data_only":
choices_export = ["csv", "json", "xlsx"]
- help_export = "Export raw data into csv, json, xlsx"
+ help_export = "Export raw data into csv, json or xlsx."
elif export_allowed == "figures_only":
- choices_export = ["png", "jpg", "svg"]
- help_export = "Export figure into png, jpg, svg "
+ choices_export = ["png", "jpg"]
+ help_export = "Export figure into png or jpg."
else:
- choices_export = ["csv", "json", "xlsx", "png", "jpg", "svg"]
+ choices_export = ["csv", "json", "xlsx", "png", "jpg"]
help_export = (
- "Export raw data into csv, json, xlsx and figure into png, jpg, svg "
+ "Export raw data into csv, json, xlsx and figure into png or jpg."
)
parser.add_argument(
diff --git a/cli/openbb_cli/controllers/utils.py b/cli/openbb_cli/controllers/utils.py
index d49279fd940..7c92a5880ae 100644
--- a/cli/openbb_cli/controllers/utils.py
+++ b/cli/openbb_cli/controllers/utils.py
@@ -901,7 +901,7 @@ def export_data(
else:
save_to_excel(df, saved_path, sheet_name)
- elif saved_path.suffix in [".jpg", ".png", ".svg"]:
+ elif saved_path.suffix in [".jpg", ".png"]:
if figure is None:
Session().console.print("No plot to export.")
continue
diff --git a/cli/openbb_cli/models/settings.py b/cli/openbb_cli/models/settings.py
index 7fdda72d3de..ebfd15f6879 100644
--- a/cli/openbb_cli/models/settings.py
+++ b/cli/openbb_cli/models/settings.py
@@ -1,17 +1,20 @@
-"""Settings model"""
+"""Settings model."""
from typing import Any
from dotenv import dotenv_values, set_key
from openbb_cli.config.constants import ENV_FILE_SETTINGS
+from openbb_core.app.version import get_package_version
from pydantic import BaseModel, ConfigDict, model_validator
+VERSION = get_package_version("openbb-cli")
+
class Settings(BaseModel):
"""Settings model."""
# Platform CLI version
- VERSION: str = "1.0.0"
+ VERSION: str = VERSION
# DEVELOPMENT FLAGS
TEST_MODE: bool = False
diff --git a/cli/tests/test_models_settings.py b/cli/tests/test_models_settings.py
index 0834355516f..532d6bc0118 100644
--- a/cli/tests/test_models_settings.py
+++ b/cli/tests/test_models_settings.py
@@ -10,7 +10,6 @@ from openbb_cli.models.settings import Settings
def test_default_values():
"""Test the default values of the settings model."""
settings = Settings()
- assert settings.VERSION == "1.0.0"
assert settings.TEST_MODE is False
assert settings.DEBUG_MODE is False
assert settings.DEV_BACKEND is False
@@ -43,7 +42,6 @@ def test_repr():
settings = Settings()
repr_str = settings.__repr__() # pylint: disable=C2801
assert "Settings\n\n" in repr_str
- assert "VERSION: 1.0.0" in repr_str
# Test loading from environment variables
diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/__init__.py b/openbb_platform/obbject_extensions/charting/openbb_charting/__init__.py
index b2e5efcfd4a..884b370df42 100644
--- a/openbb_platform/obbject_extensions/charting/openbb_charting/__init__.py
+++ b/openbb_platform/obbject_extensions/charting/openbb_charting/__init__.py
@@ -554,3 +554,16 @@ class Charting:
ipython_display.display(ipython_display.HTML(data_as_df.to_html()))
else:
warn("IPython.display is not available.")
+
+ def url(
+ self,
+ url: str,
+ title: str = "",
+ width: Optional[int] = None,
+ height: Optional[int] = None,
+ ):
+ """Return the URL of the chart."""
+ try:
+ self._backend.send_url(url=url, title=title, width=width, height=height)
+ except Exception as e: # pylint: disable=W0718
+ warn(f"Failed to show figure with backend. {e}")
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..c255ef7f226 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
@@ -464,24 +464,6 @@ class OpenBBFigure(go.Figure):
self.update_layout(barmode="overlay", bargap=0.01, bargroupgap=0)
- def is_image_export(self, export: Optional[str] = "") -> bool:
- """Check if the export format is an image format.
-
- Parameters
- ----------
- export : `str`
- Export format
-
- Returns
- -------
- `bool`
- True if the export format is an image format, False otherwise
- """
- if not export:
- return False
-
- return any(ext in export for ext in ["jpg", "png", "svg"])
-
def set_title(
self, title: str, wrap: bool = False, wrap_width: int = 80, **kwargs
) -> "OpenBBFigure":
@@ -917,7 +899,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
diff --git a/website/content/cli/data-sources.md b/website/content/cli/data-sources.md
index eb9d9c1b5d9..aa79329da1f 100644
--- a/website/content/cli/data-sources.md
+++ b/website/content/cli/data-sources.md
@@ -62,7 +62,7 @@ options:
--adjustment {splits_and_dividends,unadjusted,splits_only}
The adjustment factor to apply. Default is splits only. (provider: polygon, yfinance)
-h, --help show this help message
- --export EXPORT Export raw data into csv, json, xlsx and figure into png, jpg, svg
+ --export EXPORT Export raw data into csv, json, xlsx and figure into png or jpg
--sheet-name SHEET_NAME [SHEET_NAME ...]
Name of excel sheet to save data to. Only valid for .xlsx files.
diff --git a/website/content/cli/quickstart.md b/website/content/cli/quickstart.md
index d575da5625a..299b68c0dc5 100644
--- a/website/content/cli/quickstart.md
+++ b/website/content/cli/quickstart.md
@@ -167,7 +167,7 @@ options:
no default.
--country COUNTRY Country of the event. (provider: nasdaq, tradingeconomics)
-h, --help show this help message
- --export EXPORT Export raw data into csv, json, xlsx and figure into png, jpg, svg
+ --export EXPORT Export raw data into csv, json, xlsx and figure into png or jpg
--sheet-name SHEET_NAME [SHEET_NAME ...]
Name of excel sheet to save data to. Only valid for .xlsx files.