* Diagram code question

Questions regarding use of any Version of Family Historian. Please ensure you have set your Version of Family Historian in your Profile. If your question fits in one of these subject-specific sub-forums, please ask it there.
Post Reply
avatar
British Kiwi
Famous
Posts: 106
Joined: 14 Sep 2014 09:59
Family Historian: V7

Diagram code question

Post by British Kiwi » 03 Mar 2015 09:31

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?

User avatar
tatewise
Megastar
Posts: 27088
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Diagram code question

Post by tatewise » 03 Mar 2015 13:39

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Jane
Site Admin
Posts: 8442
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: Diagram code question

Post by Jane » 03 Mar 2015 14:23

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))
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

User avatar
tatewise
Megastar
Posts: 27088
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Diagram code question

Post by tatewise » 03 Mar 2015 14:31

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Jane
Site Admin
Posts: 8442
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: Diagram code question

Post by Jane » 03 Mar 2015 15:45

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."

avatar
British Kiwi
Famous
Posts: 106
Joined: 14 Sep 2014 09:59
Family Historian: V7

Re: Diagram code question

Post by British Kiwi » 03 Mar 2015 21:20

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.

User avatar
tatewise
Megastar
Posts: 27088
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Diagram code question

Post by tatewise » 03 Mar 2015 21:25

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

avatar
British Kiwi
Famous
Posts: 106
Joined: 14 Sep 2014 09:59
Family Historian: V7

Re: Diagram code question

Post by British Kiwi » 03 Mar 2015 21:47

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).

User avatar
tatewise
Megastar
Posts: 27088
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Diagram code question

Post by tatewise » 03 Mar 2015 21:58

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

avatar
British Kiwi
Famous
Posts: 106
Joined: 14 Sep 2014 09:59
Family Historian: V7

Re: Diagram code question

Post by British Kiwi » 04 Mar 2015 00:22

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.

avatar
British Kiwi
Famous
Posts: 106
Joined: 14 Sep 2014 09:59
Family Historian: V7

Re: Diagram code question

Post by British Kiwi » 04 Mar 2015 06:11

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.

avatar
delwoodman
Famous
Posts: 125
Joined: 15 Sep 2007 10:42
Family Historian: V6.2
Location: Brighton, East Sussex, UK

Re: Diagram code question

Post by delwoodman » 04 Mar 2015 07:55

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
Running Windows 7 64 bit

avatar
British Kiwi
Famous
Posts: 106
Joined: 14 Sep 2014 09:59
Family Historian: V7

Re: Diagram code question

Post by British Kiwi » 04 Mar 2015 09:33

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.

User avatar
tatewise
Megastar
Posts: 27088
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Diagram code question

Post by tatewise » 04 Mar 2015 10:34

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
British Kiwi
Famous
Posts: 106
Joined: 14 Sep 2014 09:59
Family Historian: V7

Re: Diagram code question

Post by British Kiwi » 04 Mar 2015 11:48

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 :)

Post Reply