Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issue 2493. Passing customdata by userclick #2500

Merged
merged 6 commits into from
May 15, 2023
Merged
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
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