mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 14:02:06 +00:00
[BugFix] Enforce User Preference For Dark/Light Mode In Chart Output To API (#6664)
* enforce user preference for dark/light in the chart output to the API * rogue closing parenthesis that shouldn't exist
This commit is contained in:
@@ -128,6 +128,7 @@ class DerivativesViews:
|
||||
|
||||
figure = OpenBBFigure().create_subplots(shared_xaxes=True)
|
||||
figure.update_layout(ChartStyle().plotly_template.get("layout", {}))
|
||||
text_color = "white" if ChartStyle().plt_style == "dark" else "black"
|
||||
|
||||
def create_fig(figure, df, dates, color_count):
|
||||
"""Create a scatter for each date in the data."""
|
||||
@@ -184,7 +185,12 @@ class DerivativesViews:
|
||||
# Update the layout of the figure.
|
||||
figure.update_layout(
|
||||
title=dict(text=title, x=0.5, font=dict(size=20)),
|
||||
plot_bgcolor="rgba(255,255,255,0)",
|
||||
plot_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
paper_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
xaxis=dict(
|
||||
title="",
|
||||
ticklen=0,
|
||||
@@ -207,7 +213,9 @@ class DerivativesViews:
|
||||
x=0,
|
||||
xref="paper",
|
||||
font=dict(size=12),
|
||||
bgcolor="rgba(0,0,0,0)",
|
||||
bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
),
|
||||
margin=dict(
|
||||
b=10,
|
||||
|
||||
@@ -25,6 +25,7 @@ class EconomyViews:
|
||||
from openbb_charting.charts.helpers import (
|
||||
z_score_standardization,
|
||||
)
|
||||
from openbb_charting.core.chart_style import ChartStyle
|
||||
from openbb_charting.core.openbb_figure import OpenBBFigure
|
||||
from openbb_charting.styles.colors import LARGE_CYCLER
|
||||
from openbb_core.app.utils import basemodel_to_df
|
||||
@@ -177,7 +178,8 @@ class EconomyViews:
|
||||
fig = OpenBBFigure().create_subplots(
|
||||
rows=1, cols=1, shared_xaxes=True, shared_yaxes=False
|
||||
)
|
||||
|
||||
fig.update_layout(ChartStyle().plotly_template.get("layout", {}))
|
||||
text_color = "white" if ChartStyle().plt_style == "dark" else "black"
|
||||
# For each series in the DataFrame, add a scatter plot.
|
||||
for i, col in enumerate(df_ta.columns):
|
||||
|
||||
@@ -227,15 +229,21 @@ class EconomyViews:
|
||||
# Now update the layout of the complete figure.
|
||||
fig.update_layout(
|
||||
title=dict(text=title, x=0.5, font=dict(size=16)),
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
paper_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
plot_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
legend=dict(
|
||||
orientation="h",
|
||||
yanchor="bottom",
|
||||
xanchor="right",
|
||||
y=1.02,
|
||||
x=0.95,
|
||||
bgcolor="rgba(0,0,0,0)",
|
||||
bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
font=dict(size=12),
|
||||
),
|
||||
yaxis=(
|
||||
@@ -304,6 +312,7 @@ class EconomyViews:
|
||||
margin=(
|
||||
dict(r=25, l=25, b=75 if xtitle else 30) if normalize is False else None
|
||||
),
|
||||
font=dict(color=text_color),
|
||||
autosize=True,
|
||||
dragmode="pan",
|
||||
)
|
||||
@@ -311,6 +320,7 @@ class EconomyViews:
|
||||
fig.update_layout(kwargs.get("layout_kwargs"))
|
||||
if kwargs.get("title"):
|
||||
fig.set_title(str(kwargs.get("title")))
|
||||
|
||||
content = fig.to_plotly_json()
|
||||
|
||||
return fig, content
|
||||
|
||||
@@ -64,6 +64,7 @@ class FixedIncomeViews:
|
||||
|
||||
figure = OpenBBFigure().create_subplots(shared_xaxes=True)
|
||||
figure.update_layout(ChartStyle().plotly_template.get("layout", {}))
|
||||
text_color = "white" if ChartStyle().plt_style == "dark" else "black"
|
||||
|
||||
def create_fig(figure, df, dates, color_count, country: Optional[str] = None):
|
||||
"""Create a scatter for each date in the data."""
|
||||
@@ -90,7 +91,6 @@ class FixedIncomeViews:
|
||||
figure.add_scatter(
|
||||
x=plot_df["Maturity"],
|
||||
y=plot_df["Yield"],
|
||||
# fill=fill,
|
||||
mode="lines+markers",
|
||||
name=f"{country} - {date}" if country else date,
|
||||
line=dict(width=3, color=color),
|
||||
@@ -142,7 +142,12 @@ class FixedIncomeViews:
|
||||
# Update the layout of the figure.
|
||||
figure.update_layout(
|
||||
title=dict(text=title, x=0.5, font=dict(size=20)),
|
||||
plot_bgcolor="rgba(255,255,255,0)",
|
||||
plot_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
paper_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
xaxis=dict(
|
||||
title="Maturity",
|
||||
ticklen=0,
|
||||
@@ -174,7 +179,9 @@ class FixedIncomeViews:
|
||||
x=0,
|
||||
xref="paper",
|
||||
font=dict(size=12),
|
||||
bgcolor="rgba(0,0,0,0)",
|
||||
bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
),
|
||||
margin=dict(
|
||||
b=25,
|
||||
|
||||
@@ -289,8 +289,12 @@ class TechnicalViews:
|
||||
fig.set_title(title)
|
||||
|
||||
fig.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
paper_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
plot_bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
font=dict(color=text_color),
|
||||
legend=dict(
|
||||
orientation="h",
|
||||
@@ -298,7 +302,9 @@ class TechnicalViews:
|
||||
xanchor="right",
|
||||
y=1.02,
|
||||
x=1,
|
||||
bgcolor="rgba(0,0,0,0)",
|
||||
bgcolor=(
|
||||
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
),
|
||||
yaxis=dict(
|
||||
ticklen=0,
|
||||
@@ -366,7 +372,9 @@ class TechnicalViews:
|
||||
figure = OpenBBFigure(fig) # pylint: disable=E0606
|
||||
font_color = "black" if ChartStyle().plt_style == "light" else "white"
|
||||
figure.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
paper_bgcolor=(
|
||||
"rgba(0,0,0,0)" if font_color == "white" else "rgba(255,255,255,255)"
|
||||
),
|
||||
plot_bgcolor="rgba(255,255,255,1)",
|
||||
font=dict(color=font_color),
|
||||
yaxis=dict(
|
||||
@@ -473,7 +481,7 @@ def _ta_ma(**kwargs):
|
||||
specs=[[{"secondary_y": True}]],
|
||||
)
|
||||
fig.update_layout(ChartStyle().plotly_template.get("layout", {}))
|
||||
|
||||
font_color = "black" if ChartStyle().plt_style == "light" else "white"
|
||||
ma_df = DataFrame()
|
||||
window = [window] if isinstance(window, int) else window
|
||||
for w in window:
|
||||
@@ -511,8 +519,12 @@ def _ta_ma(**kwargs):
|
||||
|
||||
fig.update_layout(
|
||||
title=dict(text=title, x=0.5, font=dict(size=16)),
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
paper_bgcolor=(
|
||||
"rgba(0,0,0,0)" if font_color == "white" else "rgba(255,255,255,255)"
|
||||
),
|
||||
plot_bgcolor=(
|
||||
"rgba(0,0,0,0)" if font_color == "white" else "rgba(255,255,255,0)"
|
||||
),
|
||||
showlegend=True,
|
||||
legend=dict(
|
||||
orientation="h",
|
||||
@@ -520,7 +532,7 @@ def _ta_ma(**kwargs):
|
||||
xanchor="right",
|
||||
y=1.02,
|
||||
x=0.95,
|
||||
bgcolor="rgba(0,0,0,0)",
|
||||
bgcolor="rgba(0,0,0,0)" if font_color == "white" else "rgba(255,255,255,0)",
|
||||
),
|
||||
xaxis=dict(
|
||||
ticklen=0,
|
||||
@@ -537,6 +549,7 @@ def _ta_ma(**kwargs):
|
||||
mirror=True,
|
||||
autorange=True,
|
||||
),
|
||||
font=dict(color=font_color),
|
||||
)
|
||||
|
||||
content = fig.show(external=True).to_plotly_json()
|
||||
|
||||
Reference in New Issue
Block a user