Page 1 of 1
Diagram code question
Posted: 03 Mar 2015 09:31
by British Kiwi
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?
Re: Diagram code question
Posted: 03 Mar 2015 13:39
by tatewise
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.
- 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.
Re: Diagram code question
Posted: 03 Mar 2015 14:23
by Jane
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))
Re: Diagram code question
Posted: 03 Mar 2015 14:31
by tatewise
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.
Re: Diagram code question
Posted: 03 Mar 2015 15:45
by Jane
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.
Re: Diagram code question
Posted: 03 Mar 2015 21:20
by British Kiwi
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.
Re: Diagram code question
Posted: 03 Mar 2015 21:25
by tatewise
Yes, but even then it omits the Root Individual who is any one of the siblings, and displays nothing if there are no siblings.
Re: Diagram code question
Posted: 03 Mar 2015 21:47
by British Kiwi
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).
Re: Diagram code question
Posted: 03 Mar 2015 21:58
by tatewise
Sorry, I do not understand what you mean by "proper" functions. Potentially, all functions can be used in all contexts where Expressions are allowed.
Re: Diagram code question
Posted: 04 Mar 2015 00:22
by British Kiwi
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.
Re: Diagram code question
Posted: 04 Mar 2015 06:11
by British Kiwi
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.
Re: Diagram code question
Posted: 04 Mar 2015 07:55
by delwoodman
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
Re: Diagram code question
Posted: 04 Mar 2015 09:33
by British Kiwi
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.
Re: Diagram code question
Posted: 04 Mar 2015 10:34
by tatewise
Don't confuse FH
Expressions used within FH itself and
LUA that is the scripting languge for
Plugins.
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.
Re: Diagram code question
Posted: 04 Mar 2015 11:48
by British Kiwi
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
