From 08af10e9851781fd40d02429fc1a42a31a74d0b2 Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Sat, 14 Oct 2017 09:41:41 +0200 Subject: [PATCH] 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. --- lib/network/modules/components/Node.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/network/modules/components/Node.js b/lib/network/modules/components/Node.js index f4b70e11..828d5c3f 100644 --- a/lib/network/modules/components/Node.js +++ b/lib/network/modules/components/Node.js @@ -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) {