Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Event for overriding styles in client side (Read 5408 times)
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Event for overriding styles in client side
Oct 29th, 2013 at 4:34pm
Print Post  
Hi,

I am loading the diagram from server side and in the client side i need to override some styles before the diagram ia draw in the client side. Which is the best method/event that i can use to override the styles?

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event for overriding styles in client side
Reply #1 - Oct 29th, 2013 at 5:12pm
Print Post  
Hi,

You could replace the fromJson: function (json) in Style prototype following the usual approach (e.g. check addHandles in http://mindfusion.eu/Forum/YaBB.pl?num=1370420209), and adjust the style after calling original function.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: Event for overriding styles in client side
Reply #2 - Oct 29th, 2013 at 7:03pm
Print Post  
Hi Stoyan,

I tried the below code, but its never gets executed in the client side.
var actualFromJson = MindFusion.Diagramming.Style.prototype.fromJson;
               MindFusion.Diagramming.Style.prototype.fromJson = function (e) {
                                 actualFromJson.apply(this, [e]);
               }

Also the condition to apply style is stored in each node/link's tag object. I need to get that and apply the styles accordingly.

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event for overriding styles in client side
Reply #3 - Oct 29th, 2013 at 7:38pm
Print Post  
Check if the diagram hasn't already loaded at the time when you are replacing the function. If you need the information for items to be available too, why not just loop over the diagram's nodes / links collections after the page loads and update each item's style?
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: Event for overriding styles in client side
Reply #4 - Oct 30th, 2013 at 6:10am
Print Post  
Hi Stoyan,

Why not just loop over the diagram's nodes / links collections after the page loads and update each item's style

I am doing like that, but the problem is there is a flickering happening when i do like this.
For example the color of the node will be yellow when it comes from the server, and in the client side i will make it as red. So first it draws as yellow and after a delay it will redraw as red.

I need to avoid this flickering issue.


Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event for overriding styles in client side
Reply #5 - Oct 30th, 2013 at 12:14pm
Print Post  
Hi Kiran,

The ControlLoadedScript we added in version 1.6 should be called just after loading items and before drawing them. If you loop over nodes and change their attributes from that script, you shouldn't see them redraw.

You could also replace the Diagram.fromJson function and loop over items after calling the original, that's called even before ControlLoadedScript.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: Event for overriding styles in client side
Reply #6 - Oct 30th, 2013 at 5:04pm
Print Post  
Hi Stoyan,

I have added the below code, but the controlLoaded event is not firing

$(document).ready(function () {
                var diagram = $find("diagramView1");
                diagram.addEventListener("controlLoaded", DiagramLoaded);
            });

function DiagramLoaded(sender, args) {
            alert("loading");
        }

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: Event for overriding styles in client side
Reply #7 - Oct 30th, 2013 at 5:35pm
Print Post  
Hi Stoyan,

I got it. When i hooked the event from server side it is working.
But is there any way to hook it entirely in client side. Coz i don't want to specify my javascript function name in the serverside. I need to consolidate all to client side.

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event for overriding styles in client side
Reply #8 - Oct 31st, 2013 at 9:04am
Print Post  
Hi Kiran,

The Html.DiagramView method generates the component initialization and fromJson calls in a single code block, so you cannot attach to that event on client side before it gets raised, unless you replace Diagram's initialize constructor with the sole purpose of attaching a handler:

Code
Select All
        Sys.Application.add_init(function ()
        {
            var originalInit = MindFusion.Diagramming.Diagram.prototype.initialize;
            MindFusion.Diagramming.Diagram.prototype.initialize = function ()
            {
                originalInit.apply(this, []);
                this.addEventListener("controlLoaded", DiagramLoaded);
            };
        });
 



Or you could replace the Diagram.fromJson function and adjust the styles after calling the original.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint