Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix graph customdata for pointnumbers #1942

Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- [#1953](https://github.com/plotly/dash/pull/1953) Fix bug [#1783](https://github.com/plotly/dash/issues/1783) in which a failed hot reloader blocks the UI with alerts.

- [#1942](https://github.com/plotly/dash/pull/1942) Fix bug [#1663](https://github.com/plotly/dash/issues/1663) preventing pie traces from sending `customdata` with `clickData` and other events.

## [2.2.0] - 2022-02-18

### Added
Expand Down
15 changes: 10 additions & 5 deletions components/dash-core-components/src/fragments/Graph.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ const filterEventData = (gd, eventData, event) => {

if (
has('curveNumber', fullPoint) &&
has('pointNumber', fullPoint) &&
has('customdata', data[pointData.curveNumber])
) {
pointData.customdata =
data[pointData.curveNumber].customdata[
fullPoint.pointNumber
];
if (has('pointNumber', fullPoint)) {
pointData.customdata =
data[pointData.curveNumber].customdata[
fullPoint.pointNumber
];
} else if (has('pointNumbers', fullPoint)) {
pointData.customdata = fullPoint.pointNumbers.map(point => {
return data[pointData.curveNumber].customdata[point];
});
}
}

// specific to histogram. see https://github.com/plotly/plotly.js/pull/2113/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from multiprocessing import Value, Lock
import numpy as np
from time import sleep
import plotly.express as px
import plotly.graph_objects as go
from dash import Dash, Input, Output, dcc, html

Expand Down Expand Up @@ -165,7 +166,46 @@ def update_graph(n_clicks):
assert dash_dcc.get_logs() == []


def test_grbs005_graph_update_frames(dash_dcc):
def test_grbs005_graph_customdata(dash_dcc):
app = Dash(__name__)

df = px.data.tips()
df["id"] = df.index

app.layout = html.Div(
[
dcc.Graph(
id="pie-chart",
figure=go.Figure(
data=[
go.Pie(
labels=df["day"], ids=df["id"].map(str), customdata=df["id"]
)
]
),
),
dcc.Textarea(id="text-area"),
]
)

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

dash_dcc.start_server(app)
dash_dcc.wait_for_element("#pie-chart")

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

data = dash_dcc.wait_for_element("#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] == data["points"][0]["pointNumbers"][0]


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

def get_scatter(multiplier, offset):
Expand Down