Browse Source

Network: preload images in options for all shape types (#3570)

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.
mbroad/code-climate-coverage-develop
wimrijnders 7 years ago
committed by Yotam Berkowitz
parent
commit
08af10e985
1 changed files with 7 additions and 6 deletions
  1. +7
    -6
      lib/network/modules/components/Node.js

+ 7
- 6
lib/network/modules/components/Node.js View File

@ -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) {

Loading…
Cancel
Save