From ff5916dc8e6afcf4d2fa28c0f486b7c3a7793190 Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Sat, 24 Jun 2017 14:09:50 +0200 Subject: [PATCH] Set dimensions properly of images on initialization. (#3205) * Set dimensions properly of images on initialization. Fix for #3203 Image nodes were assigned the default size on initialization, leading to very compressed images. This fix adjusts the default size as soon as the images used have been loaded. The approach for dealing with this has been adapted from `CircularImage`. * Fixed tabs --- lib/network/CachedImage.js | 1 + lib/network/modules/components/nodes/shapes/Image.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/network/CachedImage.js b/lib/network/CachedImage.js index ad640017..fde6cb05 100644 --- a/lib/network/CachedImage.js +++ b/lib/network/CachedImage.js @@ -23,6 +23,7 @@ class CachedImage { init() { if (this.initialized()) return; + this.src = this.image.src; // For same interface with Image var w = this.image.width; var h = this.image.height; diff --git a/lib/network/modules/components/nodes/shapes/Image.js b/lib/network/modules/components/nodes/shapes/Image.js index 5905f462..04b15e84 100644 --- a/lib/network/modules/components/nodes/shapes/Image.js +++ b/lib/network/modules/components/nodes/shapes/Image.js @@ -10,6 +10,17 @@ class Image extends CircleImageBase { } resize(ctx, selected = this.selected, hover = this.hover) { + var imageAbsent = (this.imageObj.src === undefined) || + (this.imageObj.width === undefined) || + (this.imageObj.height === undefined); + + if (imageAbsent) { + var side = this.options.size * 2; + this.width = side; + this.height = side; + return; + } + if (this.needsRefresh(selected, hover)) { this._resizeImage(); }