From c19713cd3b72b097fa5357e4747566e0944aa93a Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Wed, 3 May 2023 17:22:46 -0400 Subject: [PATCH] fix no figure title text --- frontend-components/plotly/src/App.tsx | 6 - .../plotly/src/components/Chart.tsx | 4 +- openbb_terminal/core/plots/backend.py | 18 ++ openbb_terminal/core/plots/plotly.html | 170 +++++++++--------- 4 files changed, 106 insertions(+), 92 deletions(-) diff --git a/frontend-components/plotly/src/App.tsx b/frontend-components/plotly/src/App.tsx index ff40c0ad9ba..bcadf56acd6 100644 --- a/frontend-components/plotly/src/App.tsx +++ b/frontend-components/plotly/src/App.tsx @@ -54,12 +54,6 @@ function App() { let time = new Date().toISOString().slice(11, 19).replace(/:/g, ""); window.title = `openbb_${filename}_${date}_${time}`; - let extension = ""; - if (window.export_image != undefined) { - filename = window.export_image.split("/").pop(); - extension = filename.split(".").pop().replace("jpg", "jpeg"); - } - if (data.layout.annotations != undefined) { data.layout.annotations.forEach(function (annotation) { if (annotation.text != undefined) diff --git a/frontend-components/plotly/src/components/Chart.tsx b/frontend-components/plotly/src/components/Chart.tsx index 3c0da92f36f..45829c28642 100644 --- a/frontend-components/plotly/src/components/Chart.tsx +++ b/frontend-components/plotly/src/components/Chart.tsx @@ -42,7 +42,9 @@ export default function Chart({ delete json.layout.width; delete json.layout.height; - json.layout.title.text = ""; + if (json.layout?.title?.text) { + json.layout.title.text = ""; + } const [barButtons, setModeBarButtons] = useState({}); const [LogYaxis, setLogYaxis] = useState(false); diff --git a/openbb_terminal/core/plots/backend.py b/openbb_terminal/core/plots/backend.py index 569ae67ae61..5629acf18bf 100644 --- a/openbb_terminal/core/plots/backend.py +++ b/openbb_terminal/core/plots/backend.py @@ -186,6 +186,24 @@ class Backend(PyWry): # pylint: disable=C0415 from openbb_terminal.helper_funcs import command_location + title = "Interactive Chart" + + # We check if figure is a subplot and has a title annotation + if not fig.layout.title.text and fig._has_subplots(): # pylint: disable=W0212 + for annotation in fig.select_annotations( + selector=dict(xref="paper", yref="paper") + ): + # Subplots always set the first annotation as the title + # so we break after the first one + if annotation.text: + title = annotation.text + annotation.text = "" + break + + 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): diff --git a/openbb_terminal/core/plots/plotly.html b/openbb_terminal/core/plots/plotly.html index 6a4650e1711..3206a5cdf6d 100644 --- a/openbb_terminal/core/plots/plotly.html +++ b/openbb_terminal/core/plots/plotly.html @@ -33,60 +33,60 @@ }