diff --git a/components/dash-core-components/src/fragments/Graph.react.js b/components/dash-core-components/src/fragments/Graph.react.js index 8fae4f7189..694bf5404e 100644 --- a/components/dash-core-components/src/fragments/Graph.react.js +++ b/components/dash-core-components/src/fragments/Graph.react.js @@ -125,13 +125,11 @@ const filterEventData = (gd, eventData, event) => { (event === 'click' && gd._fullLayout.clickanywhere === true); if (includeXYVals) { - if (has('xvals', eventData)) { - filteredEventData.xvals = eventData.xvals; - } - - if (has('yvals', eventData)) { - filteredEventData.yvals = eventData.yvals; - } + ['xvals', 'yvals', 'xPixel', 'yPixel'].forEach(key => { + if (has(key, eventData)) { + filteredEventData[key] = eventData[key]; + } + }); if (has('xaxes', eventData)) { filteredEventData.xaxes_id = eventData.xaxes[0]._id; diff --git a/components/dash-core-components/tests/integration/graph/test_graph_basics.py b/components/dash-core-components/tests/integration/graph/test_graph_basics.py index efe32383d2..c8c2f56278 100644 --- a/components/dash-core-components/tests/integration/graph/test_graph_basics.py +++ b/components/dash-core-components/tests/integration/graph/test_graph_basics.py @@ -559,7 +559,10 @@ def show_figure_state(figure): def test_grbs011_clickanywhere_hoveranywhere(dash_dcc): - """When clickanywhere and hoveranywhere are enabled, clickData and hoverData include xvals and yvals""" + """ + When clickanywhere and hoveranywhere are enabled, clickData and hoverData include xvals and yvals + Note - xPixel and yPixel requires Plotly>=7 + """ app = Dash(__name__) app.layout = html.Div( @@ -587,6 +590,10 @@ def on_event(click_data, hover_data): "click_y": (click_data or {}).get("yvals", [None])[0], "hover_x": (hover_data or {}).get("xvals", [None])[0], "hover_y": (hover_data or {}).get("yvals", [None])[0], + "click_xPixel": (click_data or {}).get("xPixel", [None])[0], + "click_yPixel": (click_data or {}).get("yPixel", [None])[0], + "hover_xPixel": (hover_data or {}).get("xPixel", [None])[0], + "hover_yPixel": (hover_data or {}).get("yPixel", [None])[0], } return json.dumps(result) @@ -600,11 +607,18 @@ def on_event(click_data, hover_data): out = json.loads(dash_dcc.find_element("#output").text) - # click anywhere should produce coordinates - assert out["click_x"] is not None - assert out["click_y"] is not None - assert out["hover_x"] is not None - assert out["hover_y"] is not None + # click/hover anywhere should produce coordinates + for key in ( + "click_x", + "click_y", + "hover_x", + "hover_y", + "click_xPixel", + "click_yPixel", + "hover_xPixel", + "hover_yPixel", + ): + assert out[key] is not None def test_grbs012_graph_patch_keeps_relayout_ranges(dash_dcc):