Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions components/dash-core-components/src/fragments/Graph.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down
Loading