The MindFusion Forums
Flow Diagramming Components >> ASP.NET >> Diagram with custom Node - Image not shown first load
https://mindfusion.eu/Forum/YaBB.pl?num=1491568907

Message started by Ghaith on Apr 7th, 2017 at 12:41pm

Title: Diagram with custom Node - Image not shown first load
Post by Ghaith on Apr 7th, 2017 at 12: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?

Title: Re: Diagram with custom Node - Image not shown first load
Post by Slavcho on Apr 7th, 2017 at 3: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

Title: Re: Diagram with custom Node - Image not shown first load
Post by Ghaith on Apr 7th, 2017 at 6: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

Title: Re: Diagram with custom Node - Image not shown first load
Post by Slavcho on Apr 8th, 2017 at 11:43am
Try this handler -

[code]
imgFile.addEventListener("load", function () {
     img.loaded = true;
     node.invalidate();
});[/code]

Regards,
Slavcho
Mindfusion

Title: Re: Diagram with custom Node - Image not shown first load
Post by Ghaith on Apr 10th, 2017 at 1:44pm
That solved the problem.

Many thanks

Title: Re: Diagram with custom Node - Image not shown first load
Post by Ghaith on Jun 1st, 2017 at 4: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

Title: Re: Diagram with custom Node - Image not shown first load
Post by Slavcho on Jun 1st, 2017 at 6:32pm
Have you also added similar load event handlers for them to repaint the node when image is downloaded?

Title: Re: Diagram with custom Node - Image not shown first load
Post by Ghaith on Jun 2nd, 2017 at 2: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
                }
        }


Title: Re: Diagram with custom Node - Image not shown first load
Post by Slavcho on Jun 5th, 2017 at 8: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.

Title: Re: Diagram with custom Node - Image not shown first load
Post by Ghaith on Jun 5th, 2017 at 11:45am
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?

Title: Re: Diagram with custom Node - Image not shown first load
Post by Slavcho on Jun 5th, 2017 at 1:07pm
Please attach a test project that reproduces it.

Title: Re: Diagram with custom Node - Image not shown first load
Post by Ghaith on Jun 6th, 2017 at 7: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

Title: Re: Diagram with custom Node - Image not shown first load
Post by Slavcho on Jun 7th, 2017 at 1: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();
});[/code]

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

Title: Re: Diagram with custom Node - Image not shown first load
Post by Ghaith on Jun 8th, 2017 at 3:43pm
changing the this did the work.

thanks a lot for your support

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.