Initializes a new instance of FamilyTree2.
The HTML element where the family tree will be rendered.
Persist the state (scale, position, expand/collapse and focus) in the url or local storage
let familyTree = new FamilyTree2(document.getElementById('tree'));
familytree.state.name = "StateForMyTree";
familyTree.state.writeToLocalStorage = true;
familyTree.state.readFromLocalStorage = true;
familyTree.state.writeToSessionStorage = true;
familyTree.state.readFromSessionStorage = true;
familyTree.state.writeToUrlParams = true;
familyTree.state.readFromUrlParams = true;
The collapsed node IDs. This property allows you to get and set the collapsed node IDs.
let familyTree = new FamilyTree2(document.getElementById('tree'));
let collapsedIds = familyTree.collapsedIds; // Get the collapsed node IDs
familyTree.collapsedIds = [6, 8, 9, 12]; // Set the collapsed node IDs
The collapsed node IDs. This property allows you to get and set the collapsed node IDs.
let familyTree = new FamilyTree2(document.getElementById('tree'));
let collapsedIds = familyTree.collapsedIds; // Get the collapsed node IDs
familyTree.collapsedIds = [6, 8, 9, 12]; // Set the collapsed node IDs
Gets the edited node ID.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.readOnly = false;
familyTree.addFamilyMembers([{id: 1}])
.draw(1, null, function(){
this.edit(1, 'name');
console.log(this.editId)
});
Gets the root HTML element of the chart.
let familyTree = new FamilyTree2(document.getElementById('tree'));
let treeElement = familyTree.element;
Gets the family data.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([{ id: 1, spouseIds: [2] }, { id: 2 }]).draw(1);
let family = familyTree.family;
Gets the focus ID.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([{ id: 1, spouseIds: [2] }, { id: 2 }])
.draw(1, null, function() {
let focusId = familyTree.focusId;
});
Gets or sets the current mode of the chart. It could be 'dark' or 'light' Default value: "light";
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.mode = "dark";
Gets or sets the current mode of the chart. It could be 'dark' or 'light' Default value: "light";
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.mode = "dark";
Gets or sets the visibility of the navigation bar.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.navigationBar = false;
const navBar = familyTree.navigationBar;
Gets or sets the visibility of the navigation bar.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.navigationBar = false;
const navBar = familyTree.navigationBar;
Gets or sets the read-only state of the chart.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.readOnly = false;
const readOnly = familyTree.readOnly;
Gets or sets the read-only state of the chart.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.readOnly = false;
const readOnly = familyTree.readOnly;
Gets the SVG element of the chart.
let familyTree = new FamilyTree2(document.getElementById('tree'));
const svg = familyTree.svgElement;
Gets the template object.
let familyTree = new FamilyTree2(document.getElementById('tree'));
let template = familyTree.template;
Gets or sets the template name.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.templateName = 'kitkat';
let templateName = familyTree.templateName;
Gets or sets the template name.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.templateName = 'kitkat';
let templateName = familyTree.templateName;
Adds a child to the family tree.
Here is an example with two parents of the added child:
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).addChild(1, 2, {name: "Maria"}).draw(1);
Here is an example with one parent of the added child:
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).addChild(1, {name: "Maria"}).draw(1);
The ID of the first parent.
The ID of the second parent (optional).
Additional data for the child node (optional).
Family tree object.
Add family members.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1);
Adds a father to the specified family member.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
].addFather(1, {name: "Derek"}).draw(1);
The ID of the family member to whom the father will be added.
Tha family member object
Family tree object.
Adds a mother to the specified family member.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).addMother(1, {name: "Maria"}).draw(1);
The ID of the family member to whom the mother will be added.
The data object containing information about the mother.
Family tree object.
Adds a sibling to the specified family member.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).addSibling(1, {name: "Maria"}).draw(1);
The ID of the family member to whom the sibling will be added.
The data of the new sibling.
Family tree object.
Adds a spouse to the specified family member.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).addSpouse(1, {name: "Maria"}).draw(1);
The ID of the family member to whom the spouse will be added.
The spouse's data.
Family tree object.
Adds an unmarried partner to the specified family member.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).addUnmarriedPartner(1, {name: "Maria"}).draw(1);
The ID of the family member to whom the partner will be added.
he data of the unmarried partner to be added.
Family tree object.
Clears the chart.
familyTree.onLoaded(() => {
familyTree.clear()
});
Clears the state
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.clearState('myStateName');
Destroys the familyTree instance.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1);
familyTree.destroy();
Draws the tree.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1);
Show node relations to add.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.readOnly = false;
familyTree.addFamilyMembers([{ id: 1 }])
.draw(1, null, function() {
this.edit(1, 'name');
});
Fits the family tree in the tree div.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{
id: 1,
fatherId: 2,
motherId: 3,
spouseIds: [4],
siblingIds: [5, 6],
childIds: [7],
name: 'Me'
},
{ id: 2, name: 'Father' },
{ id: 3, name: 'Mother' },
{ id: 4, childIds: [7], name: 'Spouse' },
{ id: 5, name: 'Sibling 1', motherId: 8 },
{ id: 6, name: 'Sibling 2' },
{ id: 7, name: 'Child' },
{ id: 8, name: 'Mother 1' }
]).draw(1);
familyTree.fit();
Retrieves a family member by ID.
The family member's ID.
Femily member object.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1);
let familyMember = familyTree.getFemilyMember(2);
Returns the node object.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.onLoaded(() => {
let node = familyTree.getNode(2);
//...
});
familyTree.addFamilyMembers([
{ id: 1, spouseIds: [2], childIds: [3, 4] },
{ id: 2, childIds: [3, 4] },
{ id: 3 },
{ id: 4 }
]).draw(1);
Registers an event listener for the 'demand' event. Triggers when new data from the server is required.
The function to be called when the 'demand' event is triggered.
An array of IDs that needs to be pulled from the server or any source.
Family tree object.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.onDemand(function (args) {
fetch(`https://familytree.balkan.app/FetchFamilyMembers/c8sshc/${args.ids.join(',')}`)
.then((data) => data.json())
.then((data) => familyTree.addFamilyMembers(data).draw());
});
Registers an event listener for the onFocusButtonClick event. Triggers when a new family member is focused from the UI or programmatically.
The function to be called when the onFocusButtonClick event is triggered.
New family tree member ID that will be focussed
Old family tree member ID that was focussed
Family tree object.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.onFocusButtonClick(function (args) {
fetch('https://familytree.balkan.app/FetchFamily/c8sshc/' + args.newFocusId)
.then((data) => data.json())
.then((data) => familyTree.addFamilyMembers(data).draw(args.newFocusId, familyTree.fit));
return false;
});
Registers a new event listener that will be called after the family tree has been loaded.
The function to be called after the tree is loaded.
Family tree object.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.onLoaded(() => {
alert('Family tree loaded');
});
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).addSpouse(1, { name: "Maria" }).draw(1);
Fires an event when you click on a node
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.onNodeClick(function(args){
alert('node clicked')
});
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1);
Fires an event when you click outside a anode
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.onSvgClick(function(args){
alert('svg clicked')
});
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1);
Registers an update listener for the 'updated' event. Triggers when one or more family tree members are updated, added, or removed.
The function to be called when the 'updated' event is triggered.
An array of family members that needs to be inserted or added in the storage
An array of IDs that needs to be removed or delted from the storage.
An array of family members that needs to be updated / synced in the storage
Family tree.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.onUpdated(function (args) {
// Option 1 - update your server with the new data in args
// Option 2 - update your server with the array from familyTree.family
});
Removes specified family member
Family member id that will be removed
Family tree object
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]);
familyTree.remove(2).draw(1);
Select family member node.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1, null, function () {
this.select(2);
});
Shows the edit/details form for a node ID.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{ id: 1, name: "John", spouseIds: [2] },
{ id: 2, name: "Ana" }
]).draw(1);
familyTree.showEditor(2);
Creates URL parameners from the state
let familyTree = new FamilyTree2(document.getElementById('tree'));
familytree.state.name = "StateForMyTree";
familyTree.state.writeToUrlParams = true;
familyTree.state.readFromUrlParams = true;
document.getElementById('button').addEventListener('click', function () {
let location = window.location + '?' + familyTree.stateToUrl()
window.open(location);
});
Retrieves an SVG representation of the chart.
SVG as string
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([{ id: 1, spouseIds: [2] }, { id: 2 }])
.draw(1);
let svg = familyTree.svg();
Creates a family tree template.
The name of the new template.
The name of the source template.
Family tree template object.
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.template = FamilyTree2.createTemplate("myTemplate", "base");
Generated using TypeDoc
Basic usage:
Load on demand usage