Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, im trying to draw a family tree. i will try to tell the concept
heres the main data table
VB
|ID  | Name | ....| Spouse ID| Mother | Father |
________________________________________________
|p01 | Jhon | ....| p02      |        |        |
________________________________________________
|p02 | Mary | ....| P01      |        |        |
________________________________________________
|p03 |rachel| ....|          |  ps02  |  ps01  |
________________________________________________
|p04 | paul | ....|  p06     |  ps02  |  ps01
________________________________________________
|p05 |jenny | ....|          |  ps02  |  ps01  |
________________________________________________
|p06 |sarah | ....| P04      |  ps02  |  ps01  |
________________________________________________


and i want my end result to be like
VB
     jhon ----- Mary
             |
             |
  ---------------------------------------
 |               |                      |
Rachel           Paul --- Sarah         Jenny
                       |


get the image?

so the logic im trying to use here is that first draw a box which has the text "jhon" then another box with the name "Mary" then connect the two boxes with a line in between and continue such....

VB
Dim x As Integer = 30
        Dim y As Integer = 30
        Dim wid As Integer = 165
        Dim hgt As Integer = 30
        Dim cus As String = Nothing
        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

        For i = 0 To Me.FamilyDataSet1.Persons.Rows.Count - 1
            e.Graphics.DrawRectangle(Pens.Black, x, y, wid, hgt)
            Dim big_font As New Font("Comic Sans MS", 20, FontStyle.Bold, GraphicsUnit.Pixel)
            e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
            e.Graphics.DrawString(FamilyDataSet1.Persons.Rows(i).Item(1), big_font, Brushes.Black, x, y)
            If cus = Nothing Then
                Continue For
            ElseIf cus = FamilyDataSet1.Persons.Rows(i).Item(8) Then
                x += 60
                Continue For
            End If
            cus = FamilyDataSet1.Persons.Rows(i).Item(8)
        Next


Familydataset1 is the dataset used
Persons is the data table
'item(1) and item(8) refers to Name feild and the spouse id feild respectively

what i am trying to do here is after drawing the box check who is the spouse of jhon then draw the box for jhons spouse "mary" by increasing the x cordinate of the jhons rectangle
im stuck from there, rather its all a bit tangled and infact im stuck from the begining itself, please help me.
tanqsss in advance :)

heres a more detailed tree
[^]
Posted
Updated 7-Sep-12 2:21am
v2
Comments
Sergey Alexandrovich Kryukov 6-Sep-12 13:40pm    
Not really clear what's the problem. Perhaps you need to explain more.
It's important to understand that what you call a "family tree" is a graph which is not a tree. The term "family tree" reflects historical paternalistic approach where the female role was majorly ignored... :-)
--SA
osman makhtoom 11-Nov-12 13:55pm    
how i can to create database for the family tree project

I actually did this years ago as a project for my father, but I don't have the source anymore. Basically what you have to do is this:
The key is to break down the solution into smaller bits that are manageable.

1) Decide how to draw a single node on the tree and build that object.
2) Decide how different nodes can be attached to each other and build that object.
3) Decide how the nodes are to be placed on the image based on their relationships.
4) Draw the image.
 
Share this answer
 
Comments
c0derM 8-Sep-12 0:30am    
That seems to be the exact logic im aiming for but how do i space the nodes in the form? and if possible give some code to start with
I would recommend you take a different look at how your database is structured. I would recommend you go with Nested Set Model[^] structure. In combination with a PostreSQL DB (which supports recursive queries) it can be a very powerful solution.

I've implemented this once (actually it was BS degree, but it was a web app) using JavaEE, MySQL (had no idea about Postgres at the time) and JIT (Javascript library for trees / graphs / etc, operating on JSON-based data. You can find it here[^]).

Also, if you really want to try this with desktop and don't wanna go along with web, I'd recommend you take a look at the family tree WPF showcase app[^], the GUI and exec concepts are explained pretty well.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900