diff --git a/frontend-components/tables/src/components/Table/index.tsx b/frontend-components/tables/src/components/Table/index.tsx index ee46a8222086..8446893f1c87 100644 --- a/frontend-components/tables/src/components/Table/index.tsx +++ b/frontend-components/tables/src/components/Table/index.tsx @@ -181,7 +181,8 @@ export default function Table({ : columns[0]; const indexValue = indexLabel ? row[indexLabel] : null; const value = row[column]; - const only_numbers = value?.toString()?.split(".")?.pop()?.replace(/[^0-9]/g, "") ?? ""; + const only_numbers = + value?.toString()?.split(".")?.[0]?.replace(/[^0-9]/g, "") ?? ""; const probablyDate = only_numbers?.length >= 4 && (includesDateNames(column) || @@ -197,7 +198,11 @@ export default function Table({ indexValue.toLowerCase().includes("hour") || indexValue.toLowerCase().includes("minute")))); - if (probablyDate && isoYearRegex.test(value?.toString())) + if ( + probablyDate && + value?.length === 4 && + isoYearRegex.test(value?.toString()) + ) return value; if (probablyDate) { @@ -219,7 +224,8 @@ export default function Table({ const indexValue = indexLabel ? row.original[indexLabel] : null; const value = row.original[column]; const valueType = typeof value; - const only_numbers = value?.toString()?.split(".")?.pop()?.replace(/[^0-9]/g, "") ?? ""; + const only_numbers = + value?.toString()?.split(".")?.[0]?.replace(/[^0-9]/g, "") ?? ""; const probablyDate = only_numbers?.length >= 4 && (includesDateNames(column) || @@ -246,14 +252,15 @@ export default function Table({ ); } - if (probablyDate && isoYearRegex.test(value?.toString())) { - return
{value}
; - } + if ( probablyDate && - !isNaN(new Date(value).getTime()) && - !isoYearRegex.test(value?.toString()) + value?.length === 4 && + isoYearRegex.test(value?.toString()) ) { + return{value}
; + } + if (probablyDate && !isNaN(new Date(value).getTime())) { if (typeof value === "string") { const date = value.split("T")[0]; const time = value.split("T")[1]?.split(".")[0]; diff --git a/openbb_terminal/common/quantitative_analysis/qa_view.py b/openbb_terminal/common/quantitative_analysis/qa_view.py index c273a12ba58c..83c26897eaba 100644 --- a/openbb_terminal/common/quantitative_analysis/qa_view.py +++ b/openbb_terminal/common/quantitative_analysis/qa_view.py @@ -121,7 +121,8 @@ def display_hist( fig.update_layout( xaxis_title="Value", - yaxis_title="Proportion", + margin=dict(r=40), + yaxis=dict(title="Proportion", title_standoff=40), bargap=0.01, bargroupgap=0, ) diff --git a/openbb_terminal/core/plots/plotly_helper.py b/openbb_terminal/core/plots/plotly_helper.py index 68fb219d311f..dfa7f92aef0d 100644 --- a/openbb_terminal/core/plots/plotly_helper.py +++ b/openbb_terminal/core/plots/plotly_helper.py @@ -3,7 +3,7 @@ import json import sys import textwrap -from datetime import datetime +from datetime import datetime, timedelta from math import floor from pathlib import Path from typing import ( @@ -598,9 +598,9 @@ def _validate_x(data: Union[np.ndarray, pd.Series, type[TimeSeriesT]]): colors = [None] * len(valid_x) # type: ignore max_y = 0 - for i, (x_i, name_i, color_i) in enumerate(zip(valid_x, name, colors)): + for i0, (x_i, name_i, color_i) in enumerate(zip(valid_x, name, colors)): if not color_i: - color_i = theme.up_color if i % 2 == 0 else theme.down_color + color_i = theme.up_color if i0 % 2 == 0 else theme.down_color res_mean, res_std = np.mean(x_i), np.std(x_i) res_min, res_max = min(x_i), max(x_i) @@ -639,13 +639,13 @@ def _validate_x(data: Union[np.ndarray, pd.Series, type[TimeSeriesT]]): if show_rug: self.add_scatter( x=x_i, - y=[0.002] * len(x_i), + y=[0.00002] * len(x_i), name=name_i if len(name) < 2 else name[1], mode="markers", marker=dict( color=theme.down_color, symbol="line-ns-open", - size=8, + size=10, ), row=row, col=col, @@ -1340,6 +1340,7 @@ def hide_date_gaps( return # We get the missing days + is_daily = df_data.index[-1].time() == df_data.index[-2].time() dt_days = pd.date_range(start=dt_start, end=dt_end, normalize=True) # We get the dates that are missing @@ -1351,17 +1352,22 @@ def hide_date_gaps( if len(dt_missing_days) < 2_000: rangebreaks = [dict(values=dt_missing_days)] - # We get the frequency of the data to hide intra-day gaps - if df_data.index[-1].time() != df_data.index[-2].time(): - freq = df_data.index[1] - df_data.index[0] - freq_mins = int(freq.seconds / 60) - break_values = ( - df_data.resample(f"{freq_mins}T") - .max() - .index.union(df_data.index) - .difference(df_data.index) - ) - rangebreaks = [dict(values=break_values, dvalue=freq_mins * 60 * 1000)] + df_data = df_data.sort_index() + # We add a rangebreak if the first and second time are not the same + # since daily data will have the same time (00:00) + if not is_daily: + for i in range(len(df_data) - 1): + if df_data.index[i + 1] - df_data.index[i] > timedelta(hours=2): + rangebreaks.insert( + 0, + dict( + bounds=[ + df_data.index[i] + + timedelta(minutes=60 - df_data.index[i].minute), + df_data.index[i + 1], + ] + ), + ) self.update_xaxes(rangebreaks=rangebreaks, row=row, col=col) @@ -1372,16 +1378,19 @@ def add_rangebreaks(self) -> None: for row, row_dict in self._subplot_xdates.items(): for col, values in row_dict.items(): - x_values = ( - pd.to_datetime(np.concatenate(values)) - .to_pydatetime() - .astype("datetime64[ms]") - ) - self.hide_date_gaps( - pd.DataFrame(index=x_values.tolist()), - row=row, - col=col, - ) + try: + x_values = ( + pd.to_datetime(np.concatenate(values)) + .to_pydatetime() + .astype("datetime64[ms]") + ) + self.hide_date_gaps( + pd.DataFrame(index=x_values.tolist()), + row=row, + col=col, + ) + except ValueError: + continue def to_subplot( self, diff --git a/openbb_terminal/core/plots/table.html b/openbb_terminal/core/plots/table.html index 351a979165ba..93a59444d995 100644 --- a/openbb_terminal/core/plots/table.html +++ b/openbb_terminal/core/plots/table.html @@ -79,7 +79,7 @@ }