Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Re: is this possible-Urgent (Read 3182 times)
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: is this possible-Urgent
Oct 23rd, 2008 at 3:13pm
Print Post  
Flowchart.NET cannot automatically read graph data from a database. You will need to use a data reader or a dataset object to load the data yourself, and call the respective methods from the control's API to create the chart elements.

First call Diagram.Factory.CreateShapeNode() in a loop for each record in PersonInfo, and map the person IDs to their corresponding ShapeNodes, either via a Hashmap or by assigning the id to ShapeNode.Tag. Next, loop over the relationship table and call CreateDiagramLink(), using the hashmap or Diagram.FindNode() to find the origin and destination nodes corresponding to the related person IDs.

Finally create a layout class instance, for example SpringLayout, and call its Arrange method.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: is this possible-Urgent
Reply #1 - Oct 23rd, 2008 at 3:48pm
Print Post  
Call CreateShapeNode to add an object representing a person record, and CreateDiagramLink to add an object representing a relationship record. For example

Code
Select All
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Person";
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
	ShapeNode node = diagram.Factory.CreateShapeNode(0, 0, 40, 30);
	node.Tag = reader.GetInt32(0);
	node.Text = reader.GetString(1);
}
reader.Close();

cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Relationship";
reader = cmd.ExecuteReader();
while (reader.Read())
{
	diagram.Factory.CreateDiagramLink(
		diagram.FindNode(reader.GetInt32(1)),
		diagram.FindNode(reader.GetInt32(2)));
}

AnnealLayout al = new AnnealLayout();
al.Arrange(diagram);
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: is this possible-Urgent
Reply #2 - Oct 25th, 2008 at 9:14am
Print Post  
You can use a simple loop to arrange the nodes in a row, with the links arching above them at a height proportional to the node distance:

Code
Select All
for (int i = 0; i < diagram.Nodes.Count; ++i)
{
	DiagramNode node = diagram.Nodes[i];
	node.Bounds = new RectangleF(20 + i * 90, 50, 50, 35);
}

foreach (DiagramLink link in diagram.Links)
{
	link.Style = LinkStyle.Bezier;
	link.SegmentCount = 1;

	RectangleF o = link.Origin.Bounds;
	RectangleF d = link.Destination.Bounds;
	PointCollection p = link.ControlPoints;

	p[0] = new PointF((o.Left + o.Right) / 2, o.Top);
	p[3] = new PointF((d.Left + d.Right) / 2, d.Top);
	float h = p[3].X - p[0].X;

	p[1] = new PointF(p[0].X, p[0].Y - h / 4);
	p[2] = new PointF(p[3].X, p[3].Y - h / 4);

	link.UpdateFromPoints();
}
 



You can't render links like these with the standard Flowchart.NET link styles, but you could try custom drawing them by setting link.CustomDraw = Full and handling the DrawLink event.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: is this possible-Urgent
Reply #3 - Oct 31st, 2008 at 3:05pm
Print Post  
Are you still applying the tree or spring  layout? You shouldn't use it now that you are taking care of the node positions yourself.
  
Back to top
 
IP Logged
 
vars
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 1
Joined: Oct 23rd, 2008
Re: is this possible-Urgent
Reply #4 - Oct 31st, 2008 at 3:14pm
Print Post  
you are simply great Grin
thanks a lot
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint