Skip to content

Commit

Permalink
Fix bug where graph would become unresponsive if an invalid figure wa…
Browse files Browse the repository at this point in the history
…s passed
  • Loading branch information
KoolADE85 committed Dec 11, 2024
1 parent 35ced08 commit 2a640fb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/dash-core-components/src/fragments/Graph.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ class PlotlyGraph extends Component {
configClone.typesetMath = mathjax;

const figureClone = {
data: figure.data,
layout: this.getLayout(figure.layout, responsive),
frames: figure.frames,
data: figure?.data,
layout: this.getLayout(figure?.layout, responsive),
frames: figure?.frames,
config: configClone,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,44 @@ def handleClick(clickData):
data = json.loads(data)
assert "customdata" in data["points"][0], "graph clickData must contain customdata"
assert data["points"][0]["customdata"][0] == expected_value


def test_grbs008_graph_with_empty_figure(dash_dcc):
app = Dash(__name__)
app.layout = html.Div(
[
html.Button("Toggle graph", id="btn"),
dcc.Graph(
id="graph",
figure=None,
),
]
)

@app.callback(Output("graph", "figure"), [Input("btn", "n_clicks")])
def toggle_figure(n_clicks):
if int(n_clicks or 0) % 2 == 0:
# a valid figure
return go.Figure([], layout=go.Layout(title="Valid Figure"))
else:
# an invalid figure
return None

dash_dcc.start_server(app)

# Click the toggle button a couple of times and expect the graph to change between the
# valid and invalid figures, using the "title" as the indicator.
dash_dcc.wait_for_element("#graph")
wait.until(
lambda: dash_dcc.find_element(".gtitle").text == "Valid Figure", timeout=2
)

dash_dcc.find_element("#btn").click()
wait.until(lambda: len(dash_dcc.find_elements(".gtitle")) == 0, timeout=2)

dash_dcc.find_element("#btn").click()
wait.until(
lambda: dash_dcc.find_element(".gtitle").text == "Valid Figure", timeout=2
)

assert dash_dcc.get_logs() == []

0 comments on commit 2a640fb

Please sign in to comment.