Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Genealogy diagram (Read 1554 times)
syed
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 1
Joined: Mar 10th, 2012
Genealogy diagram
Mar 10th, 2012 at 3:36am
Print Post  
Hi,
I have a requirement to show genealogy diagram to user based readily available data. Our existing database is as follows
1- Every person has unique ID
2- Relation field's has id of respective persons based on relationship like Father, Mother, Spouse etc.
Please help me with a sample code or hints to accomplish this.
Please help its very urgent
Thanks in advance
Regards
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Genealogy diagram
Reply #1 - Mar 11th, 2012 at 9:10am
Print Post  
Hi,

Code
Select All
var persons = new[]
{
	new Person { Id = 1, Name = "n1" },
	new Person { Id = 2, Name = "n2" },
	new Person { Id = 3, Name = "n3" },
	new Person { Id = 4, Name = "n4" },
	new Person { Id = 5, Name = "n5" }
};
var relations = new[]
{
	new Relation { P1 = 1, P2 = 3, Type = "father" },
	new Relation { P1 = 2, P2 = 3, Type = "mother" },
	new Relation { P1 = 1, P2 = 2, Type = "spouse" },
	new Relation { P1 = 3, P2 = 5, Type = "father" },
	new Relation { P1 = 4, P2 = 5, Type = "mother" },
	new Relation { P1 = 3, P2 = 4, Type = "spouse" }
};

var map = new Dictionary<int, DiagramNode>();
foreach (var person in persons)
{
	var node = diagram.Factory.CreateShapeNode(0, 0, 30, 20);
	node.Text = person.Name;
	map[person.Id] = node;
}
foreach (var rel in relations)
{
	var link = diagram.Factory.CreateDiagramLink(map[rel.P1], map[rel.P2]);
	link.Text = rel.Type;
}

new LayeredLayout().Arrange(diagram);

class Person
{
	public int Id { get; set; }
	public string Name { get; set; }
}

class Relation
{
	public int P1 { get; set; }
	public int P2 { get; set; }
	public string Type { get; set; }
} 



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