From 85bfa59d6a539010b80e2d92e7b9b725946520e3 Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Mon, 6 Jul 2026 15:49:04 +0530 Subject: [PATCH 1/2] fix(plotly): extract z-bbox from point.bbox.z, not point.bbox.y The injected extractPoints helper built the bbox z-extent from point.bbox.y0/y1 instead of point.bbox.z0/z1, a copy-paste of the two lines above it. As a result, on_hover/on_click/on_unhover event data for 3D traces reported a z0/z1 that always duplicated the y-extent, and the real z bounding box was unreachable. The BBox TypedDict already declares z0/z1 as fields distinct from y0/y1, so this only corrects the generated JavaScript. 2D traces are unaffected: their point.bbox carries no z fields, so the keys are still dropped by removeUndefined. Add a regression test asserting the generated helper sources z0/z1 from point.bbox.z0/point.bbox.z1. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --- .../src/reflex_components_plotly/plotly.py | 4 ++-- .../units/components/graphing/test_plotly.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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 From d63144a07ab294dc9276be78bcf70948eb73abf4 Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Mon, 6 Jul 2026 23:59:51 +0530 Subject: [PATCH 2/2] chore(plotly): add changelog fragment for z-bbox fix Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --- packages/reflex-components-plotly/news/6722.bugfix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/reflex-components-plotly/news/6722.bugfix.md 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.