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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 5 additions & 2 deletions 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 All @@ -910,7 +910,10 @@ def export_data(
Session().console.print("Wrong export file specified.")
continue

Session().console.print(f"Saved file: {saved_path}")
if saved_path.exists():
Session().console.print(f"Saved file: {saved_path}")
else:
Session().console.print(f"Failed to save file: {saved_path}")

if figure is not None:
figure._exported = True # pylint: disable=protected-access
Expand Down
2 changes: 1 addition & 1 deletion frontend-components/plotly/package-lock.json

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

4 changes: 2 additions & 2 deletions frontend-components/plotly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "vite",
"build": "vite build",
"build_tsc": "tsc && vite build",
"deploy": "npm run build && mv dist/index.html ../../cli/openbb_cli/assets/interactive/plotly.html",
"deploy": "npm run build && mv dist/index.html ../../openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly.html",
"preview": "vite preview"
},
"dependencies": {
Expand All @@ -26,7 +26,7 @@
"@types/plotly.js-dist-min": "^2.3.4",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@types/react-plotly.js": "^2.6.0",
"@types/react-plotly.js": "^2.6.3",
"@types/wicg-file-system-access": "^2020.9.6",
"@vitejs/plugin-react": "^3.1.0",
"autoprefixer": "^10.4.13",
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
11 changes: 5 additions & 6 deletions frontend-components/plotly/src/index.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@font-face {
font-family: "Fira Code";
src: url("../../fonts/FiraCode-VF.ttf") format("truetype");
/* fix Fire Code font width issue that makes Text get cut off in Plotly.js */
src: url("https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;700&display=swap") format("truetype");
font-weight: 400 700;
font-stretch: 50%;
}

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
._input {
@apply w-full text-xs px-2 py-1 bg-grey-50 dark:bg-grey-900 h-[36px] border-[1.5px] border-grey-300 dark:border-grey-700 rounded outline-none dark:outline-1 focus:border-grey-500 active:border-grey-500 dark:text-white dark:focus:text-white dark:focus:border-white dark:active:border-white dark:hover:border-white disabled:border-grey-600 font-normal;
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

This file was deleted.

Large diffs are not rendered by default.

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 @@ -54,7 +52,7 @@ class PyWry(DummyBackend): # type: ignore
JUPYTER_NOTEBOOK = True

PLOTS_CORE_PATH = Path(__file__).parent.resolve()
PLOTLYJS_PATH = PLOTS_CORE_PATH / "assets" / "plotly-2.24.2.min.js"
PLOTLYJS_PATH = PLOTS_CORE_PATH / "assets" / "plotly-2.32.0.min.js"
BACKEND = None


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