Skip to content

refactor: deduplicate NAV layout setup into shared helper#372

Merged
tschm merged 2 commits intomainfrom
copilot/fix-duplicated-code-in-analytics-plots
Mar 23, 2026
Merged

refactor: deduplicate NAV layout setup into shared helper#372
tschm merged 2 commits intomainfrom
copilot/fix-duplicated-code-in-analytics-plots

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

lagged_performance_plot and smoothed_holdings_performance_plot contained identical 27-line Plotly layout blocks differing only by title string.

Changes

  • New _apply_nav_layout static method — encapsulates the shared update_layout / update_xaxes / update_yaxes / log_scale logic, parameterised by title and log_scale
  • Both plot methods now delegate to the helper, replacing the duplicated blocks with a single call each
# Before (repeated verbatim in two methods)
fig.update_layout(
    title="NAV accumulated by lag",
    hovermode="x unified",
    plot_bgcolor="white",
    legend={...},
    xaxis={"rangeselector": {"buttons": [...]}, ...},
)
fig.update_yaxes(title_text="NAV (accumulated)")
fig.update_xaxes(showgrid=True, gridwidth=0.5, gridcolor="lightgrey")
fig.update_yaxes(showgrid=True, gridwidth=0.5, gridcolor="lightgrey")
if log_scale:
    ...

# After
self._apply_nav_layout(fig, title="NAV accumulated by lag", log_scale=log_scale)
Original prompt

This section details on the original issue you should resolve

<issue_title>Duplicated code?</issue_title>
<issue_description>Found in src\jquantstats\analytics_plots.py:257-283 , src\jquantstats\analytics_plots.py:592-618</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

@tschm tschm marked this pull request as ready for review March 23, 2026 08:49
Copilot AI changed the title [WIP] Fix duplicated code in analytics plots refactor: deduplicate NAV layout setup into shared helper Mar 23, 2026
Copilot AI requested a review from tschm March 23, 2026 08:55
@tschm tschm merged commit c263ec1 into main Mar 23, 2026
21 checks passed
@tschm tschm deleted the copilot/fix-duplicated-code-in-analytics-plots branch March 23, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated code?

2 participants