Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to create custom layout? (Read 1300 times)
Ankur shah
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Mar 16th, 2017
How to create custom layout?
Sep 5th, 2019 at 6:48am
Print Post  
Can you please let me know what is correct way to build custom layout in mindfusion?
So that we can handle resizeToFitText() and arrange animated function on my custom layout.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: How to create custom layout?
Reply #1 - Sep 5th, 2019 at 6:58am
Print Post  
You could set node.Bounds and link.ControlPoints values if all you need is custom positions.

If you want to integrate it with diagram's arrange method, e.g. for handling unconnected subgraphs or animations, you will need to implement MyLayout.prototype.arrange = function (graph) method, that works with Graph, Vertex and Edge objects from MindFusion.Graphs namespace. E.g. see FractalLayout.js if you have the source code, or otherwise our developer could post a sample layout class for some simple tabular arrangement.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Ankur shah
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Mar 16th, 2017
Re: How to create custom layout?
Reply #2 - Sep 5th, 2019 at 7:54am
Print Post  
We don't have source code for mindfusion library. Can you please send me some example?
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: How to create custom layout?
Reply #3 - Sep 5th, 2019 at 12:11pm
Print Post  
Hi,

Below is a simple custom layout that just orders the nodes in a diagram in a grid-like pattern:
Code (Javascript)
Select All
var MyLayout = function ()
{
	this.multipleGraphsPlacement = MindFusion.Graphs.MultipleGraphsPlacement.Horizontal;
	this.margins = 5; // margins from the top left
	this.cols = 5; // nodes per row

	// grid sizes
	this.offsetX = 40;
	this.offsetY = 40;
};

MyLayout.prototype.arrange = function (graph)
{
	var x = 0, y = 0;
	for (var i = 0, col = 1; i < graph.vertices.length; i++, ++col)
	{
		var node = graph.vertices[i];
		node.x = x + node.width / 2;
		node.y = y + node.height / 2;
		x += this.offsetX;

		if (col >= this.cols)
		{
			col = 0;
			x = 0;
			y += this.offsetY;
		}
	}
}; 



To use it, just pass a new instance to the arrange method of the diagram:
Code (Javascript)
Select All
function arrangeCustom()
{
    var layout = new MyLayout();
    diagram.arrange(layout);
} 



Regards,
Lyubo
MindFusion
« Last Edit: Sep 5th, 2019 at 1:23pm by Lyubo »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint