Skip to content

Commit 985756f

Browse files
committed
Fixed. The issue was that _merge_frames and _merge_secondary_y_frames weren't preserving the layout property of animation frames (which contains range_y).
Changes: - figures.py: Added layout=base_frame.layout to go.Frame() in both merge functions - test_figures.py: Added 2 new tests for frame layout preservation
1 parent cd7ddc9 commit 985756f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/test_figures.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ def test_frame_names_preserved(self) -> None:
232232
combined_names = {frame.name for frame in combined.frames}
233233
assert original_names == combined_names
234234

235+
def test_frame_layout_preserved(self) -> None:
236+
"""Test that frame layout (e.g., axis range) is preserved."""
237+
fig = xpx(self.da_3d).line(animation_frame="time", range_y=[0, 10])
238+
overlay_fig = xpx(self.da_3d).scatter(animation_frame="time")
239+
240+
# Verify base has frame layout
241+
assert fig.frames[0].layout is not None
242+
243+
combined = overlay(fig, overlay_fig)
244+
245+
# Frame layout should be preserved
246+
for i, frame in enumerate(combined.frames):
247+
assert frame.layout == fig.frames[i].layout
248+
235249

236250
class TestOverlayFacetsAndAnimation:
237251
"""Tests for overlay with both facets and animation."""
@@ -560,6 +574,20 @@ def test_mismatched_animation_frames_raises(self) -> None:
560574
with pytest.raises(ValueError, match="frame names don't match"):
561575
add_secondary_y(fig1, fig2)
562576

577+
def test_frame_layout_preserved(self) -> None:
578+
"""Test that frame layout (e.g., axis range) is preserved."""
579+
base = xpx(self.da_2d).line(animation_frame="time", range_y=[0, 10])
580+
secondary = xpx(self.da_2d).bar(animation_frame="time")
581+
582+
# Verify base has frame layout
583+
assert base.frames[0].layout is not None
584+
585+
combined = add_secondary_y(base, secondary)
586+
587+
# Frame layout should be preserved
588+
for i, frame in enumerate(combined.frames):
589+
assert frame.layout == base.frames[i].layout
590+
563591

564592
class TestAddSecondaryYDeepCopy:
565593
"""Tests to ensure add_secondary_y creates deep copies."""

xarray_plotly/figures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def _merge_frames(
142142
data=merged_data,
143143
name=frame_name,
144144
traces=list(range(base_trace_count + sum(overlay_trace_counts))),
145+
layout=base_frame.layout,
145146
)
146147
)
147148

@@ -403,6 +404,7 @@ def _merge_secondary_y_frames(
403404
data=merged_data,
404405
name=frame_name,
405406
traces=list(range(base_trace_count + secondary_trace_count)),
407+
layout=base_frame.layout,
406408
)
407409
)
408410

0 commit comments

Comments
 (0)