diff --git a/packages/reflex-components-plotly/news/6722.bugfix.md b/packages/reflex-components-plotly/news/6722.bugfix.md new file mode 100644 index 00000000000..04f33c3b99c --- /dev/null +++ b/packages/reflex-components-plotly/news/6722.bugfix.md @@ -0,0 +1 @@ +Fixed `rx.plotly` `on_hover`/`on_click`/`on_unhover` event data reporting the wrong z bounding box for 3D traces: `bbox.z0`/`bbox.z1` had been duplicating the y-extent instead of surfacing the real z-extent. diff --git a/packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py b/packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py index 7649f24790e..debb80ec596 100644 --- a/packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py +++ b/packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py @@ -214,8 +214,8 @@ def add_custom_code(self) -> list[str]: x1: point.bbox.x1, y0: point.bbox.y0, y1: point.bbox.y1, - z0: point.bbox.y0, - z1: point.bbox.y1, + z0: point.bbox.z0, + z1: point.bbox.z1, }) : undefined; return removeUndefined({ x: point.x, diff --git a/tests/units/components/graphing/test_plotly.py b/tests/units/components/graphing/test_plotly.py index 85dcb2da646..f85dd1a42e6 100644 --- a/tests/units/components/graphing/test_plotly.py +++ b/tests/units/components/graphing/test_plotly.py @@ -75,3 +75,22 @@ def test_plotly_basic_locale_option_merges_into_config(plotly_fig: go.Figure): assert "locale" not in rendered.props assert "_rxGetPlotlyLocaleConfig" in str(config_var) assert "fr" in str(config_var) + + +def test_plotly_extract_points_bbox_z_source(plotly_fig: go.Figure): + """Test that the point extractor reads the z-bbox from the z fields. + + The generated ``extractPoints`` helper must source the ``z0``/``z1`` bounding + box members from ``point.bbox.z0``/``point.bbox.z1`` so 3D-plot event data + reports the real z-extent instead of duplicating the y-extent. + + Args: + plotly_fig: The figure to display. + """ + component = rx.plotly(data=plotly_fig) + custom_code = "\n".join(component.add_custom_code()) + + assert "z0: point.bbox.z0" in custom_code + assert "z1: point.bbox.z1" in custom_code + assert "z0: point.bbox.y0" not in custom_code + assert "z1: point.bbox.y1" not in custom_code