Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
Network: preload images in options for all shape types (almende#3570)
Browse files Browse the repository at this point in the history
Fixes almende#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.
  • Loading branch information
wimrijnders authored and mojoaxel committed Jun 9, 2019
1 parent 2eff28c commit 615a8f2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/network/modules/components/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,20 @@ class Node {
/**
* Load the images from the options, for the nodes that need them.
*
* TODO: The imageObj members should be moved to CircularImageBase.
* It's the only place where they are required.
* Images are always loaded, even if they are not used in the current shape.
* The user may switch to an image shape later on.
*
* @private
*/
_load_images() {
// Don't bother loading for nodes without images
if (this.options.shape !== 'circularImage' && this.options.shape !== 'image') {
return;
if (this.options.shape === 'circularImage' || this.options.shape === 'image') {
if (this.options.image === undefined) {
throw new Error("Option image must be defined for node type '" + this.options.shape + "'");
}
}

if (this.options.image === undefined) {
throw new Error("Option image must be defined for node type '" + this.options.shape + "'");
return;
}

if (this.imagelist === undefined) {
Expand Down

0 comments on commit 615a8f2

Please sign in to comment.