BALKANGraph / FamilyTreeJS

Build family tree app with BALKAN FamilyTreeJS library. Family Tree also called a genealogy or a pedigree chart, is a chart representing family relationships in a conventional tree structure.
50 stars 16 forks source link

`replaceIds` doesn't work with multiple ids #96

Closed pandabytes closed 5 months ago

pandabytes commented 6 months ago

Hello. Thank you for the great library!

Issue

I ran into an issue with familyTree.replaceIds. This method throws an exception when I pass in multiple ids like this: familyTree.replaceIds({ 1: 'a', 2: 'b' }). However it works fine if I break the ids into individual objects so like this:

familyTree.replaceIds({ 1: 'a' });
familyTree.replaceIds({ 2: 'b' });

The exception is displayed in the chrome devtool console: image

Code example

<!--HTML-->
<script src="https://balkan.app/js/FamilyTree.js"></script>
<button id="btn">Test</button>
<div id="tree"></div>
//JavaScript
var family = new FamilyTree(document.getElementById("tree"), {
    mouseScrool: FamilyTree.action.none,
    nodeBinding: {
        field_0: "name"
    },
    nodeTreeMenu: true,
    nodes: [
        { id: 1, pids: [2], name: "Amber McKenzie", gender: "female" },
        { id: 2, pids: [1], name: "Ava Field", gender: "male" },
    ]
});

document.getElementById("btn").addEventListener("click", function () {
    // This throws an exception 
    family.replaceIds({1: 'a', 2: 'b'});

   // This doesn't throw an exception
    family.replaceIds({1: 'a'});
    family.replaceIds({2: 'b'});
});
ZornitsaPesheva commented 6 months ago

This method is used to replace ids with the those generated in the backend: https://github.com/plamen-peshev/FamilyTreeJSGenerateNewNodesIdsFromServerSide/tree/master/FamilyTreeJSGenerateNewNodesIdsFromServerSide

pandabytes commented 6 months ago

Yep. I understand what method does but I'm unsure of how to call this method correctly because, as described above

// Usage 1 - Throw exception
family.replaceIds({1: 'a', 2: 'b'});

// Usage 2 - Ok
family.replaceIds({1: 'a'});
family.replaceIds({2: 'b'});
ZornitsaPesheva commented 6 months ago

I don't know how exactly the method works, but the ids that are replaced are generated from the chart for the new nodes. We don't replace already existing nodes, as their id's are already taken from the server. Please try the same case as in our GitHub example.

pandabytes commented 6 months ago

Perhaps I'm not being cleared. I understand the purpose of the method, but it throws an exception when I pass an object with multiple ids in which I think it's supposed to do. So my question is, is this a bug?

ZornitsaPesheva commented 6 months ago

Yes, may be it is a bug. We will check and will write you again.

plamen-peshev commented 6 months ago

We have addressed the issue in the lates release

You can test this Code demo (before testing lcear your browser cache)

pandabytes commented 5 months ago

Thank you!