Refactor chart x-axis configuration in report generation to improve tick interval handling. Introduce a new function for dynamic tick configuration based on time range, enhancing clarity in chart displays. Update related chart layout settings for better date formatting.
This commit is contained in:
parent
0193f18fb8
commit
7fd27ffed8
File diff suppressed because it is too large
Load Diff
3241
Lightning_Report_Manual.json
Normal file
3241
Lightning_Report_Manual.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -76,6 +76,24 @@ def _chart_xaxis_range(time_values: np.ndarray) -> tuple[pd.Timestamp, pd.Timest
|
||||
return x_min - padding, x_max + padding
|
||||
|
||||
|
||||
def _chart_xaxis_tick_config(
|
||||
x_min: pd.Timestamp,
|
||||
x_max: pd.Timestamp,
|
||||
max_ticks: int = 6,
|
||||
) -> tuple[int, str]:
|
||||
span_minutes = max(1.0, (x_max - x_min).total_seconds() / 60.0)
|
||||
nice_intervals_min = (1, 2, 5, 10, 15, 30, 60, 120, 180, 240, 360, 720, 1440)
|
||||
|
||||
dtick_min = nice_intervals_min[-1]
|
||||
for interval in nice_intervals_min:
|
||||
if span_minutes / interval <= max_ticks:
|
||||
dtick_min = interval
|
||||
break
|
||||
|
||||
tickformat = "%H:%M" if x_min.date() == x_max.date() else "%d-%m-%Y %H:%M"
|
||||
return dtick_min * 60 * 1000, tickformat
|
||||
|
||||
|
||||
def _build_current_vs_distance_chart(
|
||||
lightning_df: pd.DataFrame,
|
||||
dists_km: np.ndarray,
|
||||
@ -158,13 +176,7 @@ def _build_current_vs_distance_chart(
|
||||
|
||||
timezone_label = config.timezone or "UTC"
|
||||
x_min, x_max = _chart_xaxis_range(time_values)
|
||||
span_minutes = max(1.0, (x_max - x_min).total_seconds() / 60.0)
|
||||
if span_minutes <= 15:
|
||||
dtick = 60 * 1000
|
||||
elif span_minutes <= 60:
|
||||
dtick = 5 * 60 * 1000
|
||||
else:
|
||||
dtick = 10 * 60 * 1000
|
||||
dtick, tickformat = _chart_xaxis_tick_config(x_min, x_max)
|
||||
|
||||
fig.update_layout(
|
||||
font=dict(size=16),
|
||||
@ -179,7 +191,7 @@ def _build_current_vs_distance_chart(
|
||||
gridcolor="lightgray",
|
||||
zeroline=False,
|
||||
range=[x_min, x_max],
|
||||
tickformat="%d-%m-%Y %H:%M",
|
||||
tickformat=tickformat,
|
||||
dtick=dtick,
|
||||
tickangle=-25,
|
||||
tickfont=dict(size=22),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user