* Diagram code question
-
British Kiwi
- Famous
- Posts: 106
- Joined: 14 Sep 2014 09:59
- Family Historian: V7
Diagram code question
Hi
I decided to have a crack and writing a bit of very minor code in a fan chart. I have a full fan chart but in the centre I have the root person plus all siblings. Basically I wanted to do one for my two kids. After a lot of tweaking I finally have it in a way that will work even if the second child is selected as the root person, but I'm sure there is a neater way of writing code. (My experience is VBA so this is a little new to me). Also, I only have it for three children (I'm certainly not planning on having more than three kids), but is there a way to loop for x number of kids or should I just create 10 instances of it.
Here is the code I have written:
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, %INDI.FAMC[1]>CHIL[1]>NAME[1]%, %INDI.NAME%)
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, ExistsText(%INDI.FAMC[1]>CHIL[1]>%,"(" . LifeDates2(%INDI.FAMC[1]>CHIL[2]>%,STD) . ")"), "(" . LifeDates2(%INDI%,STD) . ")")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, %INDI.FAMC[1]>CHIL[2]>NAME[1]%, "")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, ExistsText(%INDI.FAMC[1]>CHIL[2]>%,"(" . LifeDates2(%INDI.FAMC[1]>CHIL[2]>%,STD) . ")"),"")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, %INDI.FAMC[1]>CHIL[3]>NAME[1]%, "")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, ExistsText(%INDI.FAMC[1]>CHIL[3]>%,"(" . LifeDates2(%INDI.FAMC[1]>CHIL[3]>%,STD) . ")"),"")
P.S. Is there a way to add comments?
I decided to have a crack and writing a bit of very minor code in a fan chart. I have a full fan chart but in the centre I have the root person plus all siblings. Basically I wanted to do one for my two kids. After a lot of tweaking I finally have it in a way that will work even if the second child is selected as the root person, but I'm sure there is a neater way of writing code. (My experience is VBA so this is a little new to me). Also, I only have it for three children (I'm certainly not planning on having more than three kids), but is there a way to loop for x number of kids or should I just create 10 instances of it.
Here is the code I have written:
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, %INDI.FAMC[1]>CHIL[1]>NAME[1]%, %INDI.NAME%)
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, ExistsText(%INDI.FAMC[1]>CHIL[1]>%,"(" . LifeDates2(%INDI.FAMC[1]>CHIL[2]>%,STD) . ")"), "(" . LifeDates2(%INDI%,STD) . ")")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, %INDI.FAMC[1]>CHIL[2]>NAME[1]%, "")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, ExistsText(%INDI.FAMC[1]>CHIL[2]>%,"(" . LifeDates2(%INDI.FAMC[1]>CHIL[2]>%,STD) . ")"),"")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, %INDI.FAMC[1]>CHIL[3]>NAME[1]%, "")
=TextIf(%INDI%=%CUR_DGM_ROOT.NAME[1]%, ExistsText(%INDI.FAMC[1]>CHIL[3]>%,"(" . LifeDates2(%INDI.FAMC[1]>CHIL[3]>%,STD) . ")"),"")
P.S. Is there a way to add comments?
- tatewise
- Megastar
- Posts: 27081
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Diagram code question
That is quite good for a first attempt.
Unfortunately, there is no way to add comments - perhaps something for the Wish List.
Regarding your code here are some suggestions.
Unfortunately, there is no way to add comments - perhaps something for the Wish List.
Regarding your code here are some suggestions.
- The test %INDI%=%CUR_DGM_ROOT.NAME[1]% is unreliable, and .NAME[1] is not needed.
If both the Individual and Current Root happen to have same name it goes wrong.
You need to use RecordId(%INDI%)=RecordId(%CUR_DGM_ROOT%) since RecordId are unique. - =TextIf(RecordId(%INDI%)=RecordId(%CUR_DGM_ROOT%), %INDI.FAMC[1]>CHIL[1]>NAME[1]%, %INDI.NAME%) displays nothing if the Current Root has no siblings.
i.e. The RecordId test is true, but %INDI.FAMC[1]>CHIL[1]>NAME[1]% does not exist, so you need a test like:
RecordId(%INDI%)=RecordId(%CUR_DGM_ROOT%) and Exists(%INDI.FAMC[1]>CHIL[1]>%) - The same test is needed for the 1st child LifeDates too
- There is typo in the 1st child LifeDates2(%INDI.FAMC[1]>CHIL[2]>%,STD) it should use CHIL[1]
- There is no looping option, and even the looping index [1+] does not work in this context, so you just have to repeat for all instances, but with all that extra text I don't think it will display in one box.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- Jane
- Site Admin
- Posts: 8441
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Diagram code question
Another option might be to use Previous and Next Sibling which keeps the code simpler.
=PrevSib(%CUR_DGM_ROOT%,2) =LifeDates(PrevSib(%CUR_DGM_ROOT%,2))
=PrevSib(%CUR_DGM_ROOT%,1) =LifeDates(PrevSib(%CUR_DGM_ROOT%,1))
=NextSib(%CUR_DGM_ROOT%,1) =LifeDates(NextSib(%CUR_DGM_ROOT%,1))
=NextSib(%CUR_DGM_ROOT%,2) =LifeDates(NextSib(%CUR_DGM_ROOT%,2))
=PrevSib(%CUR_DGM_ROOT%,2) =LifeDates(PrevSib(%CUR_DGM_ROOT%,2))
=PrevSib(%CUR_DGM_ROOT%,1) =LifeDates(PrevSib(%CUR_DGM_ROOT%,1))
=NextSib(%CUR_DGM_ROOT%,1) =LifeDates(NextSib(%CUR_DGM_ROOT%,1))
=NextSib(%CUR_DGM_ROOT%,2) =LifeDates(NextSib(%CUR_DGM_ROOT%,2))
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
- tatewise
- Megastar
- Posts: 27081
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Diagram code question
I have just tried that script Jane, but it does not work satisfactorily.
It repeats the same sibling(s) in every segment of the Fan Chart, and omits the Diagram Root Individual.
So if there are no siblings it displays nothing at all!
What might work is to replace each instance of:
%INDI.FAMC[1]>CHIL[1]>NAME[1]%
with:
PrevSib(%INDI%,2) or NextSib(%INDI%,2)
and
LifeDates2(%INDI.FAMC[1]>CHIL[1]>%,STD)
with
LifeDates(PrevSib(%INDI%,2)) or LifeDates(NextSib(%INDI%,2))
taking care to use the appropriate numerical parameters.
It repeats the same sibling(s) in every segment of the Fan Chart, and omits the Diagram Root Individual.
So if there are no siblings it displays nothing at all!
What might work is to replace each instance of:
%INDI.FAMC[1]>CHIL[1]>NAME[1]%
with:
PrevSib(%INDI%,2) or NextSib(%INDI%,2)
and
LifeDates2(%INDI.FAMC[1]>CHIL[1]>%,STD)
with
LifeDates(PrevSib(%INDI%,2)) or LifeDates(NextSib(%INDI%,2))
taking care to use the appropriate numerical parameters.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- Jane
- Site Admin
- Posts: 8441
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Diagram code question
Ok, I would have ungrouped the chart and just edited the text on the center segment. I only posted the code for the sibling logic rather than all.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
-
British Kiwi
- Famous
- Posts: 106
- Joined: 14 Sep 2014 09:59
- Family Historian: V7
Re: Diagram code question
Thank you so much. I will have a play later. I found another thread about ungrouping charts, does that mean that I can just add this code to one section ie the centre? If so I wouldn't need the part checking for the root person.
- tatewise
- Megastar
- Posts: 27081
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Diagram code question
Yes, but even then it omits the Root Individual who is any one of the siblings, and displays nothing if there are no siblings.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
-
British Kiwi
- Famous
- Posts: 106
- Joined: 14 Sep 2014 09:59
- Family Historian: V7
Re: Diagram code question
Great I will stick with your suggestions. Is there a list of functions that can be used in this context? I could only find information for writing 'proper' functions. (I hope that makes sense).
- tatewise
- Megastar
- Posts: 27081
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Diagram code question
Sorry, I do not understand what you mean by "proper" functions. Potentially, all functions can be used in all contexts where Expressions are allowed.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
-
British Kiwi
- Famous
- Posts: 106
- Joined: 14 Sep 2014 09:59
- Family Historian: V7
Re: Diagram code question
It's been so long since I did any programming I've forgotten the terminology. When I said proper I meant things like call functions and non-proper I meant expressions. I googled Lua If statements and so tried using "if...then...else...end if" which is the same as I was used to and that didn't work. Obviously I must have missed something. What I ak lookingfir at the moment would be a list of things like TextExists etc.
-
British Kiwi
- Famous
- Posts: 106
- Joined: 14 Sep 2014 09:59
- Family Historian: V7
Re: Diagram code question
How does PrevSib and NextSib work? Just wondering how it would be affected by the person I select. So if I choose the eldest as my root person, or the third out of five, how would this show? It probably makes sense to list all the siblings in chronological order.
-
delwoodman
- Famous
- Posts: 125
- Joined: 15 Sep 2007 10:42
- Family Historian: V6.2
- Location: Brighton, East Sussex, UK
Re: Diagram code question
If you look at "Understanding Functions" in the Help files you will see an explanation of FH functions and links to other relevant pages, including a full list of FH functions. There are also individual pages for each function giving examples of srequired syntax.
Derek
Derek
Running Windows 7 64 bit
-
British Kiwi
- Famous
- Posts: 106
- Joined: 14 Sep 2014 09:59
- Family Historian: V7
Re: Diagram code question
Thanks Derek. I had looked at thr knowledge base a while ago when I was very sleep deprived and couldn't make it out. This help file makes more sense.
- tatewise
- Megastar
- Posts: 27081
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Diagram code question
Don't confuse FH Expressions used within FH itself and LUA that is the scripting languge for Plugins.
Expressions may have several components:
Expressions may have several components:
- Data References such as %INDI.NAME[1]%
See how_to:understanding_data_references|> Understanding Data References and associated FH Help. - Functions such as =TextIf(...)
See how_to:understanding_functions|> Understanding Functions and associated FH Help. - Operators such as + - = >
See FH Help > Using Family Historian > Advanced Topics > Understanding Functions > Operators etc.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
-
British Kiwi
- Famous
- Posts: 106
- Joined: 14 Sep 2014 09:59
- Family Historian: V7
Re: Diagram code question
Thanjs Mike. I will give these a read. One day I would like to write a plugin but in the meantime I will be happy with my custom chart 