Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic [Help]: Table node Fit to text Width/Height and Diagram Link (Read 5305 times)
Jeetendra
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Location: Germany
Joined: Mar 23rd, 2016
[Help]: Table node Fit to text Width/Height and Diagram Link
Apr 6th, 2016 at 8:22am
Print Post  
Hello MindFusion Team,

I have been playing with JavaScript Components.

//here is my code which i change from your tutorial-1

var Diagram = MindFusion.Diagramming.Diagram;
var DiagramLink = MindFusion.Diagramming.DiagramLink;
var ShapeNode = MindFusion.Diagramming.ShapeNode;

var Rect = MindFusion.Drawing.Rect;
var LayeredLayout = MindFusion.Graphs.LayeredLayout;
var ArrayList = MindFusion.Collections.ArrayList;

var diagram;

$(document).ready(function ()
{
     // create a Diagram component that wraps the "diagram" canvas
     diagram = MindFusion.AbstractionLayer.createControl(Diagram, null, null, null, $("#diagram")[0]);
     diagram.setLinkHeadShapeSize(2);

     // pretend we are calling a web service
     //$.get("Tutorial1.txt", onResponse);
           onResponse("");
     
     var mdiag = MindFusion.Diagramming;
     mdiag.DiagramLink.prototype.setTextBounds = function ()
     {
           var pos = this.points.length % 2 == 1 ?
                 this.points[Math.floor(this.points.length / 2)] :
                 mdiag.Utils.mid(this.points[this.points.length / 2 - 1], this.points[this.points.length / 2]);
           var bounds = new MindFusion.Drawing.Rect(pos.x, pos.y, 0, 0);
           this.text.setBounds(bounds, 0);
     };
});

function onResponse(json)
{
     
           var graph = {
                 "nodes":[
                 {"id":0,"name":"parent 1 TEST TEST TEST For long TExt"},
                 {"id":1,"name":"parent 2"},
                 {"id":2,"name":"Main"},
                 {"id":3,"name":"child 1"},
                 {"id":4,"name":"child 2"},
                 ],
                 "links":[
                 {"origin":0,"target":2},
                 {"origin":1,"target":2},
                 {"origin":2,"target":3},
                 {"origin":2,"target":4},
                 ]};
           buildDiagram(graph);      
}

function buildDiagram(graph)
{
     var nodeMap = [];

     // load node data
     var nodes = graph.nodes;
     ArrayList.forEach(nodes, function (node)
     {
           var diagramNode = diagram.getFactory().createTableNode(0, 0, 18, 8);
           nodeMap[node.id] = diagramNode;
           diagramNode.setText(node.name);
           diagramNode.setBrush("LightGray");
     });

     // load link data
     var links = graph.links;
     ArrayList.forEach(links, function (link)
     {
           var link = diagram.getFactory().createDiagramLink(
                 nodeMap[link.origin],
                 nodeMap[link.target]);
     });

     // arrange the graph            
      var layout = new MindFusion.Graphs.TreeLayout();
layout.direction = MindFusion.Graphs.LayoutDirection.TopToBottom;
layout.levelDistance = 25;
layout.nodeDistance = 15;
layout.linkType = MindFusion.Graphs.TreeLayoutLinkType.Default;
diagram.arrange(layout);
diagram.resizeToFitItems(50);
}

It generates expected output but nodes width is predefined, thats why i loose text inside Tablenode.

my questions are following,

1) is there any way to set fix to text width/height for TableNode?

2) Is there way to add Link which does not have direction Arrow for connection?


You help will be highly appreciable.

Thank you for your continuous support.

  

Regards,
Jeetendra Kumawat
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #1 - Apr 6th, 2016 at 9:29am
Print Post  
Hi Jeetendra,

1. After populating a table, try setting its height to table.getCaptionHeight() + table.rows.length * table.getRowHeight(). You could call Diagram's measureString(text, font, bounds, styled): Size function to find out necessary width.

2. Set ArrowHead property of DiagramLink to null.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Jeetendra
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Location: Germany
Joined: Mar 23rd, 2016
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #2 - Apr 6th, 2016 at 9:52am
Print Post  
Hi Slavcho,

Can you please give me an example how to set height and width with these methods for TableNode?

I do not see height/width property for TableNode. I didn't found measureString(text, font, bounds, styled) method for diagram class.

How do we set these?

  

Regards,
Jeetendra Kumawat
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #3 - Apr 6th, 2016 at 10:06am
Print Post  
Hi Jeetendra,

You can set them through table's Bounds property -

Code
Select All
var height = table.getCaptionHeight() + table.rows.length * table.getRow(0).height;
var maxWidth = 0;
for (var i = 0; i < table.rows.length; i++)
{
	// assuming there's text only in second column
	var cellText = table.getCell(1, i).getText();
	var size = diagram.measureString(cellText, table.getEffectiveFont());
	maxWidth = Math.max(maxWidth, size.width);
}
var newBounds = table.getBounds().clone();
newBounds.width = maxWidth + 10; // some extra space for icon, text padding
newBounds.height = height;
table.setBounds(newBounds); 



measureString is a member of diagram's base Canvas class; we haven't got to defining it in TypeScript yet.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Jeetendra
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Location: Germany
Joined: Mar 23rd, 2016
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #4 - Apr 6th, 2016 at 11:09am
Print Post  
Hi Slavcho,

Thank you for your help. It saved me a lot time.

I have small question regarding TreeLayout which rearrange nodes accordingly to their parent/Child relation.

I have attached a jpeg file which has info about how much i have achieved and what i want to achieve.

Can you please have a look and tell me what sort of diagram link or layout property i need to set to get the desired result?

Thanks.
  

Regards,
Jeetendra Kumawat
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #5 - Apr 6th, 2016 at 11:42am
Print Post  
Hi Jeetendra,

Try setting layout.linkType = MindFusion.Graphs.TreeLayout.LinkTypeCascading;

It will place link starts at bottom side of nodes. You could explicitly set positions of first and last links to be on the sides by setting node's AnchorPattern and assigning links' OriginAnchor and DesintationAnchor. Or maybe loop over nodes after applying TreeLayout, and set StartPoint positions of their first and last outgoing links to align them to sides, and then call links' route() method.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Jeetendra
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Location: Germany
Joined: Mar 23rd, 2016
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #6 - Apr 6th, 2016 at 11:56am
Print Post  
Hi Slavcho,

Tried doing that.

I end up thinking for another way which divides the out going link into two childs as shown in picture.

How would you guide me to achieve this?
  

Regards,
Jeetendra Kumawat
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #7 - Apr 6th, 2016 at 1:05pm
Print Post  
The last image is exactly what the cascading link type does -

Code
Select All
var f = diagram.getFactory();
var t1 = f.createTableNode(0, 0, 30, 30)
var t2 = f.createTableNode(0, 0, 30, 30)
var t3 = f.createTableNode(0, 0, 30, 30)
var t4 = f.createTableNode(0, 0, 30, 30)
f.createDiagramLink(t1, t2);
f.createDiagramLink(t2, t3);
f.createDiagramLink(t2, t4);

var tl = new TreeLayout();
tl.linkType = MindFusion.Graphs.TreeLayoutLinkType.Cascading;
diagram.arrange(tl); 



Regards,
Slavcho
Mindfusion

edit: sorry, seems I've mistyped the dot position in older post
  
Back to top
 
IP Logged
 
Jeetendra
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Location: Germany
Joined: Mar 23rd, 2016
Re: [Help]: Table node Fit to text Width/Height and Diagram Link
Reply #8 - Apr 6th, 2016 at 1:47pm
Print Post  
Hi Slavcho,

Thank you for the help. It does work for Child elements but when it comes to parent it doesn't merge in one link.

// Here is the Code which use & see the diagram For output

var Diagram = MindFusion.Diagramming.Diagram;
var DiagramLink = MindFusion.Diagramming.DiagramLink;
var ShapeNode = MindFusion.Diagramming.ShapeNode;

var Rect = MindFusion.Drawing.Rect;
var LayeredLayout = MindFusion.Graphs.LayeredLayout;
var ArrayList = MindFusion.Collections.ArrayList;

var diagram;

$(document).ready(function ()
{
     // create a Diagram component that wraps the "diagram" canvas
     diagram = MindFusion.AbstractionLayer.createControl(Diagram, null, null, null, $("#diagram")[0]);
     diagram.setLinkHeadShapeSize(2);

           var graph = {
                 "nodes":[
                 {"id":0,"name":"parent 1"},
                 {"id":1,"name":"parent 2"},
                 {"id":2,"name":"Main"},
                 {"id":3,"name":"child 1"},
                 {"id":4,"name":"child 2"},
                 ],
                 "links":[
                 {"origin":0,"target":2},
                 {"origin":1,"target":2},
                 {"origin":2,"target":3},
                 {"origin":2,"target":4},
                 ]};
     
     var nodeMap = [];

     // load node data
     var nodes = graph.nodes;
     ArrayList.forEach(nodes, function (node)
     {
           var diagramNode = diagram.getFactory().createTableNode(0, 0, 18, 8);
           nodeMap[node.id] = diagramNode;
           diagramNode.setText(node.name);
           diagramNode.setBrush("LightGray");
     });

     // load link data
     var links = graph.links;
     ArrayList.forEach(links, function (link)
     {
           var link = diagram.getFactory().createDiagramLink(
                 nodeMap[link.origin],
                 nodeMap[link.target]);
                 
                 link.route();
     });
     
     

     // arrange the graph            
      var layout = new MindFusion.Graphs.TreeLayout();
layout.direction = MindFusion.Graphs.LayoutDirection.TopToBottom;
layout.levelDistance = 15;
layout.nodeDistance = 10;
layout.linkType = MindFusion.Graphs.TreeLayoutLinkType.Cascading;
diagram.arrange(layout);
diagram.resizeToFitItems(50);
     
});



Is there something wrong i did or its right output with TreeLayout?
« Last Edit: Apr 7th, 2016 at 7:36am by Jeetendra »  

Regards,
Jeetendra Kumawat
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint