Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PDF export capabilities #6442

Merged
merged 12 commits into from
May 21, 2024
Merged
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/psf/black
rev: 24.1.0
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
Expand Down
10 changes: 5 additions & 5 deletions cli/openbb_cli/controllers/base_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,11 +745,11 @@ def parse_known_args_and_warn(
choices_export = ["csv", "json", "xlsx"]
help_export = "Export raw data into csv, json, xlsx"
elif export_allowed == "figures_only":
choices_export = ["png", "jpg", "pdf", "svg"]
help_export = "Export figure into png, jpg, pdf, svg "
choices_export = ["png", "jpg", "svg"]
help_export = "Export figure into png, jpg, svg "
else:
choices_export = ["csv", "json", "xlsx", "png", "jpg", "pdf", "svg"]
help_export = "Export raw data into csv, json, xlsx and figure into png, jpg, pdf, svg "
choices_export = ["csv", "json", "xlsx", "png", "jpg", "svg"]
help_export = "Export raw data into csv, json, xlsx and figure into png, jpg, svg "

parser.add_argument(
"--export",
Expand Down Expand Up @@ -812,7 +812,7 @@ def parse_known_args_and_warn(
"raw_data_and_figures",
]:
ns_parser.is_image = any(
ext in ns_parser.export for ext in ["png", "svg", "jpg", "pdf"]
ext in ns_parser.export for ext in ["png", "svg", "jpg"]
)

except SystemExit:
Expand Down
10 changes: 6 additions & 4 deletions cli/openbb_cli/controllers/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ def __mock_parse_known_args_and_warn(
choices_export = ["csv", "json", "xlsx"]
help_export = "Export raw data into csv, json, xlsx"
elif export_allowed == "figures_only":
choices_export = ["png", "jpg", "pdf", "svg"]
help_export = "Export figure into png, jpg, pdf, svg "
choices_export = ["png", "jpg", "svg"]
help_export = "Export figure into png, jpg, svg "
else:
choices_export = ["csv", "json", "xlsx", "png", "jpg", "pdf", "svg"]
help_export = "Export raw data into csv, json, xlsx and figure into png, jpg, pdf, svg "
choices_export = ["csv", "json", "xlsx", "png", "jpg", "svg"]
help_export = (
"Export raw data into csv, json, xlsx and figure into png, jpg, svg "
)

parser.add_argument(
"--export",
Expand Down
2 changes: 1 addition & 1 deletion cli/openbb_cli/controllers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def export_data(
else:
save_to_excel(df, saved_path, sheet_name)

elif saved_path.suffix in [".jpg", ".pdf", ".png", ".svg"]:
elif saved_path.suffix in [".jpg", ".png", ".svg"]:
if figure is None:
Session().console.print("No plot to export.")
continue
Expand Down
2 changes: 1 addition & 1 deletion frontend-components/plotly/src/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ function Chart({
const filename = window.export_image.split("/").pop();
const extension = filename.split(".").pop().replace("jpg", "jpeg");

if (["jpeg", "png", "svg", "pdf"].includes(extension))
if (["jpeg", "png", "svg"].includes(extension))
return non_blocking(async function () {
await hideModebar();
await saveImage("MainChart", filename.split(".")[0], extension);
Expand Down
4 changes: 2 additions & 2 deletions frontend-components/plotly/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export async function saveImage(
) {
const chart = document.getElementById(id) as HTMLElement;

if (["svg", "pdf"].includes(extension)) {
if (["svg"].includes(extension)) {
const chart = document.getElementById("plotlyChart") as HTMLElement;
const margin = chart.layout.margin;
const old_index = chart.layout.annotations.length;
Expand Down Expand Up @@ -351,7 +351,7 @@ export async function downloadImage(
}
await loadingOverlay(`Saving ${extension.toUpperCase()}`).then(
setTimeout(async function () {
if (["svg", "pdf"].includes(extension)) {
if (["svg"].includes(extension)) {
await saveImage(id, filename, extension);
hidemodebar(false);
loading(false);
Expand Down
48 changes: 24 additions & 24 deletions openbb_platform/extensions/devtools/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openbb_platform/extensions/devtools/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ruff = "^0.1.6"
pylint = "^3.0.2"
mypy = "^1.6.1"
pydocstyle = "^6.3.0"
black = "^24.1.0"
black = "^24.4.2"
bandit = "^1.7.5"
codespell = "^2.2.5"
pre-commit = "^3.5.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import plotly.graph_objects as go
from openbb_core.env import Env
from packaging import version
from reportlab.graphics import renderPDF
from svglib.svglib import svg2rlg

if TYPE_CHECKING:
from openbb_core.app.model.charts.charting_settings import ChartingSettings
Expand Down Expand Up @@ -236,7 +234,6 @@ def send_figure(

async def process_image(self, export_image: Path):
"""Check if the image has been exported to the path."""
pdf = export_image.suffix == ".pdf"
img_path = export_image.resolve()

checks = 0
Expand All @@ -246,15 +243,7 @@ async def process_image(self, export_image: Path):
if checks > 50:
break

if pdf:
img_path = img_path.rename(img_path.with_suffix(".svg"))

if img_path.exists(): # noqa: SIM102
if pdf:
drawing = svg2rlg(img_path)
img_path.unlink(missing_ok=True)
renderPDF.drawToFile(drawing, str(export_image))

if self.charting_settings.plot_open_export:
if sys.platform == "win32":
os.startfile(export_image) # nosec: B606 # noqa: S606
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def is_image_export(self, export: Optional[str] = "") -> bool:
if not export:
return False

return any(ext in export for ext in ["jpg", "pdf", "png", "svg"])
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
Expand Down Expand Up @@ -1621,7 +1621,9 @@ def _prepare_data_corr_plot(x, lags):
lim = min(int(np.ceil(10 * np.log10(nobs))), nobs - 1)
lags = np.arange(not zero, lim + 1)
elif np.isscalar(lags):
lags = np.arange(not zero, int(lags) + 1) # +1 for zero lag
lags = np.arange(
not zero, int(lags) + 1 # type: ignore
) # +1 for zero lag
else:
irregular = True
lags = np.asanyarray(lags).astype(int)
Expand Down
Loading
Loading