Skip to content

Commit

Permalink
Newly added elements should not have their style initially updated tw…
Browse files Browse the repository at this point in the history
…ice from false background image loading detection #2016

Caused by : Allow for background image properties to be specified as multiples (i.e. arrays or space separated strings) #1747

The check for whether background images are loading is incorrect, as the count of images does not take into account invalid/null entries.
  • Loading branch information
maxkfranz committed Nov 10, 2017
1 parent 9f569e1 commit 17791a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/collection/element.js
Expand Up @@ -64,7 +64,8 @@ let Element = function( cy, params, restore ){
edges: [], // array of connected edges
children: [], // array of children
parent: null, // parent ref
traversalCache: {} // cache of output of traversal functions
traversalCache: {}, // cache of output of traversal functions
backgrounding: false // whether background images are loading
};

// renderedPosition overrides if specified
Expand Down
20 changes: 11 additions & 9 deletions src/extensions/renderer/canvas/drawing-nodes.js
Expand Up @@ -45,16 +45,18 @@ CRp.drawNode = function( context, node, shiftToOriginWithBb, drawLabel ){

let bgImgProp = node.pstyle( 'background-image' );
let urls = bgImgProp.value;
let url;
let urlDefined = [];
let image = [];
let numImages = urls.length;
for( let i = 0; i < numImages; i++ ){
url = urls[i];
urlDefined[i] = url != null && url !== 'none';
if( urlDefined[i] ){
let urlDefined = new Array( urls.length );
let image = new Array( urls.length );
let numImages = 0;
for( let i = 0; i < urls.length; i++ ){
let url = urls[i];
let defd = urlDefined[i] = url != null && url !== 'none';

if( defd ){
let bgImgCrossOrigin = node.cy().style().getIndexedStyle(node, 'background-image-crossorigin', 'value', i);

numImages++;

// get image, and if not loaded then ask to redraw when later loaded
image[i] = r.getCachedImage( url, bgImgCrossOrigin, function(){
node.emitAndNotify('background');
Expand Down Expand Up @@ -153,7 +155,7 @@ CRp.drawNode = function( context, node, shiftToOriginWithBb, drawLabel ){
let prevBging = _p.backgrounding;
let totalCompleted = 0;

for( let i = 0; i < numImages; i++ ){
for( let i = 0; i < image.length; i++ ){
if( urlDefined[i] && image[i].complete && !image[i].error ){
totalCompleted++;
r.drawInscribedImage( context, image[i], node, i, nodeOpacity );
Expand Down

0 comments on commit 17791a7

Please sign in to comment.