Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to know alternate containers (Read 6189 times)
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
How to know alternate containers
Nov 5th, 2013 at 1:32pm
Print Post  
Hi,

Is there any way to find alternate containers in java script. I need to give different color for alternate container nodes.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to know alternate containers
Reply #1 - Nov 5th, 2013 at 6:52pm
Print Post  
Hi,

What do you mean by an alternate container?

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


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: How to know alternate containers
Reply #2 - Nov 6th, 2013 at 6:55am
Print Post  
Hi,

Container T1 with children T2, T3 and T4 containers, in which T2 is inside T1 and T3 inside T2 and T4 inside T3.

I need to give different color for T1 and T3.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to know alternate containers
Reply #3 - Nov 6th, 2013 at 9:37am
Print Post  
Hi,

Code
Select All
var nestedCtrColors = ["white", "gray"];

function outermostContainer(node)
{
	if (node.container)
		return outermostContainer(node.container);

	if (node.children)
		return node;

	return null;
}

function colorNestedContainers(container, level)
{
	container.setBrush(nestedCtrColors[level % nestedCtrColors.length]);
	Array.forEach(container.children, function (child)
	{
		if (child.children)
			colorNestedContainers(child, level + 1);
	});
}

function onContainerChildAdded(sender, args)
{
	var ctr = args.getContainer();
	colorNestedContainers(outermostContainer(ctr), 0);
}

function onContainerChildRemoved(sender, args)
{
	var node = args.getNode();
	if (node.children)
		colorNestedContainers(outermostContainer(node), 0);
} 



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: How to know alternate containers
Reply #4 - Nov 7th, 2013 at 2:03pm
Print Post  
Hi Stoyan,

I am loading the diagram from xml and after that i need to apply the styles.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to know alternate containers
Reply #5 - Nov 7th, 2013 at 4:18pm
Print Post  
Do you mean you need to set the colors on server side?
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: How to know alternate containers
Reply #6 - Nov 7th, 2013 at 6:43pm
Print Post  
Hi Stoyan,

I am loading the xml in the server, but i need to apply the alternate color style in the client side.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to know alternate containers
Reply #7 - Nov 7th, 2013 at 7:21pm
Print Post  
Call the colorNestedContainers function above for all outermost containers after the diagram has been loaded on client side:

Code
Select All
Array.forEach(diagram.nodes, function (node)
{
	if (node.children && !node.container)
		colorNestedContainers(node, 0);
}); 



"node.children" checks whether the node is a container, "node.container" checks if it's inside another container.

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