Repository navigation
Fix Sankey crash when no link is valid - #8213
Open
Pedroveras-dev wants to merge 2 commits into
Open
Pedroveras-dev wants to merge 2 commits into
Pedroveras-dev wants to merge 2 commits into
Conversation
d3-sankey 0.12 throws 'Invalid array length' when it lays out a graph without nodes. Skip the layout and use an empty graph instead, as in v3.7.0. Fixes plotly#8211
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8211
A Sankey trace with no valid link now renders an empty plot. Before this fix, the trace threw
RangeError: Invalid array length.Problem
[{ type: 'sankey' }], or a trace where all links havevalue: 0, makesPlotly.newPlotthrowRangeError: Invalid array lengthcomputeNodeLayersin@plotly/d3-sankey0.12.3. With zero nodes,max([])returnsundefined, so the column count isNaN. Thennew Array(NaN)throws.Solution
sankeyModelinsrc/traces/sankey/render.jsskips the layout when the graph has zero nodes. It uses an empty graph{ nodes: [], links: [] }instead.calc.jsbuilds the nodes from the valid links. Thus the trace has nodes only when it has at least one valid link.@plotly/d3-sankey. This fix needs no new release of the package. It also covers the circular layout generator, because the layout call does not run for the two generators.Tests
New jasmine tests in
test/jasmine/tests/sankey_test.js:renders a Sankey trace without valid linksswitches between empty and non-empty Sankey on reactResults:
sankeyjasmine suite (Karma), with the fix:TOTAL: 90 SUCCESSrender.js: 2 FAILED withRangeError: Invalid array lengthnpm run lint: exit 0npm run test-syntax: exit 0npm run typecheck: exit 0The change adds no mock and moves no image baseline. Existing figures with nodes take the same code path as before.
🐦