- Welcome, Guest. Please Login or Register
MindFusion  
  Version 2 of our Xamarin Calendar component adds Resource view and support for Universal Windows Platform. Now beta testing spreadsheet component for Java Swing. We have released our Java Swing Pack.  
  HomeHelpSearchLoginRegister   
     
     
   
 
Page Index Toggle Pages: 1 Send Topic Print  
Diagram with custom Node - Image not shown first load
Read 828 times

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Diagram with custom Node - Image not shown first load
Apr 7th, 2017 at 1:41pm
 
I have created a custom node containing couple of text and images, and was working fine, but the nodes started to load with the text only, and the images is not there, until I click on the node, then the images appeared. I don't know If it is because something I did or some property I changed.

I checked the console in Chrome, the function "updateCanvasElements" already called and the images are pushed.
I tested on IE, everything is okay as usual.

I searched, but nothing I could found or someone having the same problem.

Any Ideas? Hin?
 
 
« Last Edit: Apr 7th, 2017 at 3:04pm by Ghaith »
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 1103
Gender: male
tech.support


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #1 - Apr 7th, 2017 at 4:47pm
 
The DOM image might have not downloaded yet the first time you try to draw it. You could check the image.complete property, and if it's false call diagram.repaint() to schedule a redraw. You could as well subscribe to the image.load event. That's similar to what was discussed in this thread - http://mindfusion.eu/Forum/YaBB.pl?num=1488530760/15#15
 
 
 
IP Logged    
 
     

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #2 - Apr 7th, 2017 at 7:32pm
 
Dear this is the code I am using
//Add image
var imgFile = new Image();
imgFile.src = 'data:image/png;base64,' + f.value;
imgFile.addEventListener("load", function () {
                });

var img = new MindFusion.Drawing.Image(
new MindFusion.Drawing.Rect(this.bounds.x + p.position_X, this.bounds.y + p.position_Y, p.width, p.height));
img.image = imgFile;
img.loaded = imgFile.complete;

this.graphicsContainer.content.push(img);

but this didn't help
 
 
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 1103
Gender: male
tech.support


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #3 - Apr 8th, 2017 at 12:43pm
 
Try this handler -

Code:
imgFile.addEventListener("load", function () {
	img.loaded = true;
	node.invalidate();
}); 



Regards,
Slavcho
Mindfusion
 
 
 
IP Logged    
 
     

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #4 - Apr 10th, 2017 at 2:44pm
 
That solved the problem.

Many thanks
 
 
 
IP Logged    
 
     

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #5 - Jun 1st, 2017 at 5:09pm
 
Dear,

Previously I was using only 1 image per node and it worked correctly, but now I added multi image to same node. 3 images in my case used as buttons.

My Issue is that the first 2 images is not shown on the node on the first load, unless I select the node - I think a repaint function executed -, but the last image shown directly and no problem in it.

any ideas
 
 
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 1103
Gender: male
tech.support


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #6 - Jun 1st, 2017 at 7:32pm
 
Have you also added similar load event handlers for them to repaint the node when image is downloaded?
 
 
 
IP Logged    
 
     

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #7 - Jun 2nd, 2017 at 3:35pm
 
yes, I have the same way for all images
here is my code, where I am doing a loop for all the fields stored in the node Tag, and I tried to pass the image src as base64 and another time as a link, and always only the last one pushed is the one that appears normally.

Note: This issue happened on Google chrome, but not on IE.

Code:
        for (var i = 0; i < this.tag.fields.length; i++) {
            var f = this.tag.fields[i];
            var p = f.fieldPattern;
            if (p != null) {
                if (f.isImage) {
                    //Add image
                    var imgFile = new Image();
                    imgFile.src = f.value;

                    var img = new MindFusion.Drawing.Image(
                        new MindFusion.Drawing.Rect(this.bounds.x + p.position_X, this.bounds.y + p.position_Y, p.width, p.height));
                    img.image = imgFile;
                    img.loaded = imgFile.complete;
                    imgFile.addEventListener("load", function () {
                        img.loaded = true;
                        if (this.parent)
                            this.invalidate();
                    });
                    this.graphicsContainer.content.push(img);
                }
                else {
                    //add label
                }
        }
 


 
 
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 1103
Gender: male
tech.support


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #8 - Jun 5th, 2017 at 9:04am
 
Have you verified the code calls content.push(img) more than once, and that the image positions are different? Working under IE but not Chrome sounds strange - try clearing Chrome's cache in case it's using older version of your script, and check if there are error shown in console.
 
 
 
IP Logged    
 
     

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #9 - Jun 5th, 2017 at 12:45pm
 
Content.Push(img) is called for every image, and the positions are different, if you prefer I can send you a screen recording presenting the issue?
 
 
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 1103
Gender: male
tech.support


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #10 - Jun 5th, 2017 at 2:07pm
 
Please attach a test project that reproduces it.
 
 
 
IP Logged    
 
     

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #11 - Jun 6th, 2017 at 8:04pm
 
Dear,

I couldn't attach the project here, please check the following link, I uploaded it to DropBox

https://www.dropbox.com/s/ndg1wx6v7qygkhe/ImageLoadingTest.rar?dl=0
 
 
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 1103
Gender: male
tech.support


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #12 - Jun 7th, 2017 at 2:36pm
 
The problem is 'this' in nested function does not refer to the node but to the global window object. You will need to remember it in closure -

Code:
var This = this;
imgFile.addEventListener("load", function ()
{
	img.loaded = true;
	if (This.parent)
		This.invalidate();
}); 



Also updateCanvasElements itself does not seem best place to create and load image objects. Instead load them from constructor or from the fromJson overload, saving all images in an array, and then only add the already-loaded array elements when updateCanvas is called.

Regards,
Slavcho
 
 
 
IP Logged    
 
     

Ghaith   Offline
YaBB Newbies
*
Posts: 18
I Love MindFusion!


   
     
 
Re: Diagram with custom Node - Image not shown first load
Reply #13 - Jun 8th, 2017 at 4:43pm
 
changing the this did the work.

thanks a lot for your support
 
 
 
IP Logged    
 
     
Page Index Toggle Pages: 1 Send Topic Print