From 9fa9b00fda6580fce709c4d29257c8dd51017ef5 Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Fri, 29 Sep 2017 18:18:29 +0200 Subject: [PATCH] Network: Prevent image loading for hidden cluster nodes (#3492) Fixes #3483. If `shape: 'image'` is defined as option, this was used for initializing hidden cluster nodes during layout initialization. However, because no image is being passed, this led to an exception. This fix prevens shape `image` from being used for hidden cluster nodes. In addition, some extra fields for these nodes are now overridden for some performance improvament. --- lib/network/modules/LayoutEngine.js | 25 ++++++++++++++++--- .../modules/components/shared/Label.js | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/network/modules/LayoutEngine.js b/lib/network/modules/LayoutEngine.js index 7dc04b7e..ccee1a43 100644 --- a/lib/network/modules/LayoutEngine.js +++ b/lib/network/modules/LayoutEngine.js @@ -561,13 +561,32 @@ class LayoutEngine { if (positionDefined < 0.5 * indices.length) { let MAX_LEVELS = 10; let level = 0; - let clusterThreshold = 150; - // Performance enhancement, during clustering edges need only be simple straight lines. + let clusterThreshold = 150; // TODO add this to options + + // + // Define the options for the hidden cluster nodes // These options don't propagate outside the clustering phase. + // + // Some options are explicitly disabled, because they may be set in group or default node options. + // The clusters are never displayed, so most explicit settings here serve as performance optimizations. + // + // The explicit setting of 'shape' is to avoid `shape: 'image'`; images are not passed to the hidden + // cluster nodes, leading to an exception on creation. + // + // All settings here are performance related, except when noted otherwise. + // let clusterOptions = { + clusterNodeProperties:{ + shape: 'ellipse', // Bugfix: avoid type 'image', no images supplied + label: '', // avoid label handling + group: '', // avoid group handling + font: {multi: false}, // avoid font propagation + }, clusterEdgeProperties:{ + label: '', // avoid label handling + font: {multi: false}, // avoid font propagation smooth: { - enabled: false + enabled: false // avoid drawing penalty for complex edges } } }; diff --git a/lib/network/modules/components/shared/Label.js b/lib/network/modules/components/shared/Label.js index 7a98af32..ab17918a 100644 --- a/lib/network/modules/components/shared/Label.js +++ b/lib/network/modules/components/shared/Label.js @@ -64,7 +64,7 @@ class Label { this.initFontOptions(options.font); - if (options.label !== undefined) { + if (options.label !== undefined && options.label !== null && options.label !== '') { this.labelDirty = true; }