Skip to content

feat: add _iter_all_traces helper and rewrite manipulation notebook#18

Merged
FBumann merged 5 commits intomainfrom
feature/improve-notebook
Jan 22, 2026
Merged

feat: add _iter_all_traces helper and rewrite manipulation notebook#18
FBumann merged 5 commits intomainfrom
feature/improve-notebook

Conversation

@FBumann
Copy link
Owner

@FBumann FBumann commented Jan 22, 2026

Summary

  • Add internal _iter_all_traces(fig) helper to iterate over all traces including animation frames
  • Refactor update_traces() and _style_traces_as_bars() to use the new helper
  • Rewrite manipulation.ipynb to use xpx() with a 4D DataArray demonstrating:
    • Standard Plotly methods (layout, axes, traces)
    • Faceted plots with facet_col/facet_row
    • Animation pain point and update_traces solution
    • Unified hover pattern
    • Facets + animation combined

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Completely revised manipulation examples notebook with updated data structures and comprehensive guidance on applying figure modifications using standard Plotly methods and xarray-plotly utilities
    • Enhanced documentation for animation-aware updates and faceted plots
  • Refactor

    • Improved internal animation frame iteration mechanism for more consistent trace updates across all animation frames

✏️ Tip: You can customize this high-level summary in your review settings.

  def _iter_all_traces(fig: go.Figure) -> Iterator:
      """Iterate over all traces in a figure, including animation frames.

      Yields traces from fig.data first, then from each frame in fig.frames.
      Useful for applying styling to all traces including those in animations.
      """
      yield from fig.data
      for frame in fig.frames or []:
          yield from frame.data

  Refactored update_traces to use it (simpler now - removed the separate fig.update_traces() call):
  for trace in _iter_all_traces(fig):
      if selector is None:
          trace.update(**kwargs)
      else:
          if all(getattr(trace, k, None) == v for k, v in selector.items()):
              trace.update(**kwargs)

  The helper can now be reused internally wherever trace iteration including animation frames is needed.
@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

The pull request refactors a documentation notebook to demonstrate xarray-plotly with a 4D dataset example while introducing a centralized helper function for iterating over traces across animation frames, replacing duplicated iteration logic.

Changes

Cohort / File(s) Summary
Documentation Example Notebook
docs/examples/manipulation.ipynb
Restructured notebook content and data setup: replaced 2D sample data with 4D DataArray (scenario × metric × year × country from Gapminder), updated imports to use config, update_traces, xpx, and rewrote narrative sections and code examples to emphasize standard Plotly methods and xarray-plotly helpers. Minor Python version reference bump from 3.11.0 to 3.12.0.
Trace Iteration Refactoring
xarray_plotly/figures.py, xarray_plotly/plotting.py
Introduced _iter_all_traces() helper function in figures.py to centralize iteration over all traces including animation frames, and refactored update_traces() to use this iterator with conditional selector-based filtering. Updated plotting.py to use _iter_all_traces() in _style_traces_as_bars() instead of manual trace collection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A notebook reborn with fourfold arrays,
Traces now dance through animation's maze,
Helpers unite what was scattered before,
xpx-powered plots and so much more! 📊✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: introducing a new _iter_all_traces helper function and comprehensively rewriting the manipulation notebook with updated examples and documentation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@FBumann FBumann changed the title Feature/improve notebook feat: add _iter_all_traces helper and rewrite manipulation notebook Jan 22, 2026
@FBumann FBumann merged commit f46cbf5 into main Jan 22, 2026
9 checks passed
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.

1 participant