Skip to content

Commit

Permalink
Fixed highcharts#9803, networkgraph throwing maximum call stack error…
Browse files Browse the repository at this point in the history
… with cyclical links.
  • Loading branch information
trentmwillis committed Jan 4, 2019
1 parent cff8d96 commit 4d2d274
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions js/modules/networkgraph/layouts.js
Expand Up @@ -212,12 +212,18 @@ H.extend(
rootNodes = nodes.filter(function (node) {
return node.linksTo.length === 0;
}),
sortedNodes = [];
sortedNodes = [],
visitedLinks = [];

function addToNodes(node) {
node.linksFrom.forEach(function (link) {
if (visitedLinks.indexOf(link) !== -1) {
return;
}

visitedLinks.push(link);
sortedNodes.push(link.toNode);
addToNodes(link.toNode);
addToNodes(link.toNode); // HERE
});
}

Expand Down
@@ -0,0 +1,6 @@
---
resources:
- https://code.jquery.com/qunit/qunit-2.0.1.js
- https://code.jquery.com/qunit/qunit-2.0.1.css
js_wrap: b
...
7 changes: 7 additions & 0 deletions samples/unit-tests/series-networkgraph/networkgraph/demo.html
@@ -0,0 +1,7 @@
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/networkgraph.js"></script>

<div id="qunit"></div>
<div id="qunit-fixture"></div>

<div id="container"></div>
23 changes: 23 additions & 0 deletions samples/unit-tests/series-networkgraph/networkgraph/demo.js
@@ -0,0 +1,23 @@
QUnit.test('Network Graph', function (assert) {
var chart = Highcharts.chart('container', {});

chart.addSeries({
layoutAlgorithm: {
enableSimulation: false
},
keys: ['from', 'to'],
data: [
['A', 'B'],
['B', 'A'],
['C', 'A']
],
type: 'networkgraph'
});

assert.strictEqual(
chart.series[0].points.length,
3,
'Series successfully added'
);

});

0 comments on commit 4d2d274

Please sign in to comment.