Skip to content

Commit

Permalink
Merge pull request #2500 from plotly/fix-2493
Browse files Browse the repository at this point in the history
Fixed the issue 2493. Passing customdata by userclick
  • Loading branch information
T4rk1n committed May 15, 2023
2 parents 5306753 + aacc530 commit 52b73b1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- [#2489](https://github.com/plotly/dash/pull/2489) Fix location change event handling when `Location` objects are removed from the layout. Event handlers would not be removed and eventually change props of a random DOM element, fix [#1346](https://github.com/plotly/dash/issues/1346)
- [#2498](https://github.com/plotly/dash/pull/2498) Fix error when caching callbacks which return `Patch` objects by making `Patch` objects picklable
- [#2491](https://github.com/plotly/dash/pull/2491) Fix clientside inline function name not found, fix [#2488](https://github.com/plotly/dash/issues/2488)
- [#2500](https://github.com/plotly/dash/pull/2500) Passing customdata by click for scattermapbox, fix [#2493](https://github.com/plotly/dash/issues/2493)

## [2.9.2] - 2023-03-29

Expand Down
20 changes: 15 additions & 5 deletions components/dash-core-components/src/fragments/Graph.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,22 @@ const filterEventData = (gd, eventData, event) => {
has('customdata', data[pointData.curveNumber])
) {
if (has('pointNumber', fullPoint)) {
pointData.customdata =
data[pointData.curveNumber].customdata[
fullPoint.pointNumber
];
if (typeof fullPoint.pointNumber === 'number') {
pointData.customdata =
data[pointData.curveNumber].customdata[
fullPoint.pointNumber
];
} else if (
!fullPoint.pointNumber &&
fullPoint.data.mode.includes('lines')
) {
pointData.customdata =
data[pointData.curveNumber].customdata;
}
} else if (has('pointNumbers', fullPoint)) {
pointData.customdata = fullPoint.pointNumbers.map(point => {
pointData.customdata = fullPoint.pointNumbers.map(function (
point
) {
return data[pointData.curveNumber].customdata[point];
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,51 @@ def set_data(dataset):
assert dash_dcc.wait_for_text_to_equal(
"#relayout-data", "[0, -1, -2]"
), "graph data must contain frame [0,-1,-2]"


def test_grbs007_graph_scatter_lines_customdata(dash_dcc):
app = Dash(__name__)

expected_value = "obj-1"

scatter_figures = go.Figure(
data=[
go.Scatter(
x=[0, 1, 1, 0, 0],
y=[1, 1, 2, 2, 1],
mode="lines",
fill="toself",
customdata=[expected_value],
)
]
)

app.layout = html.Div(
[
dcc.Graph(
id="scatter-lines",
figure=scatter_figures,
style={"width": 600, "height": 300},
),
dcc.Textarea(id="test-text-area"),
],
style={"width": 1000, "height": 500},
)

@app.callback(
Output("test-text-area", "value"), Input("scatter-lines", "clickData")
)
def handleClick(clickData):
return json.dumps(clickData)

dash_dcc.start_server(app)
dash_dcc.wait_for_element("#scatter-lines")

dash_dcc.find_elements("g .xy")[0].click()

data = dash_dcc.wait_for_element("#test-text-area").get_attribute("value")
assert data != "", "graph clickData must contain data"

data = json.loads(data)
assert "customdata" in data["points"][0], "graph clickData must contain customdata"
assert data["points"][0]["customdata"][0] == expected_value
8 changes: 6 additions & 2 deletions components/dash-html-components/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ def test_click_static(dash_duo):
[
html.Div("no event listener", className="div-1"),
html.Div("event listener", id="div-2", n_clicks=0),
html.Div("no event listener", id="div-3", n_clicks=0, disable_n_clicks=True),
html.Div("event listener", id="div-4", n_clicks=0, disable_n_clicks=False),
html.Div(
"no event listener", id="div-3", n_clicks=0, disable_n_clicks=True
),
html.Div(
"event listener", id="div-4", n_clicks=0, disable_n_clicks=False
),
html.Div(id="div-output"),
]
)
Expand Down

0 comments on commit 52b73b1

Please sign in to comment.