Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Network: Handle null data gracefully (#3571)
Browse files Browse the repository at this point in the history
* Network: preload images in options for all shape types

Fixes #3532

If the images option is set, preload it, even if the node shape is not `image` or `circularImage`.
This needs to be done because the user can switch to an image shape later, as is happening in the issue.
Option `image` is only mandatory for the image shapes.

There is no unit test for this, because it would need a mock object for Image and I didn't succeed in creating/finding one.

* Network: Handle null data gracefully

During testing I discovered that passing `null` for network data leads to a thrown error.
This adds a guard to prevent it, plus unit tests for regression.
  • Loading branch information
wimrijnders authored and yotamberk committed Oct 14, 2017
1 parent 08af10e commit 1ece237
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/network/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ Emitter(Network.prototype);
* @param {Object} options
*/
Network.prototype.setOptions = function (options) {
if (options === null) {
options = undefined; // This ensures that options handling doesn't crash in the handling
}

if (options !== undefined) {
let errorFound = Validator.validate(options, allOptions);
if (errorFound === true) {
Expand Down
19 changes: 19 additions & 0 deletions test/Network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,25 @@ describe('Network', function () {
createSampleNetwork(options);
});


it('can deal with null data', function() {
// While we're at it, try out other silly values as well
// All the following are wrong, but none should lead to a crash
var awkwardData = [
null,
[1,2,3],
42,
'meow'
];

var container = document.getElementById('mynetwork');

for (var n = 0; n < awkwardData.length; ++n) {
var network = new vis.Network(container, awkwardData[n], {}); // Should not throw
}
});


describe('Node', function () {

it('has known font options', function () {
Expand Down

0 comments on commit 1ece237

Please sign in to comment.