[BugFix] openbb-charting: Get ChartStyle.plt_style Default Value From UserSettings (#7243)

* set ChartStyle.plt_style from UserSettings

* fix discrepencies between raw figure and pywry for light/dark
This commit is contained in:
Danglewood
2025-10-19 08:43:09 -07:00
committed by GitHub
parent e7e672f7d8
commit 023531fac7
14 changed files with 63 additions and 125 deletions

View File

@@ -530,6 +530,10 @@ function Chart({
...(originalData.layout.font || {}),
color: darkmode ? "#fff" : "#000",
};
originalData.layout.plot_bgcolor = {
...(originalData.layout.plot_bgcolor || {}),
color: darkmode ? "#000" : "#fff",
};
const changeIcon = darkmode ? ICONS.sunIcon : ICONS.moonIcon;

View File

@@ -194,12 +194,6 @@ 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(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,

View File

@@ -36,4 +36,4 @@ class EconometricsViews:
# pylint: disable=import-outside-toplevel
from openbb_charting.charts.correlation_matrix import correlation_matrix
return correlation_matrix(**kwargs)
return correlation_matrix(**kwargs) # type: ignore

View File

@@ -224,12 +224,6 @@ 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)" 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",
@@ -519,7 +513,7 @@ class EconomyViews:
)
content = fig.to_plotly_json()
return fig, content
return fig, content # type: ignore
@staticmethod
def economy_shipping_chokepoint_info(

View File

@@ -29,7 +29,7 @@ class EquityViews:
# pylint: disable=import-outside-toplevel
from openbb_charting.charts.price_performance import price_performance
return price_performance(**kwargs)
return price_performance(**kwargs) # type: ignore
@staticmethod
def equity_historical_market_cap( # noqa: PLR0912
@@ -80,6 +80,6 @@ class EquityViews:
scatter_kwargs=scatter_kwargs,
**kwargs,
)
content = fig.show(external=True).to_plotly_json()
content = fig.show(external=True).to_plotly_json() # type: ignore
return fig, content
return fig, content # type: ignore

View File

@@ -33,7 +33,7 @@ class EtfViews:
# pylint: disable=import-outside-toplevel
from openbb_charting.charts.price_performance import price_performance
return price_performance(**kwargs)
return price_performance(**kwargs) # type: ignore
@staticmethod
def etf_holdings(

View File

@@ -170,12 +170,6 @@ 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(21,21,21,0)" if text_color == "white" else "rgba(230,230,230,0)"
),
paper_bgcolor=(
"rgba(21,21,21,1)" if text_color == "white" else "rgba(230,230,230,1)"
),
xaxis=dict(
title="Maturity",
ticklen=10,

View File

@@ -289,12 +289,6 @@ class TechnicalViews:
fig.set_title(title)
fig.update_layout(
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",
@@ -381,9 +375,6 @@ 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)" if font_color == "white" else "rgba(255,255,255,255)"
),
plot_bgcolor="rgba(255,255,255,1)",
font=dict(color=font_color),
yaxis=dict(
@@ -527,12 +518,6 @@ 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)" 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",

View File

@@ -487,6 +487,7 @@ class Charting:
kwargs["provider"] = self._obbject.provider
kwargs["extra"] = self._obbject.extra
fig, content = charting_function(**kwargs)
content = fig.show(external=True, **kwargs).to_plotly_json() # type: ignore
self._obbject.chart = Chart(fig=fig, content=content, format=self._format)
if render:
fig.show(**kwargs)
@@ -629,8 +630,13 @@ class Charting:
style = self._charting_settings.chart_style
font_color = "black" if style == "light" else "white"
paper_bgcolor = "white" if style == "light" else "black"
plot_bgcolor = "white" if style == "light" else "black"
figure = figure.update_layout(
dict(font_color=font_color, paper_bgcolor=paper_bgcolor)
dict(
font_color=font_color,
paper_bgcolor=paper_bgcolor,
plot_bgcolor=plot_bgcolor,
)
) # pylint: disable=R1735
return figure

View File

@@ -101,15 +101,6 @@ def correlation_matrix( # noqa: PLR0912
)
fig = Figure(data=[heatmap], layout=layout)
figure = OpenBBFigure(fig=fig)
figure.update_layout(
font=dict(color=text_color),
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)"
),
)
layout_kwargs = kwargs.get("layout_kwargs", {})
if layout_kwargs:

View File

@@ -246,12 +246,6 @@ def line_chart( # noqa: PLR0912
fig.update_layout(
title=dict(text=title if title else None, x=0.5, font=dict(size=16)),
font=dict(color=text_color),
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="v",
yanchor="top",
@@ -456,12 +450,6 @@ def bar_chart( # noqa: PLR0912
figure.update_layout(
title=dict(text=title if title else None, x=0.5, font=dict(size=16)),
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="v",
yanchor="top",
@@ -637,12 +625,6 @@ def bar_increasing_decreasing( # pylint: disable=W0102
categoryorder="array" if orientation == "v" else None,
categoryarray=keys if orientation == "v" else None,
),
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="white" if text_color == "white" else "black"),
margin=dict(pad=5),
)
@@ -802,14 +784,7 @@ def surface3d(
center=dict(x=-0.01, y=0, z=-0.3),
eye=dict(x=1.75, y=1.75, z=0.69),
),
paper_bgcolor=(
"rgba(21,21,21,1)" if text_color == "white" else "rgba(255,255,255,1)"
),
plot_bgcolor=(
"rgba(21,21,21,1)" if text_color == "white" else "rgba(255,255,255,1)"
),
font=dict(color=text_color),
# margin=dict(t=100, b=10, r=10, l=10),
)
fig.update_scenes(

View File

@@ -120,12 +120,6 @@ def price_historical( # noqa: PLR0912
if _volume is True and "atr" in indicators: # type: ignore
fig.add_inchart_volume(data)
fig.update_layout(
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),
showlegend=True,
legend=dict(
@@ -254,12 +248,6 @@ def price_historical( # noqa: PLR0912
y2title = None # type: ignore
fig.update_layout(
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="v",

View File

@@ -67,9 +67,16 @@ class ChartStyle:
console_style : `str`, optional
The name of the Rich style to use, by default ""
"""
# pylint: disable=import-outside-toplevel
from openbb_core.app.service.user_service import UserService
if self.initialized:
return
user_settings = UserService().read_from_file()
pref_style = getattr(user_settings.preferences, "chart_style", None)
plt_style = plt_style or pref_style
self.initialized = True
self.user_styles_directory = user_styles_directory or self.user_styles_directory
self.plt_style = plt_style or self.plt_style

File diff suppressed because one or more lines are too long